mirror of
https://gitea.computerliebe.org/ComputerLiebe_ORG_private/Gitea-VSCode-Clone-Plugin.git
synced 2025-07-05 04:13:41 +00:00
initialize Plugin
This commit is contained in:
62
gitea-git-clone/src/extension.ts
Normal file
62
gitea-git-clone/src/extension.ts
Normal file
@ -0,0 +1,62 @@
|
||||
import * as vscode from 'vscode';
|
||||
import axios from 'axios';
|
||||
|
||||
// Funktion zur Authentifizierung bei Gitea mit dem Personal Access Token (PAT)
|
||||
async function authenticateGitea() {
|
||||
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`, {
|
||||
headers: {
|
||||
'Authorization': `token ${token}`
|
||||
}
|
||||
});
|
||||
|
||||
if (response.status === 200) {
|
||||
vscode.window.showInformationMessage(`Authentifizierung erfolgreich: ${response.data.username}`);
|
||||
}
|
||||
} catch (error) {
|
||||
vscode.window.showErrorMessage('Authentifizierung fehlgeschlagen.');
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
// Funktion zur Konfiguration der Gitea-Instanz und des Tokens über die Command Palette
|
||||
async function configureGitea() {
|
||||
const instanceUrl = await vscode.window.showInputBox({
|
||||
prompt: "Gitea Instanz-URL eingeben",
|
||||
placeHolder: "https://your-gitea-instance.com"
|
||||
});
|
||||
|
||||
const token = await vscode.window.showInputBox({
|
||||
prompt: "Gitea Personal Access Token eingeben",
|
||||
placeHolder: "token",
|
||||
password: true
|
||||
});
|
||||
|
||||
if (instanceUrl && token) {
|
||||
await vscode.workspace.getConfiguration().update('gitea.instanceUrl', instanceUrl, vscode.ConfigurationTarget.Global);
|
||||
await vscode.workspace.getConfiguration().update('gitea.personalAccessToken', token, vscode.ConfigurationTarget.Global);
|
||||
vscode.window.showInformationMessage('Gitea Konfiguration aktualisiert.');
|
||||
}
|
||||
}
|
||||
|
||||
// Aktivierungsfunktion des Plugins
|
||||
export function activate(context: vscode.ExtensionContext) {
|
||||
// Registriert den Befehl zur Authentifizierung
|
||||
let authCommand = vscode.commands.registerCommand('gitea.authenticate', authenticateGitea);
|
||||
context.subscriptions.push(authCommand);
|
||||
|
||||
// Registriert den Befehl zur Konfiguration
|
||||
let configCommand = vscode.commands.registerCommand('gitea.configure', configureGitea);
|
||||
context.subscriptions.push(configCommand);
|
||||
}
|
||||
|
||||
// Deaktivierungsfunktion des Plugins
|
||||
export function deactivate() {}
|
15
gitea-git-clone/src/test/extension.test.ts
Normal file
15
gitea-git-clone/src/test/extension.test.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import * as assert from 'assert';
|
||||
|
||||
// You can import and use all API from the 'vscode' module
|
||||
// as well as import your extension to test it
|
||||
import * as vscode from 'vscode';
|
||||
// import * as myExtension from '../../extension';
|
||||
|
||||
suite('Extension Test Suite', () => {
|
||||
vscode.window.showInformationMessage('Start all tests.');
|
||||
|
||||
test('Sample test', () => {
|
||||
assert.strictEqual(-1, [1, 2, 3].indexOf(5));
|
||||
assert.strictEqual(-1, [1, 2, 3].indexOf(0));
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user