Support of multiple Gitea instances

* chore(gitea-git-clone): update CHANGELOG.md and README.md
* feat(gitea-git-clone): add support for multiple Gitea instances
* feat(gitea-git-clone): enhance status bar integration with branch and build status
* fix(gitea-git-clone): fix issues with status bar items not updating correctly
* fix(gitea-git-clone): fix issues with long commit messages causing errors when creating pull requests
This commit is contained in:
Peter 2024-10-23 20:11:31 +02:00
parent b122dd4716
commit 5f749c57c8
6 changed files with 542 additions and 210 deletions

View File

@ -2,13 +2,31 @@
All notable changes to the “gitea-workflow” extension will be documented in this file. All notable changes to the “gitea-workflow” extension will be documented in this file.
Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.
## [Unreleased] ## 1.3
- Streamline Auth, Login and URL Setup **BREAKING CHANGE**
- if working in PR show different Icon with hint
- fix progress bar in notification New authentication and authorization is necessary, due to the redesign of the login and management of multiple Gitea instances!
### Added
- **Support for Multiple Gitea Instances**: You can now manage and switch between multiple Gitea instances within VSCode. Use the `Gitea: Configure` command to add, edit, or remove instances.
- **Enhanced Status Bar Integration**:
- **Branch Status**: The status bar now displays the current branch and indicates if it is ahead or behind the remote branch.
- **Build Status**: The build status of the current commit (e.g., success, failure, pending) is now shown in the status bar.
### Changed
- **Configuration Settings**:
- The settings for Gitea instance URL and Personal Access Token have been updated to support multiple instances.
- Old settings `gitea.instanceUrl` and `gitea.personalAccessToken` are replaced by `gitea.instances`, an array of instance configurations.
### Fixed
- **Bug Fixes**:
- Resolved issues with status bar items not updating correctly.
- Fixed an issue where long commit messages caused errors when creating pull requests by truncating titles and bodies to acceptable lengths.
## 1.2.2 ## 1.2.2

View File

