Skip to content

Commit eb8ad9a

Browse files
Copilotalexr00
andcommitted
Add Codespaces checkout command and utility function
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent 85b1129 commit eb8ad9a

4 files changed

Lines changed: 33 additions & 1 deletion

File tree

package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,6 +1417,11 @@
14171417
"title": "%command.pr.checkoutOnVscodeDevFromDescription.title%",
14181418
"category": "%command.pull.request.category%"
14191419
},
1420+
{
1421+
"command": "pr.checkoutOnCodespacesFromDescription",
1422+
"title": "%command.pr.checkoutOnCodespacesFromDescription.title%",
1423+
"category": "%command.pull.request.category%"
1424+
},
14201425
{
14211426
"command": "pr.openSessionLogFromDescription",
14221427
"title": "%command.pr.openSessionLogFromDescription.title%",
@@ -3602,6 +3607,11 @@
36023607
"group": "checkout@1",
36033608
"when": "webviewId == PullRequestOverview && github:checkoutMenu"
36043609
},
3610+
{
3611+
"command": "pr.checkoutOnCodespacesFromDescription",
3612+
"group": "checkout@2",
3613+
"when": "webviewId == PullRequestOverview && github:checkoutMenu"
3614+
},
36053615
{
36063616
"command": "pr.openSessionLogFromDescription",
36073617
"when": "webviewId == PullRequestOverview && github:codingAgentMenu"

package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@
288288
"command.pr.checkoutFromDescription.title": "Checkout",
289289
"command.pr.applyChangesFromDescription.title": "Apply Changes",
290290
"command.pr.checkoutOnVscodeDevFromDescription.title": "Checkout on vscode.dev",
291+
"command.pr.checkoutOnCodespacesFromDescription.title": "Checkout on Codespaces",
291292
"command.pr.openSessionLogFromDescription.title": "View Session",
292293
"command.issue.openDescription.title": "View Issue Description",
293294
"command.issue.copyGithubDevLink.title": "Copy github.dev Link",

src/commands.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import { PullRequestModel } from './github/pullRequestModel';
3131
import { PullRequestOverviewPanel } from './github/pullRequestOverview';
3232
import { chooseItem } from './github/quickPicks';
3333
import { RepositoriesManager } from './github/repositoriesManager';
34-
import { getIssuesUrl, getPullsUrl, isInCodespaces, ISSUE_OR_URL_EXPRESSION, parseIssueExpressionOutput, vscodeDevPrLink } from './github/utils';
34+
import { codespacesPrLink, getIssuesUrl, getPullsUrl, isInCodespaces, ISSUE_OR_URL_EXPRESSION, parseIssueExpressionOutput, vscodeDevPrLink } from './github/utils';
3535
import { OverviewContext } from './github/views';
3636
import { isNotificationTreeItem, NotificationTreeItem } from './notifications/notificationItem';
3737
import { NotificationsManager } from './notifications/notificationsManager';
@@ -725,6 +725,20 @@ export function registerCommands(
725725
return vscode.env.openExternal(vscode.Uri.parse(vscodeDevPrLink(resolved.pr)));
726726
}));
727727

728+
context.subscriptions.push(vscode.commands.registerCommand('pr.checkoutOnCodespacesFromDescription', async (context: OverviewContext | undefined) => {
729+
if (!context) {
730+
return vscode.window.showErrorMessage(vscode.l10n.t('No pull request context provided for checkout.'));
731+
}
732+
const resolved = await resolvePr(context);
733+
if (!resolved) {
734+
return vscode.window.showErrorMessage(vscode.l10n.t('Unable to resolve pull request for checkout.'));
735+
}
736+
if (!resolved.pr.head) {
737+
return vscode.window.showErrorMessage(vscode.l10n.t('Unable to checkout pull request: missing head branch information.'));
738+
}
739+
return vscode.env.openExternal(vscode.Uri.parse(codespacesPrLink(resolved.pr)));
740+
}));
741+
728742
context.subscriptions.push(vscode.commands.registerCommand('pr.openSessionLogFromDescription', async (context: SessionLinkInfo | undefined) => {
729743
if (!context) {
730744
return vscode.window.showErrorMessage(vscode.l10n.t('No pull request context provided for checkout.'));

src/github/utils.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1787,6 +1787,13 @@ export function vscodeDevPrLink(pullRequest: IssueModel) {
17871787
return `https://${vscode.env.appName.toLowerCase().includes('insider') ? 'insiders.' : ''}vscode.dev/github${itemUri.path}`;
17881788
}
17891789

1790+
export function codespacesPrLink(pullRequest: { head: GitHubRef }): string {
1791+
// GitHub Codespaces URL format: https://github.com/codespaces/new?ref={branch}&repo={owner/repo}
1792+
const repoFullName = `${pullRequest.head.owner}/${pullRequest.head.name}`;
1793+
const branch = pullRequest.head.ref;
1794+
return `https://github.com/codespaces/new?ref=${encodeURIComponent(branch)}&repo=${encodeURIComponent(repoFullName)}`;
1795+
}
1796+
17901797
export function makeLabel(label: ILabel): string {
17911798
const isDarkTheme = vscode.window.activeColorTheme.kind === vscode.ColorThemeKind.Dark;
17921799
const labelColor = gitHubLabelColor(label.color, isDarkTheme, true);

0 commit comments

Comments
 (0)