Skip to content

Commit 0a485e6

Browse files
committed
Reuse branch picks code
1 parent b8c6062 commit 0a485e6

File tree

3 files changed

+45
-55
lines changed

3 files changed

+45
-55
lines changed

src/github/createPRViewProvider.ts

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ import { IAccount, ILabel, IMilestone, IProject, isITeam, ITeam, MergeMethod, Re
1515
import { BaseBranchMetadata, PullRequestGitHelper } from './pullRequestGitHelper';
1616
import { PullRequestModel } from './pullRequestModel';
1717
import { getDefaultMergeMethod } from './pullRequestOverview';
18-
import { getAssigneesQuickPickItems, getLabelOptions, getMilestoneFromQuickPick, getProjectFromQuickPick, reviewersQuickPick } from './quickPicks';
18+
import { branchPicks, getAssigneesQuickPickItems, getLabelOptions, getMilestoneFromQuickPick, getProjectFromQuickPick, reviewersQuickPick } from './quickPicks';
1919
import { getIssueNumberLabelFromParsed, ISSUE_EXPRESSION, ISSUE_OR_URL_EXPRESSION, parseIssueExpressionOutput, variableSubstitution } from './utils';
2020
import { DisplayLabel, PreReviewState } from './views';
2121
import { RemoteInfo } from '../../common/types';
2222
import { ChooseBaseRemoteAndBranchResult, ChooseCompareRemoteAndBranchResult, ChooseRemoteAndBranchArgs, CreateParamsNew, CreatePullRequestNew, TitleAndDescriptionArgs } from '../../common/views';
23-
import type { Branch, Ref } from '../api/api';
23+
import type { Branch } from '../api/api';
2424
import { GitHubServerType } from '../common/authentication';
2525
import { emojify, ensureEmojis } from '../common/emoji';
2626
import { commands, contexts } from '../common/executeCommands';
@@ -812,40 +812,6 @@ export class CreatePullRequestViewProvider extends BaseCreatePullRequestViewProv
812812
});
813813
}
814814

