Skip to content

Comments

Add Codespaces checkout option to PR dropdown and tree context menu#8298

Merged
alexr00 merged 10 commits intomainfrom
copilot/add-checkout-option-codespaces
Dec 12, 2025
Merged

Add Codespaces checkout option to PR dropdown and tree context menu#8298
alexr00 merged 10 commits intomainfrom
copilot/add-checkout-option-codespaces

Conversation

Copy link
Contributor

Copilot AI commented Dec 11, 2025

Implementation Complete ✅

Features Added

1. PR Overview Dropdown

  • ✅ "Checkout in Codespaces" option in PR header dropdown menu
  • Command: pr.checkoutOnCodespacesFromDescription

2. PR Tree Context Menu

  • ✅ "Checkout Pull Request in Codespaces" in right-click context menu
  • Command: pr.pickOnCodespaces

Code Quality Improvements

Refactored duplicate code

  • Extracted common logic from pr.pickOnVscodeDev and pr.pickOnCodespaces into helper function pickPullRequest
  • Added async keyword to command callbacks for clarity
  • Reduces code duplication while maintaining same functionality
  • Helper function accepts a link generator function and optional head branch requirement flag

Technical Details

Helper Function

const pickPullRequest = async (
  pr: PRNode | RepositoryChangesNode | PullRequestModel, 
  linkGenerator: (pr: PullRequestModel) => string, 
  requiresHead: boolean = false
) => {
  // Validates PR parameter
  // Extracts PullRequestModel from different input types
  // Optionally validates head branch exists
  // Opens external link using provided link generator
}

Usage

  • pr.pickOnVscodeDevasync (pr) => pickPullRequest(pr, vscodeDevPrLink)
  • pr.pickOnCodespacesasync (pr) => pickPullRequest(pr, codespacesPrLink, true)

Quality Assurance

  • ✅ Code compiles successfully
  • ✅ Linter passes (no issues)
  • ✅ Hygiene check passes
  • ✅ Code review passes
  • ✅ CodeQL security scan passes (0 vulnerabilities)
  • ✅ Reduced code duplication per reviewer feedback
  • ✅ Maintains same functionality

Fixes #7424

Original prompt

This section details on the original issue you should resolve

<issue_title>Add option to checkout PR on Codespaces</issue_title>
<issue_description>Testing #7424

It'd be nice if I had an option to checkout the PR on Codespaces. I was working on a local repo that wasn't set up on my machine, and I wish I had the option from the PR header to checkout on Codespaces so that the repo would be set up for me to test my changes

Image</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits December 11, 2025 09:35
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
Copilot AI changed the title [WIP] Add option to checkout PR on Codespaces Add Codespaces checkout option to PR dropdown Dec 11, 2025
Copilot AI requested a review from alexr00 December 11, 2025 09:54
Copy link
Member

@alexr00 alexr00 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Great, also add it in the right click context menu of PR items in the pull requests tree

Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 12, 2025

@copilot Great, also add it in the right click context menu of PR items in the pull requests tree

Done in commit a486961. The "Checkout Pull Request in Codespaces" option now appears in the right-click context menu for PR items in the pull requests tree view, positioned right after the "Checkout Pull Request on vscode.dev" option. It opens the PR branch in a new GitHub Codespace using the URL format: https://github.com/codespaces/new/{owner/repo}/tree/{branch}

Copilot AI changed the title Add Codespaces checkout option to PR dropdown Add Codespaces checkout option to PR dropdown and tree context menu Dec 12, 2025
Copilot AI requested a review from alexr00 December 12, 2025 11:52
src/commands.ts Outdated
Comment on lines 719 to 738
if (pr === undefined) {
// This is unexpected, but has happened a few times.
Logger.error('Unexpectedly received undefined when picking a PR.', logId);
return vscode.window.showErrorMessage(vscode.l10n.t('No pull request was selected to checkout, please try again.'));
}

let pullRequestModel: PullRequestModel;

if (pr instanceof PRNode || pr instanceof RepositoryChangesNode) {
pullRequestModel = pr.pullRequestModel;
} else {
pullRequestModel = pr;
}

if (!pullRequestModel.head) {
return vscode.window.showErrorMessage(vscode.l10n.t('Unable to checkout pull request: missing head branch information.'));
}

return vscode.env.openExternal(vscode.Uri.parse(codespacesPrLink(pullRequestModel)));
}),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Reduce duplicate code between here and pr.pickOnVscodeDev.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in commits 32386b2 and 65f0ca4. Extracted common validation and PR model extraction logic into a pickPullRequest helper function. Both pr.pickOnVscodeDev and pr.pickOnCodespaces now use this shared function with their respective link generators.

Copilot AI and others added 2 commits December 12, 2025 13:27
…odespaces

Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
Copilot AI requested a review from alexr00 December 12, 2025 13:32
@alexr00 alexr00 marked this pull request as ready for review December 12, 2025 13:49
@alexr00 alexr00 enabled auto-merge (squash) December 12, 2025 13:49
@vs-code-engineering vs-code-engineering bot added this to the December / January 2026 milestone Dec 12, 2025
@alexr00 alexr00 merged commit b0bf1a5 into main Dec 12, 2025
6 checks passed
@alexr00 alexr00 deleted the copilot/add-checkout-option-codespaces branch December 12, 2025 13:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add option to checkout PR on Codespaces Test new PR header

3 participants