Skip to content

Commit 5ac2b15

Browse files
Copilotalexr00
andcommitted
Add checkoutPullRequestBaseBranch options to postDone setting
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent 5436d5d commit 5ac2b15

File tree

5 files changed

+25
-10
lines changed

5 files changed

+25
-10
lines changed

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,13 +476,17 @@
476476
"type": "string",
477477
"enum": [
478478
"checkoutDefaultBranch",
479-
"checkoutDefaultBranchAndPull"
479+
"checkoutDefaultBranchAndPull",
480+
"checkoutPullRequestBaseBranch",
481+
"checkoutPullRequestBaseBranchAndPull"
480482
],
481483
"description": "%githubPullRequests.postDone.description%",
482484
"default": "checkoutDefaultBranch",
483485
"enumDescriptions": [
484486
"%githubPullRequests.postDone.checkoutDefaultBranch%",
485-
"%githubPullRequests.postDone.checkoutDefaultBranchAndPull%"
487+
"%githubPullRequests.postDone.checkoutDefaultBranchAndPull%",
488+
"%githubPullRequests.postDone.checkoutPullRequestBaseBranch%",
489+
"%githubPullRequests.postDone.checkoutPullRequestBaseBranchAndPull%"
486490
]
487491
},
488492
"githubPullRequests.defaultCommentType": {

package.nls.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@
8181
"githubPullRequests.postDone.description": "The action to take after using the 'checkout default branch' or 'delete branch' actions on a currently checked out pull request.",
8282
"githubPullRequests.postDone.checkoutDefaultBranch": "Checkout the default branch of the repository",
8383
"githubPullRequests.postDone.checkoutDefaultBranchAndPull": "Checkout the default branch of the repository and pull the latest changes",
84+
"githubPullRequests.postDone.checkoutPullRequestBaseBranch": "Checkout the pull request's base branch",
85+
"githubPullRequests.postDone.checkoutPullRequestBaseBranchAndPull": "Checkout the pull request's base branch and pull the latest changes",
8486
"githubPullRequests.defaultCommentType.description": "The default comment type to use when submitting a comment and there is no active review",
8587
"githubPullRequests.defaultCommentType.single": "Submits the comment as a single comment that will be immediately visible to other users",
8688
"githubPullRequests.defaultCommentType.review": "Submits the comment as a review comment that will be visible to other users once the review is submitted",

src/commands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ export function registerCommands(
771771
const manager = reposManager.getManagerForIssueModel(pullRequestModel);
772772
if (manager) {
773773
const prBranch = manager.repository.state.HEAD?.name;
774-
await manager.checkoutDefaultBranch(branch);
774+
await manager.checkoutDefaultBranch(branch, pullRequestModel);
775775
if (prBranch) {
776776
await manager.cleanupAfterPullRequest(prBranch, pullRequestModel!);
777777
}

src/github/folderRepositoryManager.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2383,16 +2383,25 @@ export class FolderRepositoryManager extends Disposable {
23832383
}
23842384
}
23852385

2386-
public async checkoutDefaultBranch(branch: string): Promise<void> {
2386+
public async checkoutDefaultBranch(branch: string, pullRequestModel?: PullRequestModel): Promise<void> {
23872387
const CHECKOUT_DEFAULT_BRANCH = 'checkoutDefaultBranch';
23882388
const CHECKOUT_DEFAULT_BRANCH_AND_PULL = 'checkoutDefaultBranchAndPull';
2389+
const CHECKOUT_PR_BASE_BRANCH = 'checkoutPullRequestBaseBranch';
2390+
const CHECKOUT_PR_BASE_BRANCH_AND_PULL = 'checkoutPullRequestBaseBranchAndPull';
23892391

2390-
const postDoneAction = vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).get<typeof CHECKOUT_DEFAULT_BRANCH | typeof CHECKOUT_DEFAULT_BRANCH_AND_PULL>(POST_DONE, CHECKOUT_DEFAULT_BRANCH);
2392+
const postDoneAction = vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).get<typeof CHECKOUT_DEFAULT_BRANCH | typeof CHECKOUT_DEFAULT_BRANCH_AND_PULL | typeof CHECKOUT_PR_BASE_BRANCH | typeof CHECKOUT_PR_BASE_BRANCH_AND_PULL>(POST_DONE, CHECKOUT_DEFAULT_BRANCH);
23912393

2392-
if (postDoneAction === CHECKOUT_DEFAULT_BRANCH_AND_PULL) {
2393-
await this.checkoutDefaultBranchAndPull(branch);
2394+
// Determine which branch to checkout
2395+
let targetBranch = branch;
2396+
if (pullRequestModel && (postDoneAction === CHECKOUT_PR_BASE_BRANCH || postDoneAction === CHECKOUT_PR_BASE_BRANCH_AND_PULL)) {
2397+
// Use the PR's base branch if the setting specifies it
2398+
targetBranch = pullRequestModel.base.ref;
2399+
}
2400+
2401+
if (postDoneAction === CHECKOUT_DEFAULT_BRANCH_AND_PULL || postDoneAction === CHECKOUT_PR_BASE_BRANCH_AND_PULL) {
2402+
await this.checkoutDefaultBranchAndPull(targetBranch);
23942403
} else {
2395-
await this.checkoutDefaultBranchOnly(branch);
2404+
await this.checkoutDefaultBranchOnly(targetBranch);
23962405
}
23972406
}
23982407

src/github/pullRequestReviewCommon.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export namespace PullRequestReviewCommon {
145145
export async function checkoutDefaultBranch(ctx: ReviewContext, message: IRequestMessage<string>): Promise<void> {
146146
try {
147147
const prBranch = ctx.folderRepositoryManager.repository.state.HEAD?.name;
148-
await ctx.folderRepositoryManager.checkoutDefaultBranch(message.args);
148+
await ctx.folderRepositoryManager.checkoutDefaultBranch(message.args, ctx.item);
149149
if (prBranch) {
150150
await ctx.folderRepositoryManager.cleanupAfterPullRequest(prBranch, ctx.item);
151151
}
@@ -372,7 +372,7 @@ export namespace PullRequestReviewCommon {
372372
return;
373373
}
374374
}
375-
await folderRepositoryManager.checkoutDefaultBranch(defaultBranch);
375+
await folderRepositoryManager.checkoutDefaultBranch(defaultBranch, item);
376376
}
377377
await folderRepositoryManager.repository.deleteBranch(branchInfo!.branch, true);
378378
return deletedBranchTypes.push(action.type);

0 commit comments

Comments
 (0)