feat: add script to migrate PRs from vscode-copilot-chat to vscode#308236
feat: add script to migrate PRs from vscode-copilot-chat to vscode#308236joaomoreno merged 3 commits intomainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a standalone build-time utility script to help migrate pull requests from microsoft/vscode-copilot-chat into microsoft/vscode by rewriting diff paths under extensions/copilot/, applying the patch locally, and creating a new PR via the gh CLI.
Changes:
- Introduces
build/copilot-migrate-pr.ts, a CLI script that fetches PR metadata + diff frommicrosoft/vscode-copilot-chat. - Rewrites unified diff paths to live under
extensions/copilot/and applies viagit apply --3way. - Pushes a migration branch and opens a PR in
microsoft/vscode, with an option to close the source PR.
Show a summary per file
| File | Description |
|---|---|
| build/copilot-migrate-pr.ts | New migration CLI: fetch PR diff/metadata, rewrite paths, apply patch, push branch, and create target PR. |
Copilot's findings
- Files reviewed: 1/1 changed files
- Comments generated: 4
| // Ensure we're on a clean state based on main | ||
| git(['checkout', 'main'], repoRoot); | ||
| git(['pull', '--ff-only', 'origin', 'main'], repoRoot); | ||
|
|
||
| // Create and switch to the new branch | ||
| try { | ||
| git(['checkout', '-b', branchName], repoRoot); | ||
| } catch { | ||
| // Branch may already exist from a previous attempt | ||
| git(['checkout', branchName], repoRoot); | ||
| git(['reset', '--hard', 'main'], repoRoot); | ||
| } |
There was a problem hiding this comment.
createBranchAndApplyDiff performs checkout main, pull, and potentially reset --hard without first verifying the worktree is clean. If the user has local changes, this can fail mid-way (or discard work on an existing migration branch), and it also makes the script risky to run accidentally. Consider checking git status --porcelain up front (and aborting or prompting), and avoid hard-resetting an existing branch without an explicit confirmation.
build/copilot-migrate-pr.ts
Outdated
| } catch { | ||
| console.log('\nThe diff could not be applied cleanly.'); | ||
| console.log('Resolve merge conflicts in your working tree, then continue.'); | ||
| for (; ;) { |
There was a problem hiding this comment.
for (; ;) has extra spaces inside the parentheses and doesn’t match the repo’s usual formatting (e.g. for (;;)). This will likely be reformatted by the formatter/hygiene checks; consider updating it to the standard form.
| for (; ;) { | |
| for (;;) { |
build/copilot-migrate-pr.ts
Outdated
| } | ||
| } | ||
| } finally { | ||
| fs.unlinkSync(tmpDiff); |
There was a problem hiding this comment.
fs.unlinkSync(tmpDiff) in the finally will throw if writeFileSync fails (or if the temp file is otherwise missing), which can mask the original error and leave the repo in a partially modified state. Consider guarding with an existence check or wrapping the unlink in its own try/catch.
| fs.unlinkSync(tmpDiff); | |
| try { | |
| fs.unlinkSync(tmpDiff); | |
| } catch (error: NodeJS.ErrnoException) { | |
| if (error.code !== 'ENOENT') { | |
| throw error; | |
| } | |
| } |
build/copilot-migrate-pr.ts
Outdated
| const branchName = await createBranchAndApplyDiff(prNumber, meta.title, rewrittenDiff, repoRoot); | ||
| shouldRestoreRef = true; |
There was a problem hiding this comment.
shouldRestoreRef is only set to true after createBranchAndApplyDiff completes. If that function throws after changing the current ref (e.g. failing on checkout main/pull), the finally block won’t restore originalRef. Consider setting shouldRestoreRef before calling into the code that mutates git state (or restoring whenever getCurrentRef(repoRoot) differs from originalRef).
| const branchName = await createBranchAndApplyDiff(prNumber, meta.title, rewrittenDiff, repoRoot); | |
| shouldRestoreRef = true; | |
| shouldRestoreRef = true; | |
| const branchName = await createBranchAndApplyDiff(prNumber, meta.title, rewrittenDiff, repoRoot); |
…n script Co-authored-by: Copilot <copilot@github.com>
… conflicts Co-authored-by: Copilot <copilot@github.com>
Run this to migrate PRs from
vscode-copilot-chat:Example: