Skip to content

Commit 4adb2ca

Browse files
authored
Merge branch 'main' into dev/mjbvz/resource-chat-sessions
2 parents 7e83233 + d3bec0d commit 4adb2ca

4 files changed

Lines changed: 139 additions & 48 deletions

File tree

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3529,12 +3529,12 @@
35293529
"chat/chatSessions": [
35303530
{
35313531
"command": "pr.openChanges",
3532-
"when": "chatSessionType == copilot-swe-agent",
3532+
"when": "chatSessionType == copilot-swe-agent || chatSessionType == copilot-cloud-agent",
35333533
"group": "inline"
35343534
},
35353535
{
35363536
"command": "pr.checkoutChatSessionPullRequest",
3537-
"when": "chatSessionType == copilot-swe-agent",
3537+
"when": "chatSessionType == copilot-swe-agent || chatSessionType == copilot-cloud-agent",
35383538
"group": "context"
35393539
},
35403540
{
@@ -3544,18 +3544,18 @@
35443544
},
35453545
{
35463546
"command": "pr.cancelCodingAgent",
3547-
"when": "chatSessionType == copilot-swe-agent",
3547+
"when": "chatSessionType == copilot-swe-agent || chatSessionType == copilot-cloud-agent",
35483548
"group": "context"
35493549
}
35503550
],
35513551
"chat/multiDiff/context": [
35523552
{
35533553
"command": "pr.checkoutFromDescription",
3554-
"when": "chatSessionType == copilot-swe-agent"
3554+
"when": "chatSessionType == copilot-swe-agent || chatSessionType == 'copilot-cloud-agent'"
35553555
},
35563556
{
35573557
"command": "pr.applyChangesFromDescription",
3558-
"when": "chatSessionType == copilot-swe-agent"
3558+
"when": "chatSessionType == copilot-swe-agent || chatSessionType == 'copilot-cloud-agent'"
35593559
}
35603560
]
35613561
},

src/commands.ts

Lines changed: 79 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { asTempStorageURI, fromPRUri, fromReviewUri, Schemes, toPRUri } from './
1919
import { formatError } from './common/utils';
2020
import { EXTENSION_ID } from './constants';
2121
import { ICopilotRemoteAgentCommandArgs } from './github/common';
22-
import { ChatSessionWithPR } from './github/copilotApi';
22+
import { ChatSessionWithPR, CrossChatSessionWithPR } from './github/copilotApi';
2323
import { CopilotRemoteAgentManager } from './github/copilotRemoteAgent';
2424
import { FolderRepositoryManager } from './github/folderRepositoryManager';
2525
import { GitHubRepository } from './github/githubRepository';
@@ -198,6 +198,11 @@ function isChatSessionWithPR(value: any): value is ChatSessionWithPR {
198198
return !!asChatSessionWithPR.pullRequest;
199199
}
200200

