mirror of
https://gitea.computerliebe.org/ComputerLiebe_ORG_private/Gitea-VSCode-Clone-Plugin.git
synced 2025-09-06 02:09:48 +00:00
Show Open Pull Requests
* chore(gitea-git-clone): update changelog and package version * feat(gitea-git-clone): add support for showing open pull requests * docs(gitea-git-clone): update README.md with new features and commands * feat(gitea-git-clone): add localization support for open pull requests * fix(gitea-git-clone): fix typo in package.nls.json * fix(gitea-git-clone): fix typo in package.json * feat(gitea-git-clone): add functions for retrieving and showing open pull requests * feat(gitea-git-clone): add command for showing open pull requests * feat(gitea-git-clone): create status bar item for showing open pull requests * fix(gitea-git-clone): fix missing comma in package.json * fix(gitea-git-clone): fix missing comma in package.nls.de.json * fix(gitea-git
This commit is contained in:
@@ -298,6 +298,150 @@ async function configureGitea() {
|
||||
}
|
||||
}
|
||||
|
||||
// Features
|
||||
|
||||
// Funktion zum Abrufen offener Pull Requests
|
||||
async function getOpenPullRequests(): 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(localize('giteaClone.configMissing', '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(localize('giteaClone.noValidRepo', 'Kein gültiges Git-Repository im aktuellen Arbeitsbereich gefunden.'));
|
||||
return [];
|
||||
}
|
||||
|
||||
// Git-Repository-Informationen abrufen
|
||||
const { owner, repo } = await getRepoInfo(currentWorkspaceFolder);
|
||||
if (!owner || !repo) {
|
||||
vscode.window.showErrorMessage(localize('giteaClone.repoInfoError', 'Konnte Repository-Informationen nicht abrufen.'));
|
||||
return [];
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await axios.get(`${instanceUrl}/api/v1/repos/${owner}/${repo}/pulls`, {
|
||||
headers: {
|
||||
'Authorization': `token ${token}`
|
||||
},
|
||||
params: {
|
||||
state: 'open'
|
||||
}
|
||||
});
|
||||
|
||||
if (response.status === 200) {
|
||||
return response.data;
|
||||
} else {
|
||||
vscode.window.showErrorMessage(localize('giteaClone.pullRequestsError', 'Fehler beim Abrufen der Pull Requests.'));
|
||||
return [];
|
||||
}
|
||||
} catch (error) {
|
||||
vscode.window.showErrorMessage(localize('giteaClone.apiError', 'Fehler bei der Verbindung zur Gitea API.'));
|
||||
console.error(error);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
// Hilfsfunktion zum Abrufen von Repository-Informationen
|
||||
async function getRepoInfo(folderPath: string): Promise<{ owner: string, repo: string }> {
|
||||
return new Promise((resolve, reject) => {
|
||||
exec(`git config --get remote.origin.url`, { cwd: folderPath }, (error, stdout) => {
|
||||
if (error || !stdout) {
|
||||
reject(localize('giteaClone.noRemoteUrl', 'Konnte Git-Remote-URL nicht abrufen.'));
|
||||
} else {
|
||||
let repoUrl = stdout.trim();
|
||||
|
||||
// URL umwandeln, wenn sie im SSH-Format vorliegt
|
||||
if (repoUrl.startsWith('git@')) {
|
||||
const parts = repoUrl.split(':');
|
||||
const domain = parts[0].replace('git@', '');
|
||||
const path = parts[1].replace('.git', '');
|
||||
repoUrl = `https://${domain}/${path}`;
|
||||
} else {
|
||||
repoUrl = repoUrl.replace('.git', '');
|
||||
}
|
||||
|
||||
const [owner, repo] = repoUrl.split('/').slice(-2);
|
||||
resolve({ owner, repo });
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Funktion zum Anzeigen offener Pull Requests
|
||||
async function showOpenPullRequests() {
|
||||
const pullRequests = await getOpenPullRequests();
|
||||
|
||||
if (pullRequests.length === 0) {
|
||||
vscode.window.showInformationMessage(localize('giteaClone.noOpenPRs', 'Keine offenen Pull Requests vorhanden.'));
|
||||
return;
|
||||
}
|
||||
|
||||
const prItems = pullRequests.map(pr => ({
|
||||
label: `#${pr.number}: ${pr.title}`,
|
||||
description: `von ${pr.user.username}`,
|
||||
pr
|
||||
}));
|
||||
|
||||
const selectedPr = await vscode.window.showQuickPick(prItems, {
|
||||
placeHolder: localize('giteaClone.selectPullRequest', 'Wähle einen Pull Request zum Anzeigen aus')
|
||||
});
|
||||
|
||||
if (selectedPr) {
|
||||
// Öffne die URL des ausgewählten PRs im Browser
|
||||
vscode.env.openExternal(vscode.Uri.parse(selectedPr.pr.html_url));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let extensionContext: vscode.ExtensionContext;
|
||||
|
||||
// Funktion zum Aktualisieren des PR-Statusleisten-Icons
|
||||
let prStatusBarItem: vscode.StatusBarItem;
|
||||
|
||||
async function updatePRStatusBarItem(context: vscode.ExtensionContext) {
|
||||
try {
|
||||
const pullRequests = await getOpenPullRequests();
|
||||
|
||||
if (!prStatusBarItem) {
|
||||
prStatusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
|
||||
prStatusBarItem.command = 'gitea.showOpenPullRequests';
|
||||
prStatusBarItem.tooltip = localize('giteaClone.showOpenPullRequestsTooltip', 'Offene Pull Requests anzeigen');
|
||||
context.subscriptions.push(prStatusBarItem);
|
||||
}
|
||||
|
||||
const prCount = pullRequests.length;
|
||||
prStatusBarItem.text = `$(git-pull-request) Gitea Open PRs: ${prCount}`;
|
||||
prStatusBarItem.show();
|
||||
} catch (error) {
|
||||
console.error('Fehler beim Aktualisieren des PR-Statusleisten-Icons:', error);
|
||||
if (prStatusBarItem) {
|
||||
prStatusBarItem.hide();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Funktion zum Starten des PR-Statusleisten-Updaters
|
||||
function startPRStatusBarItemUpdater(context: vscode.ExtensionContext) {
|
||||
updatePRStatusBarItem(context); // Initiales Update
|
||||
|
||||
// Aktualisiere bei Fokuswechsel
|
||||
vscode.window.onDidChangeWindowState((windowState) => {
|
||||
if (windowState.focused) {
|
||||
updatePRStatusBarItem(context);
|
||||
}
|
||||
}, null, context.subscriptions);
|
||||
|
||||
// Aktualisiere alle 5 Minuten
|
||||
setInterval(() => updatePRStatusBarItem(context), 300000); // 5 Minuten
|
||||
}
|
||||
|
||||
|
||||
// Aktivierungsfunktion des Plugins
|
||||
export function activate(context: vscode.ExtensionContext) {
|
||||
// Registriert den Befehl zur Authentifizierung
|
||||
@@ -319,6 +463,13 @@ export function activate(context: vscode.ExtensionContext) {
|
||||
// Befehl zum Klonen eines Repositories
|
||||
let cloneCommand = vscode.commands.registerCommand('gitea.cloneRepository', cloneGiteaRepository);
|
||||
context.subscriptions.push(cloneCommand);
|
||||
|
||||
// Befehl zum Anzeigen offener Pull Requests
|
||||
let showPRCommand = vscode.commands.registerCommand('gitea.showOpenPullRequests', showOpenPullRequests);
|
||||
context.subscriptions.push(showPRCommand);
|
||||
|
||||
// Statusleisten-Icon erstellen und Updater starten
|
||||
startPRStatusBarItemUpdater(context);
|
||||
}
|
||||
|
||||
// Deaktivierungsfunktion des Plugins
|
||||
|
Reference in New Issue
Block a user