mirror of
https://gitea.computerliebe.org/ComputerLiebe_ORG_private/Gitea-VSCode-Clone-Plugin.git
synced 2025-07-05 12:13:42 +00:00
* feat(extension.ts): add support for creating a pull request in Gitea
* feat(extension.ts): add status bar icon for creating a pull request * feat(extension.ts): implement function to create a Gitea pull request * feat(extension.ts): implement function to add status bar icon
This commit is contained in:
@ -2,6 +2,68 @@ import * as vscode from 'vscode';
|
||||
import axios from 'axios';
|
||||
import { exec } from 'child_process';
|
||||
|
||||
// Funktion zum Abrufen des Gitea Repositories und Erstellen eines Pull Requests
|
||||
async function createGiteaPullRequest() {
|
||||
const instanceUrl = vscode.workspace.getConfiguration().get<string>('gitea.instanceUrl');
|
||||
const token = vscode.workspace.getConfiguration().get<string>('gitea.personalAccessToken');
|
||||
|
||||
if (!instanceUrl || !token) {
|
||||
vscode.window.showErrorMessage('Gitea URL oder Token ist nicht konfiguriert.');
|
||||
return;
|
||||
}
|
||||
|
||||
// Aktuellen Git-Ordner abrufen
|
||||
const currentWorkspaceFolder = vscode.workspace.workspaceFolders?.[0]?.uri?.fsPath;
|
||||
if (!currentWorkspaceFolder) {
|
||||
vscode.window.showErrorMessage('Kein gültiges Git-Repository im aktuellen Workspace gefunden.');
|
||||
return;
|
||||
}
|
||||
|
||||
// Git-Repository-Informationen abrufen
|
||||
exec(`git config --get remote.origin.url`, { cwd: currentWorkspaceFolder }, async (error, stdout, stderr) => {
|
||||
if (error || !stdout) {
|
||||
vscode.window.showErrorMessage('Konnte die Git-Remote-URL nicht abrufen.');
|
||||
return;
|
||||
}
|
||||
|
||||
let repoUrl = stdout.trim();
|
||||
|
||||
// URL umwandeln, wenn sie im SSH-Format vorliegt (git@gitea.com:owner/repo.git)
|
||||
if (repoUrl.startsWith('git@')) {
|
||||
// SSH-URL in HTTP(S)-URL umwandeln
|
||||
const parts = repoUrl.split(':');
|
||||
const domain = parts[0].replace('git@', '');
|
||||
const path = parts[1].replace('.git', '');
|
||||
repoUrl = `https://${domain}/${path}`;
|
||||
} else {
|
||||
// Falls es eine HTTPS-URL ist, einfach .git entfernen
|
||||
repoUrl = repoUrl.replace('.git', '');
|
||||
}
|
||||
|
||||
// URL für Pull Request Seite generieren
|
||||
const pullRequestUrl = `${repoUrl}/pulls/new`;
|
||||
|
||||
try {
|
||||
// Verwende die VSCode API, um die URL im Browser zu öffnen
|
||||
await vscode.env.openExternal(vscode.Uri.parse(pullRequestUrl));
|
||||
vscode.window.showInformationMessage('Pull-Request-Seite im Browser geöffnet.');
|
||||
} catch (err: unknown) {
|
||||
vscode.window.showErrorMessage('Fehler beim Öffnen der Pull-Request-Seite.');
|
||||
console.error('Fehler beim Öffnen des Browsers:', err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Funktion zum Hinzufügen des Statusbar-Icons
|
||||
function addStatusBarIcon() {
|
||||
const statusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
|
||||
statusBar.text = `$(git-pull-request) Create PR`;
|
||||
statusBar.tooltip = 'Create a Pull Request in Gitea';
|
||||
statusBar.command = 'gitea.createPullRequest';
|
||||
statusBar.show();
|
||||
return statusBar;
|
||||
}
|
||||
|
||||
// Funktion zur Authentifizierung bei Gitea mit dem Personal Access Token (PAT)
|
||||
async function authenticateGitea() {
|
||||
const instanceUrl = vscode.workspace.getConfiguration().get<string>('gitea.instanceUrl');
|
||||
@ -161,6 +223,14 @@ export function activate(context: vscode.ExtensionContext) {
|
||||
// Befehl zum Klonen eines Repositories
|
||||
let cloneCommand = vscode.commands.registerCommand('gitea.cloneRepository', cloneGiteaRepository);
|
||||
context.subscriptions.push(cloneCommand);
|
||||
|
||||
// Registriere den Befehl zum Erstellen eines Pull Requests
|
||||
let pullRequestCommand = vscode.commands.registerCommand('gitea.createPullRequest', createGiteaPullRequest);
|
||||
context.subscriptions.push(pullRequestCommand);
|
||||
|
||||
// Statusbar-Icon hinzufügen
|
||||
const statusBar = addStatusBarIcon();
|
||||
context.subscriptions.push(statusBar);
|
||||
}
|
||||
|
||||
// Deaktivierungsfunktion des Plugins
|
||||
|
Reference in New Issue
Block a user