@ -1,60 +1,94 @@
# Gitea Workflow # Gitea Workflow
A Visual Studio Code extension that allows you to clone repositories from your Gitea instance via SSH, manage Gitea authentication using a Personal Access Token (PAT), and create Pull Requests (PRs) directly from your workspace. A Visual Studio Code extension that allows you to manage your Gitea repositories directly from your workspace. Clone repositories via SSH, handle authentication with Personal Access Tokens (PAT's), create and view Pull Requests (PRs), manage multiple Gitea instances, and view branch and build statuses—all within VSCode.
## Features ## Features
- **Gitea Authentication**: Authenticate with your Gitea instance using a Personal Access Token. - **Gitea Authentication**: Authenticate with one or multiple Gitea instances using Personal Access Tokens.
- **Multiple Gitea Instances**: Manage and switch between multiple Gitea instances within VSCode.
- **Clone via SSH**: Clone repositories from Gitea using SSH URLs. - **Clone via SSH**: Clone repositories from Gitea using SSH URLs.
- **Auto-Open Repository**: After cloning, the repository will be automatically opened in the workspace. - **Auto-Open Repository**: After cloning, the repository will be automatically opened in the workspace.
- **See Open Pull Requests**: Use the icon in the status bar or the command to check how many open PRs exist and open them in a browser. - **See Open Pull Requests**: Use the icon in the status bar or the command to check how many open PRs exist and open them in a browser.
- **Create Pull Requests**: Create Pull Requests (PRs) directly from your workspace - **Create Pull Requests**: Create Pull Requests (PRs) directly from your workspace.
- **Enhanced Status Bar Integration**: View the current branch status and build status directly from the VSCode status bar.
## Commands ## Commands
- `Gitea: Authenticate`: Authenticate with your Gitea instance using your Personal Access Token (PAT). - `Gitea: Authenticate` → Authenticate with a selected Gitea instance using your Personal Access Token (PAT).
- `Gitea: Configure`: Set the URL of your Gitea instance and your PAT. - `Gitea: Configure` → Add, edit, or remove Gitea instances and their PAT's.
- `Gitea: Clone Repository`: Clone a repository from Gitea via SSH. - `Gitea: Clone Repository` → Clone a repository from a selected Gitea instance via SSH.
- `Gitea: Create Pull Request`: Create a pull request for the current repository. - `Gitea: Create Pull Request` Create a pull request for the current repository.
- `Gitea: Show Open Pull Request`: Shows open pull request for the current repository and link to them. - `Gitea: Show Open Pull Requests` → Show open pull requests for the current repository and link to them.
## Requirements ## Requirements
A Gitea instance with SSH access. - A Gitea instance with SSH access.
A Personal Access Token (PAT) from your Gitea instance for authentication. - A Personal Access Token (PAT) from your Gitea instance(s) for authentication.
## Configuration ## Configuration
You can configure the Gitea instance URL, your Personal Access Token, and default clone settings in your VSCode settings:
You can configure multiple Gitea instances and their Personal Access Tokens in your VSCode settings:
```json ```json
{ {
"gitea.instanceUrl": "https://your-gitea-instance.com", "gitea.instances": [
"gitea.personalAccessToken": "your-personal-access-token", {
"name": "Gitea Instance 1",
"url": "https://gitea.instance1.com",
"token": "your-personal-access-token-1"
},
{
"name": "Gitea Instance 2",
"url": "https://gitea.instance2.com",
"token": "your-personal-access-token-2"
}
]
} }
```` ````
Alternatively, you can use the `Gitea: Configure` command to add or edit instances interactively.
## Usage ## Usage
### Authentication ### Authentication
Run `Gitea: Authenticate` to authenticate with your Gitea instance. Run `Gitea: Authenticate` to authenticate with one of your configured Gitea instances.
You can set or update your Gitea instance URL and Personal Access Token by running `Gitea: Configure`
You can set up or update your Gitea instances and Personal Access Tokens by running `Gitea: Configure`.
### Managing Multiple Gitea Instances
Use `Gitea: Configure` to add, edit, or remove Gitea instances.
When executing commands like cloning a repository or creating a pull request,
you'll be prompted to select the Gitea instance you want to use if applicable.
### Cloning a Repository ### Cloning a Repository
Run `Gitea: Clone Repository` to clone a repository from your Gitea account. Run `Gitea: Clone Repository` from the command palette.
Choose the repository you want to clone and select the folder where you want to clone it. Select the Gitea instance from which you want to clone.
The repository will be cloned via SSH and automatically opened in VSCode. Choose the repository you want to clone.
Select the folder where you want to clone the repository.
The repository will be cloned via SSH and automatically opened in a new VSCode window.
### Creating a Pull Request ### Creating a Pull Request
_Ensure that you are on the branch for which you want to create a Pull Request._ Ensure that you are on the branch for which you want to create a Pull Request.
Run `Gitea: Create Pull Request` from the command palette. Run `Gitea: Create Pull Request` from the command palette.
The PR title will be automatically set to the latest commit message, and the body will include the commit description (if any). The PR title will be automatically set to the latest commit message, and the body will include the commit description (if any).
The current branch will be used as the source (head), and the base branch will be automatically fetched from the repository's default branch (e.g., main or master). The current branch will be used as the source (head), and the base branch will be automatically fetched from the repository's default branch (e.g., main or master).
Once the Pull Request is created, the Gitea web interface will open in your browser for further review. Once the Pull Request is created, the Gitea web interface will open in your browser for further review.
## Issues ### Viewing Open Pull Requests
If you encounter any issues or have feature requests, please feel free to submit them in [the issues section](https://gitea.computerliebe.org/ComputerLiebe/Gitea-Workflow/issues). The status bar will display the number of open pull requests for the current repository.
Click on the PR count in the status bar or run `Gitea: Show Open Pull` Requests to view and open them in a browser.
### Enhanced Status Bar Integration
**Branch Status**: The status bar shows the current branch and its status relative to the remote branch (e.g., ahead, behind).
**Build Status**: The build status of the current commit is displayed in the status bar (e.g., success, failure, pending).
### Issues
If you encounter any issues or have feature requests, please feel free to submit them in the [issues section](https://gitea.computerliebe.org/ComputerLiebe/Gitea-Workflow/issues)

View File

@ -1,41 +1,40 @@
{ {
"giteaClone.configMissing": "Gitea URL oder Token ist nicht konfiguriert.", "giteaClone.selectInstance": "Wählen Sie eine Gitea-Instanz aus",
"giteaClone.noValidRepo": "Kein gültiges Git-Repository im aktuellen Workspace gefunden.", "giteaClone.noInstanceSelected": "Keine Gitea-Instanz ausgewählt.",
"giteaClone.noRemoteUrl": "Konnte die Git-Remote-URL nicht abrufen.", "giteaClone.invalidInstance": "Ungültige Gitea-Instanz ausgewählt.",
"giteaClone.noBranch": "Branch konnte nicht ermittelt werden.", "giteaClone.configMissing": "Keine Gitea-Instanzen sind konfiguriert.",
"giteaClone.pullRequestCreated": "Pull-Request erfolgreich erstellt und im Browser geöffnet.", "giteaClone.authSuccess": "Authentifizierung erfolgreich: {0}",
"giteaClone.commitError": "Fehler beim Abrufen des letzten Commits.", "giteaClone.authFailed": "Authentifizierung fehlgeschlagen: {0}",
"giteaClone.branchError": "Fehler beim Abrufen des Branches.", "giteaClone.configUpdated": "Gitea-Konfiguration aktualisiert.",
"giteaClone.createPullRequest": "Gitea PR erstellen", "giteaClone.enterInstanceUrl": "Gitea-Instanz-URL eingeben",
"giteaClone.createPullRequestTooltip": "Pull Request in Gitea erstellen", "giteaClone.enterToken": "Gitea-Personal-Access-Token eingeben",
"giteaClone.authSuccess": "Authentifizierung erfolgreich: {0}", "giteaClone.selectRepo": "Wählen Sie ein Repository zum Klonen aus",
"giteaClone.configUpdated": "Gitea-Konfiguration aktualisiert.", "giteaClone.noRepos": "Keine Repositories gefunden.",
"giteaClone.enterInstanceUrl": "Gitea-Instanz-URL eingeben", "giteaClone.noRepoSelected": "Kein Repository ausgewählt.",
"giteaClone.enterToken": "Gitea Personal Access Token eingeben", "giteaClone.selectFolder": "Wählen Sie den Ordner zum Klonen aus",
"giteaClone.apiError": "Fehler bei der Verbindung mit der Gitea API.", "giteaClone.targetExists": "Das Zielverzeichnis \"{0}\" existiert bereits.",
"giteaClone.noRepos": "Keine Repositories gefunden.", "giteaClone.cloningRepo": "Klone {0}",
"giteaClone.selectRepo": "Wähle ein Repository zum Klonen aus", "giteaClone.cloningProgress": "Klonen läuft...",
"giteaClone.noRepoSelected": "Kein Repository ausgewählt.", "giteaClone.cloneComplete": "Repository erfolgreich geklont.",
"giteaClone.selectFolder": "Ordner zum Klonen auswählen", "giteaClone.cloneSuccess": "Repository {0} erfolgreich geklont.",
"giteaClone.cloningRepo": "Klonen von {0}", "giteaClone.openRepoError": "Fehler beim Öffnen des geklonten Repositories.",
"giteaClone.cloningProgress": "Klonvorgang läuft...", "giteaClone.createPullRequest": "Gitea PR erstellen",
"giteaClone.cloneComplete": "Repository erfolgreich geklont.", "giteaClone.createPullRequestTooltip": "Erstellen Sie einen Pull Request in Gitea",
"giteaClone.cloneSuccess": "Repository {0} erfolgreich geklont.", "giteaClone.pullRequestCreated": "Pull Request erfolgreich erstellt und im Browser geöffnet.",
"giteaClone.cloneError": "Fehler beim Klonen des Repositories.", "giteaClone.noRemoteUrl": "Konnte Git-Remote-URL nicht abrufen.",
"giteaClone.noFolderSelected": "Kein Zielordner ausgewählt.", "giteaClone.noBranch": "Konnte den Branch nicht bestimmen.",
"giteaClone.noSshUrl": "Konnte die SSH-Klon-URL nicht finden.", "giteaClone.titleTruncated": "Die Commit-Nachricht war zu lang und wurde für den Pull-Request-Titel gekürzt.",
"giteaClone.openRepoError": "Fehler beim Öffnen des geklonten Repositories.", "giteaClone.bodyTruncated": "Der Commit-Nachrichtentext war zu lang und wurde für die Pull-Request-Beschreibung gekürzt.",
"giteaClone.noOpenPRs": "Keine offenen Pull Requests vorhanden.", "giteaClone.pullRequestError": "Fehler beim Erstellen des Pull Requests: {0}",
"giteaClone.selectPullRequest": "Wähle einen Pull Request zum Anzeigen aus", "giteaClone.commitError": "Fehler beim Abrufen des letzten Commits.",
"giteaClone.repoInfoError": "Konnte Repository-Informationen nicht abrufen.", "giteaClone.branchError": "Fehler beim Abrufen des Branches.",
"giteaClone.showOpenPullRequestsTooltip": "Offene Pull Requests anzeigen", "giteaClone.defaultBranchError": "Fehler beim Abrufen des Base-Branches: {0}",
"giteaClone.targetExists": "Das Zielverzeichnis \"{0}\" existiert bereits.", "giteaClone.repoError": "Fehler beim Abrufen der Repositories.",
"giteaClone.pullRequestError": "Fehler beim Erstellen des Pull Requests: {0}", "giteaClone.repoInfoError": "Konnte Repository-Informationen nicht abrufen.",
"giteaClone.defaultBranchError": "Fehler beim Abrufen des Basis-Branches: {0}", "giteaClone.pullRequestsError": "Fehler beim Abrufen der Pull Requests: {0}",
"giteaClone.repoError": "Fehler beim Abrufen der Repositories: {0}", "giteaClone.noOpenPRs": "Keine offenen Pull Requests vorhanden.",
"giteaClone.authFailed": "Authentifizierung fehlgeschlagen: {0}", "giteaClone.selectPullRequest": "Wählen Sie einen Pull Request zum Anzeigen aus",
"giteaClone.pullRequestsError": "Fehler beim Abrufen der Pull Requests: {0}", "giteaClone.showOpenPullRequestsTooltip": "Offene Pull Requests anzeigen",
"giteaClone.titleTruncated": "Die Commit-Nachricht war zu lang und wurde für den Pull-Request-Titel gekürzt.", "giteaClone.branchStatusTooltip": "Aktueller Branch-Status",
"giteaClone.bodyTruncated": "Der Commit-Nachrichtentext war zu lang und wurde für die Pull-Request-Beschreibung gekürzt." "giteaClone.buildStatusTooltip": "Build-Status des aktuellen Commits"
} }

View File

@ -1,41 +1,40 @@
{ {
"giteaClone.configMissing": "Gitea URL or Token is not configured.", "giteaClone.selectInstance": "Select a Gitea instance",
"giteaClone.noValidRepo": "No valid Git repository found in the current workspace.", "giteaClone.noInstanceSelected": "No Gitea instance selected.",
"giteaClone.noRemoteUrl": "Could not retrieve Git remote URL.", "giteaClone.invalidInstance": "Invalid Gitea instance selected.",
"giteaClone.noBranch": "Could not determine the branch.", "giteaClone.configMissing": "No Gitea instances are configured.",
"giteaClone.pullRequestCreated": "Pull request created successfully and opened in the browser.", "giteaClone.authSuccess": "Authentication successful: {0}",
"giteaClone.commitError": "Error retrieving the last commit.", "giteaClone.authFailed": "Authentication failed: {0}",
"giteaClone.branchError": "Error retrieving the branch.", "giteaClone.configUpdated": "Gitea configuration updated.",
"giteaClone.createPullRequest": "Create Gitea PR", "giteaClone.enterInstanceUrl": "Enter Gitea instance URL",
"giteaClone.createPullRequestTooltip": "Create a Pull Request in Gitea", "giteaClone.enterToken": "Enter Gitea Personal Access Token",
"giteaClone.authSuccess": "Authentication successful: {0}", "giteaClone.selectRepo": "Select a repository to clone",
"giteaClone.configUpdated": "Gitea configuration updated.", "giteaClone.noRepos": "No repositories found.",
"giteaClone.enterInstanceUrl": "Enter Gitea instance URL", "giteaClone.noRepoSelected": "No repository selected.",
"giteaClone.enterToken": "Enter Gitea Personal Access Token", "giteaClone.selectFolder": "Select folder to clone into",
"giteaClone.apiError": "Error connecting to Gitea API.", "giteaClone.targetExists": "The target directory \"{0}\" already exists.",
"giteaClone.noRepos": "No repositories found.", "giteaClone.cloningRepo": "Cloning {0}",
"giteaClone.selectRepo": "Select a repository to clone", "giteaClone.cloningProgress": "Cloning in progress...",
"giteaClone.noRepoSelected": "No repository selected.", "giteaClone.cloneComplete": "Repository cloned successfully.",
"giteaClone.selectFolder": "Select folder to clone into", "giteaClone.cloneSuccess": "Repository {0} cloned successfully.",
"giteaClone.cloningRepo": "Cloning {0}", "giteaClone.openRepoError": "Error opening the cloned repository.",
"giteaClone.cloningProgress": "Cloning in progress...", "giteaClone.createPullRequest": "Create Gitea PR",
"giteaClone.cloneComplete": "Repository cloned successfully.", "giteaClone.createPullRequestTooltip": "Create a Pull Request in Gitea",
"giteaClone.cloneSuccess": "Repository {0} cloned successfully.", "giteaClone.pullRequestCreated": "Pull request created successfully and opened in the browser.",
"giteaClone.cloneError": "Error cloning the repository.", "giteaClone.noRemoteUrl": "Could not retrieve Git remote URL.",
"giteaClone.noFolderSelected": "No target folder selected.", "giteaClone.noBranch": "Could not determine the branch.",
"giteaClone.noSshUrl": "Could not find SSH clone URL.", "giteaClone.titleTruncated": "The commit message was too long and has been truncated for the pull request title.",
"giteaClone.openRepoError": "Error opening the cloned repository.", "giteaClone.bodyTruncated": "The commit message body was too long and has been truncated for the pull request description.",
"giteaClone.noOpenPRs": "There are no open pull requests.", "giteaClone.pullRequestError": "Error creating pull request: {0}",
"giteaClone.selectPullRequest": "Select a pull request to view", "giteaClone.commitError": "Error retrieving the last commit.",
"giteaClone.repoInfoError": "Could not retrieve repository information.", "giteaClone.branchError": "Error retrieving the branch.",
"giteaClone.showOpenPullRequestsTooltip": "Show open pull requests", "giteaClone.defaultBranchError": "Error retrieving the base branch: {0}",
"giteaClone.targetExists": "The target directory \"{0}\" already exists.", "giteaClone.repoError": "Error retrieving repositories.",
"giteaClone.pullRequestError": "Error creating pull request: {0}", "giteaClone.repoInfoError": "Could not retrieve repository information.",
"giteaClone.defaultBranchError": "Error retrieving the base branch: {0}", "giteaClone.pullRequestsError": "Error retrieving pull requests: {0}",
"giteaClone.repoError": "Error retrieving repositories: {0}", "giteaClone.noOpenPRs": "No open pull requests available.",
"giteaClone.authFailed": "Authentication failed: {0}", "giteaClone.selectPullRequest": "Select a pull request to view",
"giteaClone.pullRequestsError": "Error retrieving pull requests: {0}", "giteaClone.showOpenPullRequestsTooltip": "Show open pull requests",
"giteaClone.titleTruncated": "The commit message was too long and has been truncated for the pull request title.", "giteaClone.branchStatusTooltip": "Current branch status",
"giteaClone.bodyTruncated": "The commit message body was too long and has been truncated for the pull request description." "giteaClone.buildStatusTooltip": "Build status of the current commit"
} }

View File

@ -33,7 +33,8 @@
}, },
{ {
"command": "gitea.configure", "command": "gitea.configure",
"title": " Configure URL" "title": " Configure URL",
"category": "Gitea"
}, },
{ {
"command": "gitea.cloneRepository", "command": "gitea.cloneRepository",
@ -47,16 +48,31 @@
} }
], ],
"configuration": { "configuration": {
"type": "object",
"title": "Gitea Extension Configuration",
"properties": { "properties": {
"gitea.instanceUrl": { "gitea.instances": {
"type": "string", "type": "array",
"default": "https://your-gitea-instance.com", "description": "List of Gitea instances and their configurations.",
"description": "URL of your Gitea intance" "items": {
}, "type": "object",
"gitea.personalAccessToken": { "properties": {
"type": "string", "name": {
"description": "Personal Access Token for Gitea", "type": "string",
"secret": true "description": "Name of the Gitea instance."
},
"url": {
"type": "string",
"description": "URL of the Gitea instance."
},
"token": {
"type": "string",
"description": "Personal Access Token for the Gitea instance."
}
},
"required": ["name", "url", "token"]
},
"default": []
} }
} }
} }

