Skip to content

Add getReviewerUsers method and improve reviewer management #7345

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
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
37 changes: 37 additions & 0 deletions src/@types/vscode.proposed.chatParticipantAdditions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,43 @@ declare module 'vscode' {
export const onDidChangeChatRequestTools: Event<ChatRequest>;
}

export class LanguageModelToolExtensionSource {
/**
* ID of the extension that published the tool.
*/
readonly id: string;

/**
* Label of the extension that published the tool.
*/
readonly label: string;

private constructor(id: string, label: string);
}

export class LanguageModelToolMCPSource {
/**
* Editor-configured label of the MCP server that published the tool.
*/
readonly label: string;

/**
* Server-defined name of the MCP server.
*/
readonly name: string;

/**
* Server-defined instructions for MCP tool use.
*/
readonly instructions?: string;

private constructor(label: string, name: string, instructions?: string);
}

export interface LanguageModelToolInformation {
source: LanguageModelToolExtensionSource | LanguageModelToolMCPSource | undefined;
}

// TODO@API fit this into the stream
export interface ChatUsedContext {
documents: ChatDocumentContext[];
Expand Down
43 changes: 41 additions & 2 deletions src/github/folderRepositoryManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,10 @@ export class FolderRepositoryManager extends Disposable {
private _mentionableUsers?: { [key: string]: IAccount[] };
private _fetchMentionableUsersPromise?: Promise<{ [key: string]: IAccount[] }>;
private _assignableUsers?: { [key: string]: IAccount[] };
private _reviewerUsers?: { [key: string]: IAccount[] };
private _teamReviewers?: { [key: string]: ITeam[] };
private _fetchAssignableUsersPromise?: Promise<{ [key: string]: IAccount[] }>;
private _fetchReviewerUsersPromise?: Promise<{ [key: string]: IAccount[] }>;
private _fetchTeamReviewersPromise?: Promise<{ [key: string]: ITeam[] }>;
private _gitBlameCache: { [key: string]: string } = {};
private _githubManager: GitHubManager;
Expand Down Expand Up @@ -561,6 +563,7 @@ export class FolderRepositoryManager extends Disposable {
}

this.getAssignableUsers(repositoriesAdded.length > 0);
this.getReviewerUsers(repositoriesAdded.length > 0);
if (isAuthenticated && activeRemotes.length) {
this._onDidLoadRepositories.fire(ReposManagerState.RepositoriesLoaded);
} else if (!isAuthenticated) {
Expand Down Expand Up @@ -632,7 +635,7 @@ export class FolderRepositoryManager extends Disposable {
return undefined;
}

private async getCachedFromGlobalState<T>(userKind: 'assignableUsers' | 'teamReviewers' | 'mentionableUsers' | 'orgProjects'): Promise<{ [key: string]: T[] } | undefined> {
private async getCachedFromGlobalState<T>(userKind: 'assignableUsers' | 'reviewerUsers' | 'teamReviewers' | 'mentionableUsers' | 'orgProjects'): Promise<{ [key: string]: T[] } | undefined> {
Logger.appendLine(`Trying to use globalState for ${userKind}.`, this.id);

const usersCacheLocation = vscode.Uri.joinPath(this.context.globalStorageUri, userKind);
Expand Down Expand Up @@ -676,7 +679,7 @@ export class FolderRepositoryManager extends Disposable {
return undefined;
}

private async saveInGlobalState<T>(userKind: 'assignableUsers' | 'teamReviewers' | 'mentionableUsers' | 'orgProjects', cache: { [key: string]: T[] }): Promise<void> {
private async saveInGlobalState<T>(userKind: 'assignableUsers' | 'reviewerUsers' | 'teamReviewers' | 'mentionableUsers' | 'orgProjects', cache: { [key: string]: T[] }): Promise<void> {
const cacheLocation = vscode.Uri.joinPath(this.context.globalStorageUri, userKind);
await Promise.all(this._githubRepositories.map(async (repo) => {
const key = `${repo.remote.owner}/${repo.remote.repositoryName}.json`;
Expand Down Expand Up @@ -760,6 +763,42 @@ export class FolderRepositoryManager extends Disposable {
return this._fetchAssignableUsersPromise;
}

async getReviewerUsers(clearCache?: boolean): Promise<{ [key: string]: IAccount[] }> {
if (clearCache) {
delete this._reviewerUsers;
}

if (this._reviewerUsers) {
Logger.appendLine('Using in-memory cached reviewer users.', this.id);
return this._reviewerUsers;
}

const globalStateReviewerUsers = await this.getCachedFromGlobalState<IAccount>('reviewerUsers');

if (!this._fetchReviewerUsersPromise) {
const cache: { [key: string]: IAccount[] } = {};
const allReviewerUsers: IAccount[] = [];
this._fetchReviewerUsersPromise = new Promise(resolve => {
const promises = this._githubRepositories.map(async githubRepository => {
const data = await githubRepository.getReviewerUsers();
cache[githubRepository.remote.remoteName] = data.sort(loginComparator);
allReviewerUsers.push(...data);
return;
});

Promise.all(promises).then(() => {
this._reviewerUsers = cache;
this._fetchReviewerUsersPromise = undefined;
this.saveInGlobalState('reviewerUsers', cache);
resolve(cache);
});
});
return globalStateReviewerUsers ?? this._fetchReviewerUsersPromise;
}

return this._fetchReviewerUsersPromise;
}

async getTeamReviewers(refreshKind: TeamReviewerRefreshKind): Promise<{ [key: string]: ITeam[] }> {
if (refreshKind === TeamReviewerRefreshKind.Force) {
delete this._teamReviewers;
Expand Down
Loading