Skip to content

Commit e4fa303

Browse files
authored
fix multiDiff context buttons (#8045)
1 parent 6db883c commit e4fa303

2 files changed

Lines changed: 19 additions & 9 deletions

File tree

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3550,12 +3550,10 @@
35503550
],
35513551
"chat/multiDiff/context": [
35523552
{
3553-
"command": "pr.checkoutFromDescription",
3554-
"when": "resourceScheme == copilot-swe-agent || resourceScheme == 'copilot-cloud-agent'"
3553+
"command": "pr.checkoutFromDescription"
35553554
},
35563555
{
3557-
"command": "pr.applyChangesFromDescription",
3558-
"when": "resourceScheme == copilot-swe-agent || resourceScheme == 'copilot-cloud-agent'"
3556+
"command": "pr.applyChangesFromDescription"
35593557
}
35603558
]
35613559
},

src/commands.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -624,16 +624,28 @@ export function registerCommands(
624624
return !!contextAsPath.path;
625625
}
626626

627+
function prNumberFromUriPath(path: string): number | undefined {
628+
const trimPath = path.startsWith('/') ? path.substring(1) : path;
629+
if (!Number.isNaN(Number(trimPath))) {
630+
return Number(trimPath);
631+
}
632+
// This is a base64 encoded PR number like: /MTIz
633+
const decoded = Number(Buffer.from(trimPath, 'base64').toString('utf8'));
634+
if (!Number.isNaN(decoded)) {
635+
return decoded;
636+
}
637+
}
638+
627639
context.subscriptions.push(vscode.commands.registerCommand('pr.checkoutFromDescription', async (ctx: OverviewContext | { path: string } | undefined) => {
628640
if (!ctx) {
629641
return vscode.window.showErrorMessage(vscode.l10n.t('No pull request context provided for checkout.'));
630642
}
631643

632644
if (contextHasPath(ctx)) {
633645
const { path } = ctx;
634-
const prNumber = Number(Buffer.from(path.substring(1), 'base64').toString('utf8'));
635-
if (Number.isNaN(prNumber)) {
636-
return vscode.window.showErrorMessage(vscode.l10n.t('Unable to parse pull request number.'));
646+
const prNumber = prNumberFromUriPath(path);
647+
if (!prNumber) {
648+
return vscode.window.showErrorMessage(vscode.l10n.t('No pull request number found in context path.'));
637649
}
638650
const folderManager = reposManager.folderManagers[0];
639651
const pullRequest = await folderManager.fetchById(folderManager.gitHubRepositories[0], Number(prNumber));
@@ -659,8 +671,8 @@ export function registerCommands(
659671

660672
if (contextHasPath(ctx)) {
661673
const { path } = ctx;
662-
const prNumber = Number(Buffer.from(path.substring(1), 'base64').toString('utf8'));
663-
if (Number.isNaN(prNumber)) {
674+
const prNumber = prNumberFromUriPath(path);
675+
if (!prNumber) {
664676
return vscode.window.showErrorMessage(vscode.l10n.t('Unable to parse pull request number.'));
665677
}
666678

0 commit comments

Comments
 (0)