201+
function isCrossChatSessionWithPR(value: any): value is CrossChatSessionWithPR {
202+
const asCrossChatSessionWithPR = value as Partial<CrossChatSessionWithPR>;
203+
return !!asCrossChatSessionWithPR.pullRequestDetails;
204+
}
205+
201206
export function registerCommands(
202207
context: vscode.ExtensionContext,
203208
reposManager: RepositoriesManager,
@@ -566,7 +571,7 @@ export function registerCommands(
566571
return { folderManager, pr };
567572
};
568573

569-
const applyPullRequestChanges = async (folderManager: FolderRepositoryManager, pullRequest: PullRequestModel): Promise<void> => {
574+
const applyPullRequestChanges = async (task: vscode.Progress<{ message?: string; increment?: number; }>, folderManager: FolderRepositoryManager, pullRequest: PullRequestModel): Promise<void> => {
570575
let patch: string | undefined;
571576
try {
572577
patch = await pullRequest.getPatch();
@@ -584,22 +589,13 @@ export function registerCommands(
584589
const encoder = new TextEncoder();
585590
const tempUri = vscode.Uri.file(tempFilePath);
586591

587-
await vscode.window.withProgress(
588-
{
589-
location: vscode.ProgressLocation.Notification,
590-
title: vscode.l10n.t('Applying changes from pull request #{0}', pullRequest.number.toString()),
591-
cancellable: false
592-
},
593-
async (task) => {
594-
await vscode.workspace.fs.writeFile(tempUri, encoder.encode(patch));
595-
try {
596-
await folderManager.repository.apply(tempFilePath, false);
597-
task.report({ message: vscode.l10n.t('Successfully applied changes from pull request #{0}', pullRequest.number.toString()), increment: 100 });
598-
} finally {
599-
await vscode.workspace.fs.delete(tempUri);
600-
}
601-
}
602-
);
592+
await vscode.workspace.fs.writeFile(tempUri, encoder.encode(patch));
593+
try {
594+
await folderManager.repository.apply(tempFilePath, false);
595+
task.report({ message: vscode.l10n.t('Successfully applied changes from pull request #{0}', pullRequest.number.toString()), increment: 100 });
596+
} finally {
597+
await vscode.workspace.fs.delete(tempUri);
598+
}
603599

604600
} catch (error) {
605601
const errorMessage = formatError(error);
@@ -667,21 +663,44 @@ export function registerCommands(
667663
if (Number.isNaN(prNumber)) {
668664
return vscode.window.showErrorMessage(vscode.l10n.t('Unable to parse pull request number.'));
669665
}
670-
const folderManager = reposManager.folderManagers[0];
671-
const pullRequest = await folderManager.fetchById(folderManager.gitHubRepositories[0], Number(prNumber));
672-
if (!pullRequest) {
673-
return vscode.window.showErrorMessage(vscode.l10n.t('Unable to find pull request #{0}', prNumber.toString()));
674-
}
675666

676-
return applyPullRequestChanges(folderManager, pullRequest);
677-
}
667+
await vscode.window.withProgress(
668+
{
669+
location: vscode.ProgressLocation.Notification,
670+
title: vscode.l10n.t('Applying changes from pull request #{0}', prNumber.toString()),
671+
cancellable: false
672+
},
673+
async (task) => {
674+
task.report({ increment: 30 });
678675

679-
const resolved = await resolvePr(ctx);
680-
if (!resolved) {
681-
return vscode.window.showErrorMessage(vscode.l10n.t('Unable to resolve pull request for applying changes.'));
676+
const folderManager = reposManager.folderManagers[0];
677+
const pullRequest = await folderManager.fetchById(folderManager.gitHubRepositories[0], Number(prNumber));
678+
if (!pullRequest) {
679+
return vscode.window.showErrorMessage(vscode.l10n.t('Unable to find pull request #{0}', prNumber.toString()));
680+
}
681+
682+
return applyPullRequestChanges(task, folderManager, pullRequest);
683+
});
684+
685+
return;
682686
}
683-
return applyPullRequestChanges(resolved.folderManager, resolved.pr);
684687

688+
await vscode.window.withProgress(
689+
{
690+
location: vscode.ProgressLocation.Notification,
691+
title: vscode.l10n.t('Applying changes from pull request'),
692+
cancellable: false
693+
},
694+
async (task) => {
695+
task.report({ increment: 30 });
696+
697+
const resolved = await resolvePr(ctx);
698+
if (!resolved) {
699+
return vscode.window.showErrorMessage(vscode.l10n.t('Unable to resolve pull request for applying changes.'));
700+
}
701+
return applyPullRequestChanges(task, resolved.folderManager, resolved.pr);
702+
}
703+
);
685704
}));
686705

687706
context.subscriptions.push(
@@ -700,6 +719,14 @@ export function registerCommands(
700719
pullRequestModel = pr;
701720
} else if (isChatSessionWithPR(pr)) {
702721
pullRequestModel = pr.pullRequest;
722+
} else if (isCrossChatSessionWithPR(pr)) {
723+
const resolved = await resolvePr({
724+
owner: pr.pullRequestDetails.repository.owner.login,
725+
repo: pr.pullRequestDetails.repository.name,
726+
number: pr.pullRequestDetails.number,
727+
preventDefaultContextMenuItems: true,
728+
});
729+
pullRequestModel = resolved?.pr;
703730
} else {
704731
const resolved = await resolvePr(pr as OverviewContext);
705732
pullRequestModel = resolved?.pr;
@@ -963,8 +990,14 @@ export function registerCommands(
963990
await openDescription(telemetry, issueModel, descriptionNode, folderManager, revealDescription, !(argument instanceof RepositoryChangesNode));
964991
}
965992

966-
async function checkoutChatSessionPullRequest(argument: ChatSessionWithPR) {
967-
const pr = argument.pullRequest;
993+
async function checkoutChatSessionPullRequest(argument: ChatSessionWithPR | CrossChatSessionWithPR) {
994+
const pr = isChatSessionWithPR(argument) ? argument.pullRequest : await resolvePr({
995+
owner: argument.pullRequestDetails.repository.owner.login,
996+
repo: argument.pullRequestDetails.repository.name,
997+
number: argument.pullRequestDetails.number,
998+
preventDefaultContextMenuItems: true,
999+
}).then(resolved => resolved?.pr);
1000+
9681001
if (!pr) {
9691002
Logger.warn(`No pull request found in chat session`, logId);
9701003
return;
@@ -979,18 +1012,28 @@ export function registerCommands(
9791012
return switchToPr(folderManager, pr, folderManager.repository, false);
9801013
}
9811014

982-
async function closeChatSessionPullRequest(argument: ChatSessionWithPR) {
983-
const pr = argument.pullRequest;
1015+
async function closeChatSessionPullRequest(argument: ChatSessionWithPR | CrossChatSessionWithPR) {
1016+
const pr = isChatSessionWithPR(argument) ? argument.pullRequest : await resolvePr({
1017+
owner: argument.pullRequestDetails.repository.owner.login,
1018+
repo: argument.pullRequestDetails.repository.name,
1019+
number: argument.pullRequestDetails.number,
1020+
preventDefaultContextMenuItems: true,
1021+
}).then(resolved => resolved?.pr);
9841022
if (!pr) {
9851023
Logger.warn(`No pull request found in chat session`, logId);
9861024
return;
9871025
}
988-
pr.close();
1026+
await pr.close();
9891027
copilotRemoteAgentManager.refreshChatSessions();
9901028
}
9911029

992-
async function cancelCodingAgent(argument: ChatSessionWithPR) {
993-
const pr = argument.pullRequest;
1030+
async function cancelCodingAgent(argument: ChatSessionWithPR | CrossChatSessionWithPR) {
1031+
const pr = isChatSessionWithPR(argument) ? argument.pullRequest : await resolvePr({
1032+
owner: argument.pullRequestDetails.repository.owner.login,
1033+
repo: argument.pullRequestDetails.repository.name,
1034+
number: argument.pullRequestDetails.number,
1035+
preventDefaultContextMenuItems: true,
1036+
}).then(resolved => resolved?.pr);
9941037
if (!pr) {
9951038
Logger.warn(`No pull request found in chat session`, logId);
9961039
return;

src/github/copilotApi.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,24 @@ export interface ChatSessionWithPR extends vscode.ChatSessionItem {
5252
pullRequest: PullRequestModel;
5353
}
5454

55+
56+
/**
57+
* This is temporary for the migration of CCA only.
58+
* Once fully migrated we can rename to ChatSessionWithPR and remove the old one.
59+
**/
60+
export interface CrossChatSessionWithPR extends vscode.ChatSessionItem {
61+
pullRequestDetails: {
62+
id: string;
63+
number: number;
64+
repository: {
65+
owner: {
66+
login: string;
67+
};
68+
name: string;
69+
};
70+
};
71+
}
72+
5573
export class CopilotApi {
5674
protected static readonly ID = 'copilotApi';
5775

yarn.lock

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5899,12 +5899,17 @@ playwright-core@1.54.1:
58995899
resolved "https://registry.yarnpkg.com/playwright-core/-/playwright-core-1.54.1.tgz#d32edcce048c9d83ceac31e294a7b60ef586960b"
59005900
integrity sha512-Nbjs2zjj0htNhzgiy5wu+3w09YetDx5pkrpI/kZotDlDUaYk0HVA5xrBVPdow4SAUIlhgKcJeJg4GRKW6xHusA==
59015901

5902+
playwright-core@1.56.1:
5903+
version "1.56.1"
5904+
resolved "https://registry.yarnpkg.com/playwright-core/-/playwright-core-1.56.1.tgz#24a66481e5cd33a045632230aa2c4f0cb6b1db3d"
5905+
integrity sha512-hutraynyn31F+Bifme+Ps9Vq59hKuUCz7H1kDOcBs+2oGguKkWTU50bBWrtz34OUWmIwpBTWDxaRPXrIXkgvmQ==
5906+
59025907
playwright@^1.53.1:
5903-
version "1.54.1"
5904-
resolved "https://registry.yarnpkg.com/playwright/-/playwright-1.54.1.tgz#128d66a8d5182b5330e6440be3a72ca313362788"
5905-
integrity sha512-peWpSwIBmSLi6aW2auvrUtf2DqY16YYcCMO8rTVx486jKmDTJg7UAhyrraP98GB8BoPURZP8+nxO7TSd4cPr5g==
5908+
version "1.56.1"
5909+
resolved "https://registry.yarnpkg.com/playwright/-/playwright-1.56.1.tgz#62e3b99ddebed0d475e5936a152c88e68be55fbf"
5910+
integrity sha512-aFi5B0WovBHTEvpM3DzXTUaeN6eN0qWnTkKx4NQaH4Wvcmc153PdaY2UBdSYKaGYw+UyWXSVyxDUg5DoPEttjw==
59065911
dependencies:
5907-
playwright-core "1.54.1"
5912+
playwright-core "1.56.1"
59085913
optionalDependencies:
59095914
fsevents "2.3.2"
59105915

@@ -6776,7 +6781,16 @@ streamx@^2.15.0, streamx@^2.21.0:
67766781
optionalDependencies:
67776782
bare-events "^2.2.0"
67786783

6779-
"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
6784+
"string-width-cjs@npm:string-width@^4.2.0":
6785+
version "4.2.3"
6786+
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
6787+
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
6788+
dependencies:
6789+
emoji-regex "^8.0.0"
6790+
is-fullwidth-code-point "^3.0.0"
6791+
strip-ansi "^6.0.1"
6792+
6793+
string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
67806794
version "4.2.3"
67816795
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
67826796
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
@@ -6866,7 +6880,7 @@ stringify-entities@^4.0.0:
68666880
character-entities-html4 "^2.0.0"
68676881
character-entities-legacy "^3.0.0"
68686882

6869-
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
6883+
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
68706884
version "6.0.1"
68716885
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
68726886
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
@@ -6880,6 +6894,13 @@ strip-ansi@^4.0.0:
68806894
dependencies:
68816895
ansi-regex "^3.0.0"
68826896

6897+
strip-ansi@^6.0.0, strip-ansi@^6.0.1:
6898+
version "6.0.1"
6899+
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
6900+
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
6901+
dependencies:
6902+
ansi-regex "^5.0.1"
6903+
68836904
strip-ansi@^7.0.1:
68846905
version "7.1.2"
68856906
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-7.1.2.tgz#132875abde678c7ea8d691533f2e7e22bb744dba"
@@ -7890,7 +7911,16 @@ workerpool@^9.2.0:
78907911
resolved "https://registry.yarnpkg.com/workerpool/-/workerpool-9.3.4.tgz#f6c92395b2141afd78e2a889e80cb338fe9fca41"
78917912
integrity sha512-TmPRQYYSAnnDiEB0P/Ytip7bFGvqnSU6I2BcuSw7Hx+JSg/DsUi5ebYfc8GYaSdpuvOcEs6dXxPurOYpe9QFwg==
78927913

7893-
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
7914+
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
7915+
version "7.0.0"
7916+
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
7917+
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
7918+
dependencies:
7919+
ansi-styles "^4.0.0"
7920+
string-width "^4.1.0"
7921+
strip-ansi "^6.0.0"
7922+
7923+
wrap-ansi@^7.0.0:
78947924
version "7.0.0"
78957925
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
78967926
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==

0 commit comments

Comments
 (0)