Skip to content

Commit

Permalink
fix: use types for Git extension
Browse files Browse the repository at this point in the history
  • Loading branch information
ShawkyZ committed Oct 14, 2024
1 parent 2997997 commit 609e890
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
23 changes: 23 additions & 0 deletions src/snyk/common/git.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as vscode from 'vscode';

export interface GitExtension {
getAPI(version: number): GitAPI;
}

export interface GitAPI {
repositories: Repository[];
}

export interface Repository {
rootUri: vscode.Uri;
state: RepositoryState;
}

export interface RepositoryState {
HEAD: Branch | undefined;
onDidChange: vscode.Event<void>;
}

export interface Branch {
name?: string;
}
12 changes: 6 additions & 6 deletions src/snyk/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ import { DiagnosticsIssueProvider } from './common/services/diagnosticsService';
import { CodeIssueData, IacIssueData, OssIssueData } from './common/languageServer/types';
import { ClearCacheService } from './common/services/CacheService';
import { InMemory, Persisted } from './common/constants/general';
import { GitAPI, GitExtension, Repository } from './common/git';

class SnykExtension extends SnykLib implements IExtension {
public async activate(vscodeContext: vscode.ExtensionContext): Promise<void> {
Expand All @@ -100,26 +101,25 @@ class SnykExtension extends SnykLib implements IExtension {
}
}

// @ts-nocheck: we use any to prevent loading types from external extension
private configureGitHandlers(): void {
// Get the Git extension
const gitExtension = vscode.extensions.getExtension('vscode.git')?.exports;
const gitExtension = vscode.extensions.getExtension<GitExtension>('vscode.git')?.exports;

if (!gitExtension) {
return;
}

// Get the API from the Git extension
const git = gitExtension.getAPI(1);
const git: GitAPI = gitExtension.getAPI(1);

// Check if there are any repositories
const repositories = git?.repositories;
const repositories: Repository[] = git?.repositories;
if (!repositories || repositories.length === 0) {
return;
}
const previousBranches = new Map<any, string | undefined>();
const previousBranches = new Map<Repository, string | undefined>();
// Register event listener for changes in each repository
repositories.forEach((repo: any) => {
repositories.forEach((repo: Repository) => {
let previousBranch = repo.state.HEAD?.name;
previousBranches.set(repo, previousBranch);
repo.state.onDidChange(async () => {
Expand Down

0 comments on commit 609e890

Please sign in to comment.