Skip to content

Commit 8a5c9a1

Browse files
authored
Adding inline commands to the new migrated CCA (#8034)
1 parent e7dd890 commit 8a5c9a1

File tree

3 files changed

+58
-11
lines changed

3 files changed

+58
-11
lines changed

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3529,22 +3529,22 @@
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
{
35413541
"command": "pr.closeChatSessionPullRequest",
3542-
"when": "chatSessionType == copilot-swe-agent",
3542+
"when": "chatSessionType == copilot-swe-agent || chatSessionType == copilot-cloud-agent",
35433543
"group": "context"
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
],

src/commands.ts

Lines changed: 36 additions & 7 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,
@@ -700,6 +705,14 @@ export function registerCommands(
700705
pullRequestModel = pr;
701706
} else if (isChatSessionWithPR(pr)) {
702707
pullRequestModel = pr.pullRequest;
708+
} else if (isCrossChatSessionWithPR(pr)) {
709+
const resolved = await resolvePr({
710+
owner: pr.pullRequestDetails.repository.owner.login,
711+
repo: pr.pullRequestDetails.repository.name,
712+
number: pr.pullRequestDetails.number,
713+
preventDefaultContextMenuItems: true,
714+
});
715+
pullRequestModel = resolved?.pr;
703716
} else {
704717
const resolved = await resolvePr(pr as OverviewContext);
705718
pullRequestModel = resolved?.pr;
@@ -963,8 +976,14 @@ export function registerCommands(
963976
await openDescription(telemetry, issueModel, descriptionNode, folderManager, revealDescription, !(argument instanceof RepositoryChangesNode));
964977
}
965978

966-
async function checkoutChatSessionPullRequest(argument: ChatSessionWithPR) {
967-
const pr = argument.pullRequest;
979+
async function checkoutChatSessionPullRequest(argument: ChatSessionWithPR | CrossChatSessionWithPR) {
980+
const pr = isChatSessionWithPR(argument) ? argument.pullRequest : await resolvePr({
981+
owner: argument.pullRequestDetails.repository.owner.login,
982+
repo: argument.pullRequestDetails.repository.name,
983+
number: argument.pullRequestDetails.number,
984+
preventDefaultContextMenuItems: true,
985+
}).then(resolved => resolved?.pr);
986+
968987
if (!pr) {
969988
Logger.warn(`No pull request found in chat session`, logId);
970989
return;
@@ -979,8 +998,13 @@ export function registerCommands(
979998
return switchToPr(folderManager, pr, folderManager.repository, false);
980999
}
9811000

982-
async function closeChatSessionPullRequest(argument: ChatSessionWithPR) {
983-
const pr = argument.pullRequest;
1001+
async function closeChatSessionPullRequest(argument: ChatSessionWithPR | CrossChatSessionWithPR) {
1002+
const pr = isChatSessionWithPR(argument) ? argument.pullRequest : await resolvePr({
1003+
owner: argument.pullRequestDetails.repository.owner.login,
1004+
repo: argument.pullRequestDetails.repository.name,
1005+
number: argument.pullRequestDetails.number,
1006+
preventDefaultContextMenuItems: true,
1007+
}).then(resolved => resolved?.pr);
9841008
if (!pr) {
9851009
Logger.warn(`No pull request found in chat session`, logId);
9861010
return;
@@ -989,8 +1013,13 @@ export function registerCommands(
9891013
copilotRemoteAgentManager.refreshChatSessions();
9901014
}
9911015

992-
async function cancelCodingAgent(argument: ChatSessionWithPR) {
993-
const pr = argument.pullRequest;
1016+
async function cancelCodingAgent(argument: ChatSessionWithPR | CrossChatSessionWithPR) {
1017+
const pr = isChatSessionWithPR(argument) ? argument.pullRequest : await resolvePr({
1018+
owner: argument.pullRequestDetails.repository.owner.login,
1019+
repo: argument.pullRequestDetails.repository.name,
1020+
number: argument.pullRequestDetails.number,
1021+
preventDefaultContextMenuItems: true,
1022+
}).then(resolved => resolved?.pr);
9941023
if (!pr) {
9951024
Logger.warn(`No pull request found in chat session`, logId);
9961025
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

0 commit comments

Comments
 (0)