Skip to content

Commit 164296e

Browse files
authored
Fixed issues with remote agent for workspace having multiple repositories (#7968)
1 parent dc1060e commit 164296e

3 files changed

Lines changed: 27 additions & 16 deletions

File tree

src/commands.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ export function registerCommands(
218218
if (activePullRequests.length >= 1) {
219219
const result = await chooseItem<PullRequestModel>(
220220
activePullRequests,
221-
itemValue => itemValue.html_url,
221+
itemValue => ({ label: itemValue.html_url }),
222222
);
223223
if (result) {
224224
openPullRequestOnGitHub(result, telemetry);
@@ -255,7 +255,7 @@ export function registerCommands(
255255
? (
256256
await chooseItem(
257257
activePullRequestsWithFolderManager,
258-
itemValue => itemValue.activePr.html_url,
258+
itemValue => ({ label: itemValue.activePr.html_url }),
259259
)
260260
)
261261
: activePullRequestsWithFolderManager[0];
@@ -434,7 +434,7 @@ export function registerCommands(
434434
}
435435
return chooseItem<ReviewManager>(
436436
reviewsManager.reviewManagers,
437-
itemValue => pathLib.basename(itemValue.repository.rootUri.fsPath),
437+
itemValue => ({ label: pathLib.basename(itemValue.repository.rootUri.fsPath) }),
438438
{ placeHolder: vscode.l10n.t('Choose a repository to create a pull request in'), ignoreFocusOut: true },
439439
);
440440
}
@@ -786,7 +786,7 @@ export function registerCommands(
786786
pullRequestModel = await chooseItem<PullRequestModel>(reposManager.folderManagers
787787
.map(folderManager => folderManager.activePullRequest!)
788788
.filter(activePR => !!activePR),
789-
itemValue => `${itemValue.number}: ${itemValue.title}`,
789+
itemValue => ({ label: `${itemValue.number}: ${itemValue.title}` }),
790790
{ placeHolder: vscode.l10n.t('Choose the pull request to exit') });
791791
} else {
792792
pullRequestModel = pr;
@@ -922,7 +922,7 @@ export function registerCommands(
922922
if (activePullRequests.length >= 1) {
923923
issueModel = await chooseItem<PullRequestModel>(
924924
activePullRequests,
925-
itemValue => itemValue.title,
925+
itemValue => ({ label: itemValue.title }),
926926
);
927927
}
928928
} else {
@@ -1600,7 +1600,7 @@ ${contents}
16001600
.filter(activePR => !!activePR);
16011601
pr = await chooseItem<PullRequestModel>(
16021602
activePullRequests,
1603-
itemValue => `${itemValue.number}: ${itemValue.title}`,
1603+
itemValue => ({ label: `${itemValue.number}: ${itemValue.title}` }),
16041604
{ placeHolder: vscode.l10n.t('Pull request to create a link for') },
16051605
);
16061606
}
@@ -1656,7 +1656,7 @@ ${contents}
16561656
}
16571657
const githubRepo = await chooseItem<{ manager: FolderRepositoryManager, repo: GitHubRepository }>(
16581658
githubRepositories,
1659-
itemValue => `${itemValue.repo.remote.owner}/${itemValue.repo.remote.repositoryName}`,
1659+
itemValue => ({ label: `${itemValue.repo.remote.owner}/${itemValue.repo.remote.repositoryName}` }),
16601660
{ placeHolder: vscode.l10n.t('Which GitHub repository do you want to checkout the pull request from?') }
16611661
);
16621662
if (!githubRepo) {
@@ -1692,7 +1692,7 @@ ${contents}
16921692
});
16931693
return chooseItem<GitHubRepository>(
16941694
githubRepositories,
1695-
itemValue => `${itemValue.remote.owner}/${itemValue.remote.repositoryName}`,
1695+
itemValue => ({ label: `${itemValue.remote.owner}/${itemValue.remote.repositoryName}` }),
16961696
{ placeHolder: vscode.l10n.t('Which GitHub repository do you want to open?') }
16971697
);
16981698
}
@@ -1916,7 +1916,7 @@ ${contents}
19161916

19171917
const pr = await chooseItem<PullRequestModel>(
19181918
activePullRequests,
1919-
itemValue => `${itemValue.number}: ${itemValue.title}`,
1919+
itemValue => ({ label: `${itemValue.number}: ${itemValue.title}` }),
19201920
{ placeHolder: vscode.l10n.t('Pull request to create a link for') },
19211921
);
19221922
if (pr) {

src/github/copilotRemoteAgent.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ export class CopilotRemoteAgentManager extends Disposable {
426426
private chooseFolderManager(): Promise<FolderRepositoryManager | undefined> {
427427
return chooseItem<FolderRepositoryManager>(
428428
this.repositoriesManager.folderManagers,
429-
itemValue => pathLib.basename(itemValue.repository.rootUri.fsPath),
429+
itemValue => ({ label: pathLib.basename(itemValue.repository.rootUri.fsPath) }),
430430
);
431431
}
432432

@@ -461,7 +461,7 @@ export class CopilotRemoteAgentManager extends Disposable {
461461

462462
const result = await chooseItem<GitHubRemote>(
463463
ghRemotes,
464-
itemValue => `${itemValue.remoteName} (${itemValue.owner}/${itemValue.repositoryName})`,
464+
itemValue => ({ label: itemValue.remoteName, description: `(${itemValue.owner}/${itemValue.repositoryName})` }),
465465
{
466466
title: vscode.l10n.t('Coding agent will create pull requests against the selected remote.'),
467467
}
@@ -665,6 +665,8 @@ export class CopilotRemoteAgentManager extends Disposable {
665665
summary,
666666
undefined,
667667
autoPushAndCommit,
668+
undefined,
669+
fm
668670
);
669671

670672
if (result.state !== 'success') {
@@ -728,15 +730,15 @@ export class CopilotRemoteAgentManager extends Disposable {
728730
return vscode.l10n.t('🚀 Coding agent will continue work in [#{0}]({1}). Track progress [here]({2}).', number, link, webviewUri.toString());
729731
}
730732

731-
async invokeRemoteAgent(prompt: string, problemContext?: string, token?: vscode.CancellationToken, autoPushAndCommit = true, chatStream?: vscode.ChatResponseStream): Promise<RemoteAgentResult> {
733+
async invokeRemoteAgent(prompt: string, problemContext?: string, token?: vscode.CancellationToken, autoPushAndCommit = true, chatStream?: vscode.ChatResponseStream, fm?: FolderRepositoryManager): Promise<RemoteAgentResult> {
732734
const capiClient = await this.copilotApi;
733735
if (!capiClient) {
734736
return { error: vscode.l10n.t('Failed to initialize Copilot API. Please try again later.'), state: 'error' };
735737
}
736738

737739
await this.promptAndUpdatePreferredGitHubRemote(true);
738740

739-
const repoInfo = await this.repoInfo();
741+
const repoInfo = await this.repoInfo(fm);
740742
if (!repoInfo) {
741743
return { error: vscode.l10n.t('No repository information found. Please open a workspace with a GitHub repository.'), state: 'error' };
742744
}
@@ -1112,7 +1114,16 @@ export class CopilotRemoteAgentManager extends Disposable {
11121114

11131115
const uri = await toOpenPullRequestWebviewUri({ owner: pullRequest.remote.owner, repo: pullRequest.remote.repositoryName, pullRequestNumber: pullRequest.number });
11141116
const prLinkTitle = vscode.l10n.t('Open pull request in VS Code');
1115-
const description = new vscode.MarkdownString(`[#${pullRequest.number}](${uri.toString()} "${prLinkTitle}")`); // pullRequest.base.ref === defaultBranch ? `PR #${pullRequest.number}`: `PR #${pullRequest.number} → ${pullRequest.base.ref}`;
1117+
1118+
// If we have multiple repositories, include the repo name in the link text
1119+
// e.g., 'owner/repo #123' instead of just '#123'
1120+
let repoInfo = '';
1121+
if (this.repositoriesManager.folderManagers.length > 1) {
1122+
const owner = pullRequest.remote.owner;
1123+
const repo = pullRequest.remote.repositoryName;
1124+
repoInfo = `${owner}/${repo} `;
1125+
}
1126+
const description = new vscode.MarkdownString(`[${repoInfo}#${pullRequest.number}](${uri.toString()} "${prLinkTitle}")`); // pullRequest.base.ref === defaultBranch ? `PR #${pullRequest.number}`: `PR #${pullRequest.number} → ${pullRequest.base.ref}`;
11161127
return {
11171128
id: `${pullRequest.number}`,
11181129
label: pullRequest.title || `Session ${pullRequest.number}`,

src/github/quickPicks.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { formatError } from '../common/utils';
2020

2121
export async function chooseItem<T>(
2222
itemsToChooseFrom: T[],
23-
propertyGetter: (itemValue: T) => string,
23+
propertyGetter: (itemValue: T) => { label: string; description?: string; },
2424
options?: vscode.QuickPickOptions,
2525
): Promise<T | undefined> {
2626
if (itemsToChooseFrom.length === 0) {
@@ -34,7 +34,7 @@ export async function chooseItem<T>(
3434
}
3535
const items: Item[] = itemsToChooseFrom.map(currentItem => {
3636
return {
37-
label: propertyGetter(currentItem),
37+
...propertyGetter(currentItem),
3838
itemValue: currentItem,
3939
};
4040
});

0 commit comments

Comments
 (0)