Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 55 additions & 3 deletions src/platform/remoteCodeSearch/node/codeSearchRepoTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { AdoRepoId, getGithubRepoIdFromFetchUrl, getOrderedRemoteUrlsFromContext
import { Change } from '../../git/vscode/git';
import { logExecTime, LogExecTime } from '../../log/common/logExecTime';
import { ILogService } from '../../log/common/logService';
import { isGitHubRemoteRepository } from '../../remoteRepositories/common/utils';
import { isAzureDevOpsRemoteRepository, isGitHubRemoteRepository } from '../../remoteRepositories/common/utils';
import { ISimulationTestContext } from '../../simulationTestContext/common/simulationTestContext';
import { ITelemetryService } from '../../telemetry/common/telemetry';
import { IWorkspaceService } from '../../workspace/common/workspaceService';
Expand Down Expand Up @@ -235,6 +235,7 @@ export class CodeSearchRepoTracker extends Disposable {

private readonly _initializedGitReposP: CancelablePromise<void>;
private readonly _initializedGitHubRemoteReposP: CancelablePromise<void>;
private readonly _initializedAdoRemoteReposP: CancelablePromise<void>;

private _isDisposed = false;

Expand Down Expand Up @@ -300,6 +301,32 @@ export class CodeSearchRepoTracker extends Disposable {
}
});

this._initializedAdoRemoteReposP = createCancelablePromise(async (token) => {
try {
const adoRemoteRepos = this._workspaceService.getWorkspaceFolders().filter(isAzureDevOpsRemoteRepository);
if (!adoRemoteRepos.length) {
return;
}

this._logService.trace(`CodeSearchRepoTracker.initAdoRemoteRepos(): started`);

await raceCancellationError(
Promise.all(adoRemoteRepos.map(workspaceRoot => {
// URI format: vscode-vfs://azurerepos/{OrgName}/{ProjectName}/{RepoName}
const adoRepoIdParts = workspaceRoot.path.slice(1).split('/');
if (adoRepoIdParts.length !== 3) {
this._logService.error(`CodeSearchRepoTracker.initAdoRemoteRepos(): Invalid ADO remote repo URI format: ${workspaceRoot}. Expected format: vscode-vfs://azurerepos/{OrgName}/{ProjectName}/{RepoName}`);
return Promise.resolve();
}
return this.openAdoRemoteRepo(workspaceRoot, new AdoRepoId(adoRepoIdParts[0], adoRepoIdParts[1], adoRepoIdParts[2]));
})),
token);
this._logService.trace(`CodeSearchRepoTracker.initAdoRemoteRepos(): complete`);
} catch (e) {
this._logService.error(`CodeSearchRepoTracker.initAdoRemoteRepos(): Error occurred during initialization: ${e}`);
}
});

const refreshInterval = this._register(new IntervalTimer());
refreshInterval.cancelAndSet(() => this.updateIndexedCommitForAllRepos(), 5 * 60 * 1000); // 5 minutes