View File

@ -19,33 +19,46 @@ interface GiteaErrorResponse {
}>; }>;
} }
// Interface für Gitea-Instanzen
interface GiteaInstance {
name: string;
url: string;
token: string;
}
// Initialisiere die Lokalisierung // Initialisiere die Lokalisierung
const localize = nls.config({ messageFormat: nls.MessageFormat.file })(); const localize = nls.config({ messageFormat: nls.MessageFormat.file })();
// Globale Variablen für Statusleisten-Icons // Globale Variablen für Statusleisten-Icons
let statusBarItem: vscode.StatusBarItem | null = null; let statusBarItem: vscode.StatusBarItem | null = null;
let prStatusBarItem: vscode.StatusBarItem | null = null; let prStatusBarItem: vscode.StatusBarItem | null = null;
let branchStatusBarItem: vscode.StatusBarItem | null = null;
let buildStatusBarItem: vscode.StatusBarItem | null = null;
// Hilfsfunktion, um zu prüfen, ob ein Ordner ein Git-Repository ist // Hilfsfunktion, um die Gitea-Instanzen zu laden
async function isGitRepository(folderPath: string): Promise<boolean> { function getGiteaInstances(): GiteaInstance[] {
return new Promise((resolve) => { const instances = vscode.workspace.getConfiguration().get<any[]>('gitea.instances');
exec(`git rev-parse --is-inside-work-tree`, { cwd: folderPath }, (error) => { if (!instances) {
resolve(!error); return [];
}); }
}); return instances.map((instance) => ({
name: instance.name,
url: instance.url,
token: instance.token,
}));
} }
// Hilfsfunktion, um zu prüfen, ob das Remote-Repository eine Gitea-Instanz ist // Hilfsfunktion, um die passende Gitea-Instanz basierend auf der Remote-URL zu ermitteln
async function isGiteaRepository(folderPath: string): Promise<boolean> { async function getMatchingGiteaInstance(folderPath: string): Promise<GiteaInstance | null> {
const instanceUrl = vscode.workspace.getConfiguration().get<string>('gitea.instanceUrl'); const instances = getGiteaInstances();
if (!instanceUrl) { if (instances.length === 0) {
return false; return null;
} }
return new Promise((resolve) => { return new Promise((resolve) => {
exec(`git config --get remote.origin.url`, { cwd: folderPath }, (error, stdout) => { exec(`git config --get remote.origin.url`, { cwd: folderPath }, (error, stdout) => {
if (error || !stdout) { if (error || !stdout) {
resolve(false); resolve(null);
} else { } else {
let repoUrl = stdout.trim(); let repoUrl = stdout.trim();
@ -59,22 +72,24 @@ async function isGiteaRepository(folderPath: string): Promise<boolean> {
repoUrl = repoUrl.replace('.git', ''); repoUrl = repoUrl.replace('.git', '');
} }
resolve(repoUrl.startsWith(instanceUrl)); const matchingInstance = instances.find((instance) => repoUrl.startsWith(instance.url));
resolve(matchingInstance || null);
} }
}); });
}); });
} }
// Hilfsfunktion, um zu prüfen, ob ein Ordner ein Git-Repository ist
async function isGitRepository(folderPath: string): Promise<boolean> {
return new Promise((resolve) => {
exec(`git rev-parse --is-inside-work-tree`, { cwd: folderPath }, (error) => {
resolve(!error);
});
});
}
// Funktion zum Erstellen eines Pull Requests // Funktion zum Erstellen eines Pull Requests
async function createGiteaPullRequest() { 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(localize('giteaClone.configMissing', 'Gitea URL or Token is not configured.'));
return;
}
// Aktuellen Workspace-Ordner abrufen // Aktuellen Workspace-Ordner abrufen
const currentWorkspaceFolder = vscode.workspace.workspaceFolders?.[0]?.uri?.fsPath; const currentWorkspaceFolder = vscode.workspace.workspaceFolders?.[0]?.uri?.fsPath;
if (!currentWorkspaceFolder) { if (!currentWorkspaceFolder) {
@ -89,13 +104,16 @@ async function createGiteaPullRequest() {
return; return;
} }
// Prüfen, ob Remote-Repository eine Gitea-Instanz ist // Passende Gitea-Instanz ermitteln
const isGiteaRepo = await isGiteaRepository(currentWorkspaceFolder); const giteaInstance = await getMatchingGiteaInstance(currentWorkspaceFolder);
if (!isGiteaRepo) { if (!giteaInstance) {
// Kein Gitea-Repository, keine Aktion erforderlich // Keine passende Gitea-Instanz gefunden
return; return;
} }
const instanceUrl = giteaInstance.url;
const token = giteaInstance.token;
// Git-Repository-Informationen abrufen // Git-Repository-Informationen abrufen
exec(`git config --get remote.origin.url`, { cwd: currentWorkspaceFolder }, async (error, stdout, stderr) => { exec(`git config --get remote.origin.url`, { cwd: currentWorkspaceFolder }, async (error, stdout, stderr) => {
if (error || !stdout) { if (error || !stdout) {
@ -122,32 +140,32 @@ async function createGiteaPullRequest() {
// Den letzten Commit und den Branch abrufen // Den letzten Commit und den Branch abrufen
const { title, body } = await getLastCommit(currentWorkspaceFolder); const { title, body } = await getLastCommit(currentWorkspaceFolder);
const branch = await getCurrentBranch(currentWorkspaceFolder); const branch = await getCurrentBranch(currentWorkspaceFolder);
if (!branch) { if (!branch) {
vscode.window.showErrorMessage(localize('giteaClone.noBranch', 'Could not determine the branch.')); vscode.window.showErrorMessage(localize('giteaClone.noBranch', 'Could not determine the branch.'));
return; return;
} }
// Base-Branch über die Gitea API ermitteln // Base-Branch über die Gitea API ermitteln
const baseBranch = await getDefaultBranch(instanceUrl, owner, repo, token); const baseBranch = await getDefaultBranch(instanceUrl, owner, repo, token);
// Titel und Body auf maximale Länge beschränken // Titel und Body auf maximale Länge beschränken
const maxTitleLength = 255; const maxTitleLength = 255;
const maxBodyLength = 65535; // Beispielwert, kann je nach Gitea-Konfiguration variieren const maxBodyLength = 65535; // Beispielwert, kann je nach Gitea-Konfiguration variieren
let truncatedTitle = title; let truncatedTitle = title;
let truncatedBody = body; let truncatedBody = body;
if (title.length > maxTitleLength) { if (title.length > maxTitleLength) {
truncatedTitle = title.substring(0, maxTitleLength); truncatedTitle = title.substring(0, maxTitleLength);
vscode.window.showWarningMessage(localize('giteaClone.titleTruncated', 'The commit message was too long and has been truncated for the pull request title.')); vscode.window.showWarningMessage(localize('giteaClone.titleTruncated', 'The commit message was too long and has been truncated for the pull request title.'));
} }
if (body.length > maxBodyLength) { if (body.length > maxBodyLength) {
truncatedBody = body.substring(0, maxBodyLength); truncatedBody = body.substring(0, maxBodyLength);
vscode.window.showWarningMessage(localize('giteaClone.bodyTruncated', 'The commit message body was too long and has been truncated for the pull request description.')); vscode.window.showWarningMessage(localize('giteaClone.bodyTruncated', 'The commit message body was too long and has been truncated for the pull request description.'));
} }
// API-Request-Daten vorbereiten // API-Request-Daten vorbereiten
const prData = { const prData = {
title: truncatedTitle, // Der getrunkierte Titel title: truncatedTitle, // Der getrunkierte Titel
@ -277,14 +295,34 @@ async function getDefaultBranch(instanceUrl: string, owner: string, repo: string
// Funktion zum Abrufen der Repositories des Benutzers von Gitea // Funktion zum Abrufen der Repositories des Benutzers von Gitea
async function getGiteaRepositories(): Promise<any[]> { async function getGiteaRepositories(): Promise<any[]> {
const instanceUrl = vscode.workspace.getConfiguration().get<string>('gitea.instanceUrl'); const instances = getGiteaInstances();
const token = vscode.workspace.getConfiguration().get<string>('gitea.personalAccessToken');
if (!instanceUrl || !token) { if (instances.length === 0) {
vscode.window.showErrorMessage(localize('giteaClone.configMissing', 'Gitea URL or Token is not configured.')); vscode.window.showErrorMessage(localize('giteaClone.configMissing', 'No Gitea instances are configured.'));
return []; return [];
} }
// Benutzer wählt eine Gitea-Instanz aus
const instanceNames = instances.map(instance => instance.name);
const selectedInstanceName = await vscode.window.showQuickPick(instanceNames, {
placeHolder: localize('giteaClone.selectInstance', 'Select a Gitea instance')
});
if (!selectedInstanceName) {
vscode.window.showInformationMessage(localize('giteaClone.noInstanceSelected', 'No Gitea instance selected.'));
return [];
}
const selectedInstance = instances.find(instance => instance.name === selectedInstanceName);
if (!selectedInstance) {
vscode.window.showErrorMessage(localize('giteaClone.invalidInstance', 'Invalid Gitea instance selected.'));
return [];
}
const instanceUrl = selectedInstance.url;
const token = selectedInstance.token;
try { try {
const response = await axios.get(`${instanceUrl}/api/v1/user/repos`, { const response = await axios.get(`${instanceUrl}/api/v1/user/repos`, {
headers: { headers: {
@ -414,9 +452,10 @@ async function addStatusBarIcon() {
return null; return null;
} }
const isGiteaRepo = await isGiteaRepository(currentWorkspaceFolder); // Passende Gitea-Instanz ermitteln
if (!isGiteaRepo) { const giteaInstance = await getMatchingGiteaInstance(currentWorkspaceFolder);
// Kein Gitea-Repository if (!giteaInstance) {
// Keine passende Gitea-Instanz gefunden
return null; return null;
} }
@ -430,14 +469,34 @@ async function addStatusBarIcon() {
// 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() {
const instanceUrl = vscode.workspace.getConfiguration().get<string>('gitea.instanceUrl'); const instances = getGiteaInstances();
const token = vscode.workspace.getConfiguration().get<string>('gitea.personalAccessToken');
if (!instanceUrl || !token) { if (instances.length === 0) {
vscode.window.showErrorMessage(localize('giteaClone.configMissing', 'Gitea URL or Token is not configured.')); vscode.window.showErrorMessage(localize('giteaClone.configMissing', 'No Gitea instances are configured.'));
return; return;
} }
// Benutzer wählt eine Gitea-Instanz aus
const instanceNames = instances.map(instance => instance.name);
const selectedInstanceName = await vscode.window.showQuickPick(instanceNames, {
placeHolder: localize('giteaClone.selectInstance', 'Select a Gitea instance to authenticate')
});
if (!selectedInstanceName) {
vscode.window.showInformationMessage(localize('giteaClone.noInstanceSelected', 'No Gitea instance selected.'));
return;
}
const selectedInstance = instances.find(instance => instance.name === selectedInstanceName);
if (!selectedInstance) {
vscode.window.showErrorMessage(localize('giteaClone.invalidInstance', 'Invalid Gitea instance selected.'));
return;
}
const instanceUrl = selectedInstance.url;
const token = selectedInstance.token;
try { try {
const response = await axios.get(`${instanceUrl}/api/v1/user`, { const response = await axios.get(`${instanceUrl}/api/v1/user`, {
headers: { headers: {
@ -471,36 +530,82 @@ async function authenticateGitea() {
} }
} }
// Funktion zur Konfiguration der Gitea-Instanz und des Tokens über die Command Palette // Funktion zur Konfiguration der Gitea-Instanzen und Tokens über die Command Palette
async function configureGitea() { async function configureGitea() {
const instanceUrl = await vscode.window.showInputBox({ const instances = getGiteaInstances();
prompt: localize('giteaClone.enterInstanceUrl', 'Enter Gitea instance URL'),
placeHolder: 'https://your-gitea-instance.com' // Benutzer fragt, ob er eine neue Instanz hinzufügen oder eine bestehende bearbeiten möchte
const action = await vscode.window.showQuickPick(['Add New Instance', 'Edit Existing Instance'], {
placeHolder: 'What would you like to do?'
}); });
const token = await vscode.window.showInputBox({ if (action === 'Add New Instance') {
prompt: localize('giteaClone.enterToken', 'Enter Gitea Personal Access Token'), // Neue Instanz hinzufügen
placeHolder: 'token', const name = await vscode.window.showInputBox({
password: true prompt: 'Enter a name for the Gitea instance',
}); placeHolder: 'e.g., Company Gitea'
});
if (instanceUrl && token) { const instanceUrl = await vscode.window.showInputBox({
await vscode.workspace.getConfiguration().update('gitea.instanceUrl', instanceUrl, vscode.ConfigurationTarget.Global); prompt: localize('giteaClone.enterInstanceUrl', 'Enter Gitea instance URL'),
await vscode.workspace.getConfiguration().update('gitea.personalAccessToken', token, vscode.ConfigurationTarget.Global); placeHolder: 'https://your-gitea-instance.com'
vscode.window.showInformationMessage(localize('giteaClone.configUpdated', 'Gitea configuration updated.')); });
const token = await vscode.window.showInputBox({
prompt: localize('giteaClone.enterToken', 'Enter Gitea Personal Access Token'),
placeHolder: 'token',
password: true
});
if (name && instanceUrl && token) {
instances.push({ name, url: instanceUrl, token });
await vscode.workspace.getConfiguration().update('gitea.instances', instances, vscode.ConfigurationTarget.Global);
vscode.window.showInformationMessage(localize('giteaClone.configUpdated', 'Gitea configuration updated.'));
}
} else if (action === 'Edit Existing Instance') {
// Existierende Instanz bearbeiten
const instanceNames = instances.map(instance => instance.name);
const selectedInstanceName = await vscode.window.showQuickPick(instanceNames, {
placeHolder: 'Select a Gitea instance to edit'
});
if (!selectedInstanceName) {
vscode.window.showInformationMessage(localize('giteaClone.noInstanceSelected', 'No Gitea instance selected.'));
return;
}
const selectedInstanceIndex = instances.findIndex(instance => instance.name === selectedInstanceName);
const selectedInstance = instances[selectedInstanceIndex];
const name = await vscode.window.showInputBox({
prompt: 'Enter a name for the Gitea instance',
placeHolder: 'e.g., Company Gitea',
value: selectedInstance.name
});
const instanceUrl = await vscode.window.showInputBox({
prompt: localize('giteaClone.enterInstanceUrl', 'Enter Gitea instance URL'),
placeHolder: 'https://your-gitea-instance.com',
value: selectedInstance.url
});
const token = await vscode.window.showInputBox({
prompt: localize('giteaClone.enterToken', 'Enter Gitea Personal Access Token'),
placeHolder: 'token',
password: true,
value: selectedInstance.token
});
if (name && instanceUrl && token) {
instances[selectedInstanceIndex] = { name, url: instanceUrl, token };
await vscode.workspace.getConfiguration().update('gitea.instances', instances, vscode.ConfigurationTarget.Global);
vscode.window.showInformationMessage(localize('giteaClone.configUpdated', 'Gitea configuration updated.'));
}
} }
} }
// Funktion zum Abrufen offener Pull Requests // Funktion zum Abrufen offener Pull Requests
async function getOpenPullRequests(): Promise<any[]> { 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 Workspace-Ordner abrufen // Aktuellen Workspace-Ordner abrufen
const currentWorkspaceFolder = vscode.workspace.workspaceFolders?.[0]?.uri?.fsPath; const currentWorkspaceFolder = vscode.workspace.workspaceFolders?.[0]?.uri?.fsPath;
if (!currentWorkspaceFolder) { if (!currentWorkspaceFolder) {
@ -514,16 +619,20 @@ async function getOpenPullRequests(): Promise<any[]> {
return []; return [];
} }
const isGiteaRepo = await isGiteaRepository(currentWorkspaceFolder); // Passende Gitea-Instanz ermitteln
if (!isGiteaRepo) { const giteaInstance = await getMatchingGiteaInstance(currentWorkspaceFolder);
// Kein Gitea-Repository if (!giteaInstance) {
// Keine passende Gitea-Instanz gefunden
return []; return [];
} }
const instanceUrl = giteaInstance.url;
const token = giteaInstance.token;
// Git-Repository-Informationen abrufen // Git-Repository-Informationen abrufen
const { owner, repo } = await getRepoInfo(currentWorkspaceFolder); const { owner, repo } = await getRepoInfo(currentWorkspaceFolder);
if (!owner || !repo) { if (!owner || !repo) {
vscode.window.showErrorMessage(localize('giteaClone.repoInfoError', 'Konnte Repository-Informationen nicht abrufen.')); vscode.window.showErrorMessage(localize('giteaClone.repoInfoError', 'Could not retrieve repository information.'));
return []; return [];
} }
@ -540,7 +649,7 @@ async function getOpenPullRequests(): Promise<any[]> {
if (response.status === 200) { if (response.status === 200) {
return response.data; return response.data;
} else { } else {
vscode.window.showErrorMessage(localize('giteaClone.pullRequestsError', 'Fehler beim Abrufen der Pull Requests.')); vscode.window.showErrorMessage(localize('giteaClone.pullRequestsError', 'Error retrieving pull requests.'));
return []; return [];
} }
} catch (err: any) { } catch (err: any) {
@ -572,7 +681,7 @@ async function getRepoInfo(folderPath: string): Promise<{ owner: string, repo: s
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
exec(`git config --get remote.origin.url`, { cwd: folderPath }, (error, stdout) => { exec(`git config --get remote.origin.url`, { cwd: folderPath }, (error, stdout) => {
if (error || !stdout) { if (error || !stdout) {
reject(localize('giteaClone.noRemoteUrl', 'Konnte Git-Remote-URL nicht abrufen.')); reject(localize('giteaClone.noRemoteUrl', 'Could not retrieve Git remote URL.'));
} else { } else {
let repoUrl = stdout.trim(); let repoUrl = stdout.trim();
@ -598,18 +707,18 @@ async function showOpenPullRequests() {
const pullRequests = await getOpenPullRequests(); const pullRequests = await getOpenPullRequests();
if (pullRequests.length === 0) { if (pullRequests.length === 0) {
vscode.window.showInformationMessage(localize('giteaClone.noOpenPRs', 'Keine offenen Pull Requests vorhanden.')); vscode.window.showInformationMessage(localize('giteaClone.noOpenPRs', 'No open pull requests available.'));
return; return;
} }
const prItems = pullRequests.map(pr => ({ const prItems = pullRequests.map(pr => ({
label: `#${pr.number}: ${pr.title}`, label: `#${pr.number}: ${pr.title}`,
description: `von ${pr.user.username}`, description: `by ${pr.user.username}`,
pr pr
})); }));
const selectedPr = await vscode.window.showQuickPick(prItems, { const selectedPr = await vscode.window.showQuickPick(prItems, {
placeHolder: localize('giteaClone.selectPullRequest', 'Wähle einen Pull Request zum Anzeigen aus') placeHolder: localize('giteaClone.selectPullRequest', 'Select a pull request to view')
}); });
if (selectedPr) { if (selectedPr) {
@ -633,8 +742,9 @@ async function updatePRStatusBarItem(context: vscode.ExtensionContext) {
return; return;
} }
const isGiteaRepo = await isGiteaRepository(currentWorkspaceFolder); // Passende Gitea-Instanz ermitteln
if (!isGiteaRepo) { const giteaInstance = await getMatchingGiteaInstance(currentWorkspaceFolder);
if (!giteaInstance) {
if (prStatusBarItem) prStatusBarItem.hide(); if (prStatusBarItem) prStatusBarItem.hide();
return; return;
} }
@ -644,7 +754,7 @@ async function updatePRStatusBarItem(context: vscode.ExtensionContext) {
if (!prStatusBarItem) { if (!prStatusBarItem) {
prStatusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left); prStatusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
prStatusBarItem.command = 'gitea.showOpenPullRequests'; prStatusBarItem.command = 'gitea.showOpenPullRequests';
prStatusBarItem.tooltip = localize('giteaClone.showOpenPullRequestsTooltip', 'Offene Pull Requests anzeigen'); prStatusBarItem.tooltip = localize('giteaClone.showOpenPullRequestsTooltip', 'Show open pull requests');
context.subscriptions.push(prStatusBarItem); context.subscriptions.push(prStatusBarItem);
} }
@ -652,26 +762,179 @@ async function updatePRStatusBarItem(context: vscode.ExtensionContext) {
prStatusBarItem.text = `$(git-pull-request) Gitea Open PRs: ${prCount}`; prStatusBarItem.text = `$(git-pull-request) Gitea Open PRs: ${prCount}`;
prStatusBarItem.show(); prStatusBarItem.show();
} catch (error) { } catch (error) {
console.error('Fehler beim Aktualisieren des PR-Statusleisten-Icons:', error); console.error('Error updating PR status bar item:', error);
if (prStatusBarItem) { if (prStatusBarItem) {
prStatusBarItem.hide(); prStatusBarItem.hide();
} }
} }
} }
// Funktion zum Starten des PR-Statusleisten-Updaters // Funktion zum Aktualisieren des Branch-Statusleisten-Icons
function startPRStatusBarItemUpdater(context: vscode.ExtensionContext) { async function updateBranchStatusBarItem() {
updatePRStatusBarItem(context); // Initiales Update try {
const currentWorkspaceFolder = vscode.workspace.workspaceFolders?.[0]?.uri?.fsPath;
if (!currentWorkspaceFolder) {
if (branchStatusBarItem) branchStatusBarItem.hide();
return;
}
const isGitRepo = await isGitRepository(currentWorkspaceFolder);
if (!isGitRepo) {
if (branchStatusBarItem) branchStatusBarItem.hide();
return;
}
const branch = await getCurrentBranch(currentWorkspaceFolder);
if (!branchStatusBarItem) {
branchStatusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
branchStatusBarItem.tooltip = localize('giteaClone.branchStatusTooltip', 'Current branch status');
branchStatusBarItem.command = 'git.checkout';
}
// Überprüfen, ob der Branch up-to-date ist
const branchStatus = await getBranchStatus(currentWorkspaceFolder, branch);
branchStatusBarItem.text = `$(git-branch) ${branch} ${branchStatus}`;
branchStatusBarItem.show();
} catch (error) {
console.error('Error updating branch status bar item:', error);
if (branchStatusBarItem) {
branchStatusBarItem.hide();
}
}
}
// Hilfsfunktion, um den Branch-Status zu ermitteln
async function getBranchStatus(folderPath: string, branch: string): Promise<string> {
return new Promise((resolve) => {
exec(`git status -sb`, { cwd: folderPath }, (error, stdout) => {
if (error || !stdout) {
resolve('');
} else {
const statusLine = stdout.split('\n')[0];
const aheadMatch = /\[ahead (\d+)\]/.exec(statusLine);
const behindMatch = /\[behind (\d+)\]/.exec(statusLine);
let status = '';
if (aheadMatch) {
status += `${aheadMatch[1]}`;
}
if (behindMatch) {
status += `${behindMatch[1]}`;
}
resolve(status);
}
});
});
}
// Funktion zum Aktualisieren des Build-Statusleisten-Icons
async function updateBuildStatusBarItem() {
try {
const currentWorkspaceFolder = vscode.workspace.workspaceFolders?.[0]?.uri?.fsPath;
if (!currentWorkspaceFolder) {
if (buildStatusBarItem) buildStatusBarItem.hide();
return;
}
const isGitRepo = await isGitRepository(currentWorkspaceFolder);
if (!isGitRepo) {
if (buildStatusBarItem) buildStatusBarItem.hide();
return;
}
// Passende Gitea-Instanz ermitteln
const giteaInstance = await getMatchingGiteaInstance(currentWorkspaceFolder);
if (!giteaInstance) {
if (buildStatusBarItem) buildStatusBarItem.hide();
return;
}
const instanceUrl = giteaInstance.url;
const token = giteaInstance.token;
// Git-Repository-Informationen abrufen
const { owner, repo } = await getRepoInfo(currentWorkspaceFolder);
if (!owner || !repo) {
if (buildStatusBarItem) buildStatusBarItem.hide();
return;
}
// Aktuellen Commit-Hash abrufen
const commitHash = await getCurrentCommitHash(currentWorkspaceFolder);
// Build-Status von Gitea abrufen
const buildStatus = await getBuildStatus(instanceUrl, owner, repo, commitHash, token);
if (!buildStatusBarItem) {
buildStatusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
buildStatusBarItem.tooltip = localize('giteaClone.buildStatusTooltip', 'Build status of the current commit');
}
buildStatusBarItem.text = `$(gear) Build: ${buildStatus}`;
buildStatusBarItem.show();
} catch (error) {
console.error('Error updating build status bar item:', error);
if (buildStatusBarItem) {
buildStatusBarItem.hide();
}
}
}
// Hilfsfunktion, um den aktuellen Commit-Hash zu ermitteln
async function getCurrentCommitHash(folderPath: string): Promise<string> {
return new Promise((resolve) => {
exec(`git rev-parse HEAD`, { cwd: folderPath }, (error, stdout) => {
if (error || !stdout) {
resolve('');
} else {
resolve(stdout.trim());
}
});
});
}
// Hilfsfunktion, um den Build-Status von Gitea abzurufen
async function getBuildStatus(instanceUrl: string, owner: string, repo: string, commitHash: string, token: string): Promise<string> {
try {
const response = await axios.get(`${instanceUrl}/api/v1/repos/${owner}/${repo}/statuses/${commitHash}`, {
headers: {
'Authorization': `token ${token}`
}
});
if (response.status === 200 && response.data.length > 0) {
const latestStatus = response.data[0];
return latestStatus.state;
} else {
return 'unknown';
}
} catch (error) {
console.error('Error fetching build status:', error);
return 'unknown';
}
}
// Funktion zum Starten des Build- und Branch-Status-Updaters
function startStatusBarItemUpdater(context: vscode.ExtensionContext) {
updateBranchStatusBarItem();
updateBuildStatusBarItem();
// Aktualisiere bei Fokuswechsel // Aktualisiere bei Fokuswechsel
vscode.window.onDidChangeWindowState((windowState) => { vscode.window.onDidChangeWindowState((windowState) => {
if (windowState.focused) { if (windowState.focused) {
updatePRStatusBarItem(context); updateBranchStatusBarItem();
updateBuildStatusBarItem();
} }
}, null, context.subscriptions); }, null, context.subscriptions);
// Aktualisiere alle 5 Minuten // Aktualisiere alle 2 Minuten
setInterval(() => updatePRStatusBarItem(context), 300000); // 5 Minuten setInterval(() => {
updateBranchStatusBarItem();
updateBuildStatusBarItem();
}, 120000); // 2 Minuten
} }
// Aktivierungsfunktion des Plugins // Aktivierungsfunktion des Plugins
@ -706,35 +969,38 @@ export async function activate(context: vscode.ExtensionContext) {
vscode.workspace.onDidChangeWorkspaceFolders(async () => { vscode.workspace.onDidChangeWorkspaceFolders(async () => {
if (statusBarItem) { if (statusBarItem) {
const currentWorkspaceFolder = vscode.workspace.workspaceFolders?.[0]?.uri?.fsPath; const currentWorkspaceFolder = vscode.workspace.workspaceFolders?.[0]?.uri?.fsPath;
if (currentWorkspaceFolder && await isGitRepository(currentWorkspaceFolder) && await isGiteaRepository(currentWorkspaceFolder)) { if (currentWorkspaceFolder && await isGitRepository(currentWorkspaceFolder) && await getMatchingGiteaInstance(currentWorkspaceFolder)) {
if (statusBarItem) { statusBarItem.show();
statusBarItem.show();
}
} else { } else {
statusBarItem.hide(); statusBarItem.hide();
} }
} }
await updatePRStatusBarItem(context); await updatePRStatusBarItem(context);
updateBranchStatusBarItem();
updateBuildStatusBarItem();
}); });
vscode.window.onDidChangeActiveTextEditor(async () => { vscode.window.onDidChangeActiveTextEditor(async () => {
if (statusBarItem) { if (statusBarItem) {
const currentWorkspaceFolder = vscode.workspace.workspaceFolders?.[0]?.uri?.fsPath; const currentWorkspaceFolder = vscode.workspace.workspaceFolders?.[0]?.uri?.fsPath;
if (currentWorkspaceFolder && await isGitRepository(currentWorkspaceFolder) && await isGiteaRepository(currentWorkspaceFolder)) { if (currentWorkspaceFolder && await isGitRepository(currentWorkspaceFolder) && await getMatchingGiteaInstance(currentWorkspaceFolder)) {
if (statusBarItem) { statusBarItem.show();
statusBarItem.show();
}
} else { } else {
statusBarItem.hide(); statusBarItem.hide();
} }
} }
await updatePRStatusBarItem(context); await updatePRStatusBarItem(context);
updateBranchStatusBarItem();
updateBuildStatusBarItem();
}); });
// Starten Sie den PR-Statusleisten-Updater // Starten Sie den PR-Statusleisten-Updater
startPRStatusBarItemUpdater(context); startStatusBarItemUpdater(context);
// Starten Sie den Branch- und Build-Statusleisten-Updater
startStatusBarItemUpdater(context);
} }
// Deaktivierungsfunktion des Plugins // Deaktivierungsfunktion des Plugins