Skip to content

Commit a486961

Browse files
Copilotalexr00
andcommitted
Add Codespaces checkout to PR tree context menu
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent a8fb8d8 commit a486961

3 files changed

Lines changed: 40 additions & 0 deletions

File tree

package.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,12 @@
971971
"category": "%command.pull.request.category%",
972972
"icon": "$(globe)"
973973
},
974+
{
975+
"command": "pr.pickOnCodespaces",
976+
"title": "%command.pr.pickOnCodespaces.title%",
977+
"category": "%command.pull.request.category%",
978+
"icon": "$(cloud)"
979+
},
974980
{
975981
"command": "pr.exit",
976982
"title": "%command.pr.exit.title%",
@@ -2055,6 +2061,10 @@
20552061
"command": "pr.pickOnVscodeDev",
20562062
"when": "false"
20572063
},
2064+
{
2065+
"command": "pr.pickOnCodespaces",
2066+
"when": "false"
2067+
},
20582068
{
20592069
"command": "pr.exit",
20602070
"when": "github:inReviewMode"
@@ -2854,6 +2864,11 @@
28542864
"when": "view == pr:github && viewItem =~ /pullrequest(:local)?:nonactive/ && (!isWeb || remoteName != codespaces && virtualWorkspace != vscode-vfs)",
28552865
"group": "1_pullrequest@2"
28562866
},
2867+
{
2868+
"command": "pr.pickOnCodespaces",
2869+
"when": "view == pr:github && viewItem =~ /pullrequest(:local)?:nonactive/ && (!isWeb || remoteName != codespaces && virtualWorkspace != vscode-vfs)",
2870+
"group": "1_pullrequest@3"
2871+
},
28572872
{
28582873
"command": "pr.openChanges",
28592874
"when": "view =~ /(pr|prStatus):github/ && viewItem =~ /(pullrequest|description)/ && config.multiDiffEditor.experimental.enabled",

package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@
189189
"command.pr.pick.title": "Checkout Pull Request",
190190
"command.pr.openChanges.title": "Open Changes",
191191
"command.pr.pickOnVscodeDev.title": "Checkout Pull Request on vscode.dev",
192+
"command.pr.pickOnCodespaces.title": "Checkout Pull Request in Codespaces",
192193
"command.pr.exit.title": "Checkout Default Branch",
193194
"command.pr.dismissNotification.title": "Dismiss Notification",
194195
"command.pr.markAllCopilotNotificationsAsRead.title": "Dismiss All Copilot Notifications",

src/commands.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,30 @@ export function registerCommands(
714714
}),
715715
);
716716

717+
context.subscriptions.push(
718+
vscode.commands.registerCommand('pr.pickOnCodespaces', async (pr: PRNode | RepositoryChangesNode | PullRequestModel) => {
719+
if (pr === undefined) {
720+
// This is unexpected, but has happened a few times.
721+
Logger.error('Unexpectedly received undefined when picking a PR.', logId);
722+
return vscode.window.showErrorMessage(vscode.l10n.t('No pull request was selected to checkout, please try again.'));
723+
}
724+
725+
let pullRequestModel: PullRequestModel;
726+
727+
if (pr instanceof PRNode || pr instanceof RepositoryChangesNode) {
728+
pullRequestModel = pr.pullRequestModel;
729+
} else {
730+
pullRequestModel = pr;
731+
}
732+
733+
if (!pullRequestModel.head) {
734+
return vscode.window.showErrorMessage(vscode.l10n.t('Unable to checkout pull request: missing head branch information.'));
735+
}
736+
737+
return vscode.env.openExternal(vscode.Uri.parse(codespacesPrLink(pullRequestModel)));
738+
}),
739+
);
740+
717741
context.subscriptions.push(vscode.commands.registerCommand('pr.checkoutOnVscodeDevFromDescription', async (context: OverviewContext | undefined) => {
718742
if (!context) {
719743
return vscode.window.showErrorMessage(vscode.l10n.t('No pull request context provided for checkout.'));

0 commit comments

Comments
 (0)