815-
private async branchPicks(githubRepository: GitHubRepository, changeRepoMessage: string, isBase: boolean): Promise<(vscode.QuickPickItem & { remote?: RemoteInfo, branch?: string })[]> {
816-
let branches: (string | Ref)[];
817-
if (isBase) {
818-
// For the base, we only want to show branches from GitHub.
819-
branches = await githubRepository.listBranches(githubRepository.remote.owner, githubRepository.remote.repositoryName);
820-
} else {
821-
// For the compare, we only want to show local branches.
822-
branches = (await this._folderRepositoryManager.repository.getBranches({ remote: false })).filter(branch => branch.name);
823-
}
824-
// TODO: @alexr00 - Add sorting so that the most likely to be used branch (ex main or release if base) is at the top of the list.
825-
const branchPicks: (vscode.QuickPickItem & { remote?: RemoteInfo, branch?: string })[] = branches.map(branch => {
826-
const branchName = typeof branch === 'string' ? branch : branch.name!;
827-
const pick: (vscode.QuickPickItem & { remote: RemoteInfo, branch: string }) = {
828-
iconPath: new vscode.ThemeIcon('git-branch'),
829-
label: branchName,
830-
remote: {
831-
owner: githubRepository.remote.owner,
832-
repositoryName: githubRepository.remote.repositoryName
833-
},
834-
branch: branchName
835-
};
836-
return pick;
837-
});
838-
branchPicks.unshift({
839-
kind: vscode.QuickPickItemKind.Separator,
840-
label: `${githubRepository.remote.owner}/${githubRepository.remote.repositoryName}`
841-
});
842-
branchPicks.unshift({
843-
iconPath: new vscode.ThemeIcon('repo'),
844-
label: changeRepoMessage
845-
});
846-
return branchPicks;
847-
}
848-
849815
private async processRemoteAndBranchResult(githubRepository: GitHubRepository, result: { remote: RemoteInfo, branch: string }, isBase: boolean) {
850816
const [defaultBranch, viewerPermission] = await Promise.all([githubRepository.getDefaultBranch(), githubRepository.getViewerPermission()]);
851817

@@ -922,7 +888,7 @@ export class CreatePullRequestViewProvider extends BaseCreatePullRequestViewProv
922888
quickPick.placeholder = githubRepository ? branchPlaceholder : remotePlaceholder;
923889
quickPick.show();
924890
quickPick.busy = true;
925-
quickPick.items = githubRepository ? await this.branchPicks(githubRepository, chooseDifferentRemote, isBase) : await this.remotePicks(isBase);
891+
quickPick.items = githubRepository ? await branchPicks(githubRepository, this._folderRepositoryManager, chooseDifferentRemote, isBase) : await this.remotePicks(isBase);
926892
const activeItem = message.args.currentBranch ? quickPick.items.find(item => item.branch === message.args.currentBranch) : undefined;
927893
quickPick.activeItems = activeItem ? [activeItem] : [];
928894
quickPick.busy = false;
@@ -941,7 +907,7 @@ export class CreatePullRequestViewProvider extends BaseCreatePullRequestViewProv
941907
const selectedRemote = selectedPick as vscode.QuickPickItem & { remote: RemoteInfo };
942908
quickPick.busy = true;
943909
githubRepository = this._folderRepositoryManager.findRepo(repo => repo.remote.owner === selectedRemote.remote.owner && repo.remote.repositoryName === selectedRemote.remote.repositoryName)!;
944-
quickPick.items = await this.branchPicks(githubRepository, chooseDifferentRemote, isBase);
910+
quickPick.items = await branchPicks(githubRepository, this._folderRepositoryManager, chooseDifferentRemote, isBase);
945911
quickPick.placeholder = branchPlaceholder;
946912
quickPick.busy = false;
947913
} else if (selectedPick.branch && selectedPick.remote) {

src/github/pullRequestOverview.ts

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
import { IssueOverviewPanel } from './issueOverview';
2424
import { isCopilotOnMyBehalf, PullRequestModel } from './pullRequestModel';
2525
import { PullRequestReviewCommon, ReviewContext } from './pullRequestReviewCommon';
26-
import { pickEmail, reviewersQuickPick } from './quickPicks';
26+
import { branchPicks, pickEmail, reviewersQuickPick } from './quickPicks';
2727
import { parseReviewers } from './utils';
2828
import { CancelCodingAgentReply, DeleteReviewResult, MergeArguments, MergeResult, PullRequest, ReviewType } from './views';
2929
import { IComment } from '../common/comment';
@@ -813,21 +813,10 @@ export class PullRequestOverviewPanel extends IssueOverviewPanel<PullRequestMode
813813
try {
814814
quickPick.busy = true;
815815
quickPick.canSelectMany = false;
816-
quickPick.placeholder = 'Select a new base branch';
816+
quickPick.placeholder = vscode.l10n.t('Select a new base branch');
817817
quickPick.show();
818818

819-
// List branches from the repository
820-
const branches = await this._item.githubRepository.listBranches(
821-
this._item.remote.owner,
822-
this._item.remote.repositoryName
823-
);
824-
825-
quickPick.items = branches
826-
.filter(branch => branch !== this._item.base.name)
827-
.map(branch => ({
828-
label: branch,
829-
branch: branch
830-
}));
819+
quickPick.items = await branchPicks(this._item.githubRepository, this._folderRepositoryManager, undefined, true);
831820

832821
quickPick.busy = false;
833822
const acceptPromise = asPromise<void>(quickPick.onDidAccept).then(() => {
@@ -840,10 +829,7 @@ export class PullRequestOverviewPanel extends IssueOverviewPanel<PullRequestMode
840829

841830
if (selectedBranch) {
842831
try {
843-
// Update the base branch using GraphQL mutation
844832
await this._item.updateBaseBranch(selectedBranch);
845-
// Refresh the panel to reflect the changes
846-
await this.refreshPanel();
847833
await this._replyMessage(message, {});
848834
} catch (e) {
849835
Logger.error(formatError(e), PullRequestOverviewPanel.ID);

src/github/quickPicks.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import { GitHubRepository, TeamReviewerRefreshKind } from './githubRepository';
1111
import { AccountType, IAccount, ILabel, IMilestone, IProject, isISuggestedReviewer, isITeam, ISuggestedReviewer, ITeam, reviewerId, ReviewState } from './interface';
1212
import { IssueModel } from './issueModel';
1313
import { DisplayLabel } from './views';
14+
import { RemoteInfo } from '../../common/types';
15+
import { Ref } from '../api/api';
1416
import { COPILOT_ACCOUNTS } from '../common/comment';
1517
import { COPILOT_REVIEWER, COPILOT_REVIEWER_ID, COPILOT_SWE_AGENT } from '../common/copilot';
1618
import { emojify, ensureEmojis } from '../common/emoji';
@@ -479,4 +481,40 @@ export async function pickEmail(githubRepository: GitHubRepository, current: str
479481

480482
const result = await vscode.window.showQuickPick(getEmails(), { canPickMany: false, title: vscode.l10n.t('Choose an email') });
481483
return result ? result.label : undefined;
484+
}
485+
486+
export async function branchPicks(githubRepository: GitHubRepository, folderRepoManager: FolderRepositoryManager, changeRepoMessage: string | undefined, isBase: boolean): Promise<(vscode.QuickPickItem & { remote?: RemoteInfo, branch?: string })[]> {
487+
let branches: (string | Ref)[];
488+
if (isBase) {
489+
// For the base, we only want to show branches from GitHub.
490+
branches = await githubRepository.listBranches(githubRepository.remote.owner, githubRepository.remote.repositoryName);
491+
} else {
492+
// For the compare, we only want to show local branches.
493+
branches = (await folderRepoManager.repository.getBranches({ remote: false })).filter(branch => branch.name);
494+
}
495+
// TODO: @alexr00 - Add sorting so that the most likely to be used branch (ex main or release if base) is at the top of the list.
496+
const branchPicks: (vscode.QuickPickItem & { remote?: RemoteInfo, branch?: string })[] = branches.map(branch => {
497+
const branchName = typeof branch === 'string' ? branch : branch.name!;
498+
const pick: (vscode.QuickPickItem & { remote: RemoteInfo, branch: string }) = {
499+
iconPath: new vscode.ThemeIcon('git-branch'),
500+
label: branchName,
501+
remote: {
502+
owner: githubRepository.remote.owner,
503+
repositoryName: githubRepository.remote.repositoryName
504+
},
505+
branch: branchName
506+
};
507+
return pick;
508+
});
509+
branchPicks.unshift({
510+
kind: vscode.QuickPickItemKind.Separator,
511+
label: `${githubRepository.remote.owner}/${githubRepository.remote.repositoryName}`
512+
});
513+
if (changeRepoMessage) {
514+
branchPicks.unshift({
515+
iconPath: new vscode.ThemeIcon('repo'),
516+
label: changeRepoMessage
517+
});
518+
}
519+
return branchPicks;
482520
}

0 commit comments

Comments
 (0)