Expand Down Expand Up @@ -330,7 +357,8 @@ export class CodeSearchRepoTracker extends Disposable {
// Find all initial repos
await Promise.all([
this._initializedGitReposP,
this._initializedGitHubRemoteReposP
this._initializedGitHubRemoteReposP,
this._initializedAdoRemoteReposP
]);

if (this._isDisposed) {
Expand Down Expand Up @@ -382,6 +410,7 @@ export class CodeSearchRepoTracker extends Disposable {

this._initializedGitReposP.cancel();
this._initializedGitHubRemoteReposP.cancel();
this._initializedAdoRemoteReposP.cancel();
}

getAllRepos(): Iterable<RepoEntry> {
Expand Down Expand Up @@ -562,6 +591,29 @@ export class CodeSearchRepoTracker extends Disposable {
return initP;
}

private openAdoRemoteRepo(rootUri: URI, adoId: AdoRepoId): Promise<void> {
this._logService.trace(`CodeSearchRepoTracker.openAdoRemoteRepo(${rootUri})`);

const existing = this._repos.get(rootUri);
if (existing) {
if (existing.status === RepoStatus.Initializing) {
return existing.initTask.p;
}
}

const repo: RepoInfo = { rootUri };
const remoteInfo: ResolvedRepoRemoteInfo = {
repoId: adoId,
fetchUrl: undefined,
};

const initCancellationTokenSource = new CancellationTokenSource();
const initP = this.updateRepoStateFromEndpoint(repo, remoteInfo, false, initCancellationTokenSource.token).then(() => { });

this._repos.set(rootUri, { status: RepoStatus.Initializing, repo, initTask: { p: initP, cts: initCancellationTokenSource } });
return initP;
}

private async getRemoteInfosForRepo(repo: RepoContext): Promise<ResolvedRepoRemoteInfo[]> {
const remoteInfos = Array.from(getOrderedRepoInfosFromContext(repo));

Expand Down Expand Up @@ -951,7 +1003,7 @@ export class CodeSearchRepoTracker extends Disposable {
}

public async diffWithIndexedCommit(repoInfo: RepoEntry): Promise<CodeSearchDiff | undefined> {
if (isGitHubRemoteRepository(repoInfo.repo.rootUri)) {
if (isGitHubRemoteRepository(repoInfo.repo.rootUri) || isAzureDevOpsRemoteRepository(repoInfo.repo.rootUri)) {
// TODO: always assumes no diff. Can we get a real diff somehow?
return { changes: [] };
}
Expand Down
4 changes: 4 additions & 0 deletions src/platform/remoteRepositories/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ import { URI } from '../../../util/vs/base/common/uri';
export function isGitHubRemoteRepository(uri: URI): boolean {
return uri.scheme === 'vscode-vfs' && uri.authority.startsWith('github');
}

export function isAzureDevOpsRemoteRepository(uri: URI): boolean {
return uri.scheme === 'vscode-vfs' && uri.authority.startsWith('azurerepos');
}
55 changes: 55 additions & 0 deletions src/platform/remoteRepositories/test/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import assert from 'assert';
import { suite, test } from 'vitest';
import { URI } from '../../../util/vs/base/common/uri';
import { isAzureDevOpsRemoteRepository, isGitHubRemoteRepository } from '../common/utils';

suite('Remote Repository Utils', () => {
suite('isGitHubRemoteRepository', () => {
test('should return true for GitHub remote repository URI', () => {
const uri = URI.parse('vscode-vfs://github/microsoft/vscode');
assert.strictEqual(isGitHubRemoteRepository(uri), true);
});

test('should return false for non-GitHub vscode-vfs URI', () => {
const uri = URI.parse('vscode-vfs://azurerepos/org/project/repo');
assert.strictEqual(isGitHubRemoteRepository(uri), false);
});

test('should return false for file URI', () => {
const uri = URI.parse('file:///path/to/repo');
assert.strictEqual(isGitHubRemoteRepository(uri), false);
});

test('should return false for other schemes', () => {
const uri = URI.parse('https://github.com/microsoft/vscode');
assert.strictEqual(isGitHubRemoteRepository(uri), false);
});
});

suite('isAzureDevOpsRemoteRepository', () => {
test('should return true for Azure DevOps remote repository URI', () => {
const uri = URI.parse('vscode-vfs://azurerepos/org/project/repo');
assert.strictEqual(isAzureDevOpsRemoteRepository(uri), true);
});

test('should return false for GitHub vscode-vfs URI', () => {
const uri = URI.parse('vscode-vfs://github/microsoft/vscode');
assert.strictEqual(isAzureDevOpsRemoteRepository(uri), false);
});

test('should return false for file URI', () => {
const uri = URI.parse('file:///path/to/repo');
assert.strictEqual(isAzureDevOpsRemoteRepository(uri), false);
});

test('should return false for other schemes', () => {
const uri = URI.parse('https://dev.azure.com/org/project/_git/repo');
assert.strictEqual(isAzureDevOpsRemoteRepository(uri), false);
});
});
});
Loading