mirror of
https://gitea.computerliebe.org/ComputerLiebe_ORG_private/Gitea-VSCode-Clone-Plugin.git
synced 2024-12-28 16:01:53 +00:00
* feat(extension.ts): add support for cloning Gitea repositories via SSH
* fix(package.json): change command title from "Gitea: Configure" to "Gitea: Configure URL" * feat(extension.ts): add command "Gitea: Clone Repository" for cloning Gitea repositories
This commit is contained in:
parent
31c890eb51
commit
a23b61758b
@ -19,7 +19,11 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"command": "gitea.configure",
|
"command": "gitea.configure",
|
||||||
"title": "Gitea: Configure"
|
"title": "Gitea: Configure URL"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command": "gitea.cloneRepository",
|
||||||
|
"title": "Gitea: Clone Repository"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"configuration": {
|
"configuration": {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
import { exec } from 'child_process';
|
||||||
|
|
||||||
// Funktion zur Authentifizierung bei Gitea mit dem Personal Access Token (PAT)
|
// Funktion zur Authentifizierung bei Gitea mit dem Personal Access Token (PAT)
|
||||||
async function authenticateGitea() {
|
async function authenticateGitea() {
|
||||||
@ -47,6 +48,94 @@ async function configureGitea() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Funktion zum Abrufen der Repositories des Benutzers von Gitea
|
||||||
|
async function getGiteaRepositories(): Promise<any[]> {
|
||||||
|
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 [];
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await axios.get(`${instanceUrl}/api/v1/user/repos`, {
|
||||||
|
headers: {
|
||||||
|
'Authorization': `token ${token}`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.status === 200) {
|
||||||
|
return response.data;
|
||||||
|
} else {
|
||||||
|
vscode.window.showErrorMessage('Fehler beim Abrufen der Repositories.');
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
vscode.window.showErrorMessage('Fehler bei der Verbindung mit der Gitea API.');
|
||||||
|
console.error(error);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Funktion zum Klonen eines Repositories via SSH
|
||||||
|
async function cloneGiteaRepository() {
|
||||||
|
const repos = await getGiteaRepositories();
|
||||||
|
|
||||||
|
if (repos.length === 0) {
|
||||||
|
vscode.window.showInformationMessage('Keine Repositories gefunden.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const repoNames = repos.map(repo => repo.full_name);
|
||||||
|
const selectedRepo = await vscode.window.showQuickPick(repoNames, {
|
||||||
|
placeHolder: 'Wähle ein Repository zum Klonen aus'
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!selectedRepo) {
|
||||||
|
vscode.window.showInformationMessage('Kein Repository ausgewählt.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const repo = repos.find(r => r.full_name === selectedRepo);
|
||||||
|
|
||||||
|
// Verwende die SSH-URL anstelle von HTTPS
|
||||||
|
if (repo && repo.ssh_url) {
|
||||||
|
const folderUri = await vscode.window.showOpenDialog({
|
||||||
|
canSelectFiles: false,
|
||||||
|
canSelectFolders: true,
|
||||||
|
canSelectMany: false,
|
||||||
|
openLabel: 'Ordner zum Klonen auswählen'
|
||||||
|
});
|
||||||
|
|
||||||
|
if (folderUri && folderUri[0]) {
|
||||||
|
const folderPath = folderUri[0].fsPath;
|
||||||
|
|
||||||
|
vscode.window.withProgress({
|
||||||
|
location: vscode.ProgressLocation.Window,
|
||||||
|
title: `Cloning ${selectedRepo}`,
|
||||||
|
cancellable: false
|
||||||
|
}, async (progress) => {
|
||||||
|
progress.report({ message: 'Klonvorgang läuft...' });
|
||||||
|
|
||||||
|
exec(`git clone ${repo.ssh_url} ${folderPath}`, (error, stdout, stderr) => {
|
||||||
|
if (error) {
|
||||||
|
vscode.window.showErrorMessage('Fehler beim Klonen des Repositories.');
|
||||||
|
console.error(stderr);
|
||||||
|
} else {
|
||||||
|
vscode.window.showInformationMessage(`Repository ${selectedRepo} erfolgreich geklont.`);
|
||||||
|
console.log(stdout);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
vscode.window.showInformationMessage('Kein Zielordner ausgewählt.');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
vscode.window.showErrorMessage('Konnte die SSH-Klon-URL nicht finden.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Aktivierungsfunktion des Plugins
|
// Aktivierungsfunktion des Plugins
|
||||||
export function activate(context: vscode.ExtensionContext) {
|
export function activate(context: vscode.ExtensionContext) {
|
||||||
// Registriert den Befehl zur Authentifizierung
|
// Registriert den Befehl zur Authentifizierung
|
||||||
@ -56,6 +145,10 @@ export function activate(context: vscode.ExtensionContext) {
|
|||||||
// Registriert den Befehl zur Konfiguration
|
// Registriert den Befehl zur Konfiguration
|
||||||
let configCommand = vscode.commands.registerCommand('gitea.configure', configureGitea);
|
let configCommand = vscode.commands.registerCommand('gitea.configure', configureGitea);
|
||||||
context.subscriptions.push(configCommand);
|
context.subscriptions.push(configCommand);
|
||||||
|
|
||||||
|
// Befehl zum Klonen eines Repositories
|
||||||
|
let cloneCommand = vscode.commands.registerCommand('gitea.cloneRepository', cloneGiteaRepository);
|
||||||
|
context.subscriptions.push(cloneCommand);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deaktivierungsfunktion des Plugins
|
// Deaktivierungsfunktion des Plugins
|
||||||
|
Loading…
Reference in New Issue
Block a user