Skip to content

Commit 3783529

Browse files
committed
Clean up
1 parent 16385b5 commit 3783529

5 files changed

Lines changed: 25 additions & 33 deletions

File tree

src/common/settingKeys.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ export const NOTIFICATION_SETTING = 'notifications';
2222
export type NotificationVariants = 'off' | 'pullRequests';
2323
export const POST_CREATE = 'postCreate';
2424
export const POST_DONE = 'postDone';
25+
export const CHECKOUT_PULL_REQUEST_BASE_BRANCH = 'checkoutPullRequestBaseBranch';
26+
export const CHECKOUT_DEFAULT_BRANCH = 'checkoutDefaultBranch';
2527
export const QUERIES = 'queries';
2628
export const PULL_REQUEST_LABELS = 'labelCreated';
2729
export const FOCUSED_MODE = 'focusedMode';

src/github/activityBarViewProvider.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { MergeArguments, PullRequest, ReviewType } from './views';
1515
import { IComment } from '../common/comment';
1616
import { emojify, ensureEmojis } from '../common/emoji';
1717
import { disposeAll } from '../common/lifecycle';
18-
import { POST_DONE, PR_SETTINGS_NAMESPACE } from '../common/settingKeys';
18+
import { CHECKOUT_DEFAULT_BRANCH, CHECKOUT_PULL_REQUEST_BASE_BRANCH, POST_DONE, PR_SETTINGS_NAMESPACE } from '../common/settingKeys';
1919
import { ReviewEvent } from '../common/timelineEvent';
2020
import { formatError } from '../common/utils';
2121
import { generateUuid } from '../common/uuid';
@@ -233,8 +233,8 @@ export class PullRequestViewProvider extends WebviewViewBase implements vscode.W
233233
const continueOnGitHub = !!(isCrossRepository && isInCodespaces());
234234
const reviewState = this.getCurrentUserReviewState(this._existingReviewers, currentUser);
235235

236-
const postDoneAction = vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).get<string>(POST_DONE, 'checkoutDefaultBranch');
237-
const doneCheckoutBranch = (postDoneAction === 'checkoutPullRequestBaseBranch' || postDoneAction === 'checkoutPullRequestBaseBranchAndPull')
236+
const postDoneAction = vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).get<string>(POST_DONE, CHECKOUT_DEFAULT_BRANCH);
237+
const doneCheckoutBranch = postDoneAction.startsWith(CHECKOUT_PULL_REQUEST_BASE_BRANCH)
238238
? pullRequest.base.ref
239239
: defaultBranch;
240240

@@ -273,7 +273,7 @@ export class PullRequestViewProvider extends WebviewViewBase implements vscode.W
273273
mergeMethodsAvailability,
274274
defaultMergeMethod,
275275
repositoryDefaultBranch: defaultBranch,
276-
doneCheckoutBranch: doneCheckoutBranch,
276+
doneCheckoutBranch,
277277
isIssue: false,
278278
isAuthor: currentUser.login === pullRequest.author.login,
279279
reviewers: this._existingReviewers,

src/github/folderRepositoryManager.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ import { GitHubRemote, parseRemote, parseRepositoryRemotes, Remote } from '../co
4141
import {
4242
ALLOW_FETCH,
4343
AUTO_STASH,
44+
CHECKOUT_DEFAULT_BRANCH,
45+
CHECKOUT_PULL_REQUEST_BASE_BRANCH,
4446
GIT,
4547
POST_DONE,
4648
PR_SETTINGS_NAMESPACE,
@@ -2384,29 +2386,26 @@ export class FolderRepositoryManager extends Disposable {
23842386
}
23852387

23862388
public async checkoutDefaultBranch(branch: string, pullRequestModel?: PullRequestModel): Promise<void> {
2387-
const CHECKOUT_DEFAULT_BRANCH = 'checkoutDefaultBranch';
2388-
const CHECKOUT_DEFAULT_BRANCH_AND_PULL = 'checkoutDefaultBranchAndPull';
2389-
const CHECKOUT_PR_BASE_BRANCH = 'checkoutPullRequestBaseBranch';
2390-
const CHECKOUT_PR_BASE_BRANCH_AND_PULL = 'checkoutPullRequestBaseBranchAndPull';
2389+
const AND_PULL = 'AndPull';
23912390

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);
2391+
const postDoneAction = vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).get<string>(POST_DONE, CHECKOUT_DEFAULT_BRANCH);
23932392

23942393
// Determine which branch to checkout
23952394
let targetBranch = branch;
2396-
if (pullRequestModel && (postDoneAction === CHECKOUT_PR_BASE_BRANCH || postDoneAction === CHECKOUT_PR_BASE_BRANCH_AND_PULL)) {
2395+
if (pullRequestModel && postDoneAction.startsWith(CHECKOUT_PULL_REQUEST_BASE_BRANCH)) {
23972396
// Use the PR's base branch if the setting specifies it
23982397
targetBranch = pullRequestModel.base.ref;
23992398
}
24002399

2401-
if (postDoneAction === CHECKOUT_DEFAULT_BRANCH_AND_PULL || postDoneAction === CHECKOUT_PR_BASE_BRANCH_AND_PULL) {
2402-
await this.checkoutDefaultBranchAndPull(targetBranch);
2400+
if (postDoneAction.endsWith(AND_PULL)) {
2401+
await this.checkoutDoneBranchAndPull(targetBranch);
24032402
} else {
2404-
await this.checkoutDefaultBranchOnly(targetBranch);
2403+
await this.checkoutDoneBranchOnly(targetBranch);
24052404
}
24062405
}
24072406

2408-
private async checkoutDefaultBranchAndPull(branch: string): Promise<void> {
2409-
await this.checkoutDefaultBranchOnly(branch);
2407+
private async checkoutDoneBranchAndPull(branch: string): Promise<void> {
2408+
await this.checkoutDoneBranchOnly(branch);
24102409
// After checking out, pull the latest changes if the branch has an upstream
24112410
try {
24122411
const branchObj = await this.repository.getBranch(branch);
@@ -2420,7 +2419,7 @@ export class FolderRepositoryManager extends Disposable {
24202419
}
24212420
}
24222421

2423-
private async checkoutDefaultBranchOnly(branch: string): Promise<void> {
2422+
private async checkoutDoneBranchOnly(branch: string): Promise<void> {
24242423
let branchObj: Branch | undefined;
24252424
try {
24262425
branchObj = await this.repository.getBranch(branch);

src/github/pullRequestOverview.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import { COPILOT_SWE_AGENT, copilotEventToStatus, CopilotPRStatus, mostRecentCop
3131
import { commands, contexts } from '../common/executeCommands';
3232
import { disposeAll } from '../common/lifecycle';
3333
import Logger from '../common/logger';
34-
import { DEFAULT_MERGE_METHOD, POST_DONE, PR_SETTINGS_NAMESPACE } from '../common/settingKeys';
34+
import { CHECKOUT_DEFAULT_BRANCH, CHECKOUT_PULL_REQUEST_BASE_BRANCH, DEFAULT_MERGE_METHOD, POST_DONE, PR_SETTINGS_NAMESPACE } from '../common/settingKeys';
3535
import { ITelemetry } from '../common/telemetry';
3636
import { EventType, ReviewEvent, SessionLinkInfo, TimelineEvent } from '../common/timelineEvent';
3737
import { asPromise, formatError } from '../common/utils';
@@ -306,8 +306,8 @@ export class PullRequestOverviewPanel extends IssueOverviewPanel<PullRequestMode
306306

307307
this.preLoadInfoNotRequiredForOverview(pullRequest);
308308

309-
const postDoneAction = vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).get<string>(POST_DONE, 'checkoutDefaultBranch');
310-
const doneCheckoutBranch = (postDoneAction === 'checkoutPullRequestBaseBranch' || postDoneAction === 'checkoutPullRequestBaseBranchAndPull')
309+
const postDoneAction = vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).get<string>(POST_DONE, CHECKOUT_DEFAULT_BRANCH);
310+
const doneCheckoutBranch = postDoneAction.startsWith(CHECKOUT_PULL_REQUEST_BASE_BRANCH)
311311
? pullRequest.base.ref
312312
: defaultBranch;
313313

webviews/components/header.tsx

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ export function Header({
2727
isCurrentlyCheckedOut,
2828
isDraft,
2929
isIssue,
30-
repositoryDefaultBranch,
3130
doneCheckoutBranch,
3231
events,
3332
owner,
@@ -58,7 +57,6 @@ export function Header({
5857
<ButtonGroup
5958
isCurrentlyCheckedOut={isCurrentlyCheckedOut}
6059
isIssue={isIssue}
61-
repositoryDefaultBranch={repositoryDefaultBranch}
6260
doneCheckoutBranch={doneCheckoutBranch}
6361
owner={owner}
6462
repo={repo}
@@ -148,20 +146,19 @@ function Title({ title, titleHTML, number, url, inEditMode, setEditMode, setCurr
148146
interface ButtonGroupProps {
149147
isCurrentlyCheckedOut: boolean;
150148
isIssue: boolean;
151-
repositoryDefaultBranch: string;
152149
doneCheckoutBranch: string;
153150
owner: string;
154151
repo: string;
155152
number: number;
156153
busy?: boolean;
157154
}
158155

159-
function ButtonGroup({ isCurrentlyCheckedOut, isIssue, repositoryDefaultBranch, doneCheckoutBranch, owner, repo, number, busy }: ButtonGroupProps): JSX.Element {
156+
function ButtonGroup({ isCurrentlyCheckedOut, isIssue, doneCheckoutBranch, owner, repo, number, busy }: ButtonGroupProps): JSX.Element {
160157
const { refresh } = useContext(PullRequestContext);
161158

162159
return (
163160
<div className="button-group">
164-
<CheckoutButton {...{ isCurrentlyCheckedOut, isIssue, repositoryDefaultBranch, doneCheckoutBranch, owner, repo, number }} />
161+
<CheckoutButton {...{ isCurrentlyCheckedOut, isIssue, doneCheckoutBranch, owner, repo, number }} />
165162
<button title="Refresh with the latest data from GitHub" onClick={refresh} className="secondary">
166163
Refresh
167164
</button>
@@ -287,14 +284,13 @@ function Subtitle({ state, stateReason, isDraft, isIssue, author, base, head, co
287284
interface CheckoutButtonProps {
288285
isCurrentlyCheckedOut: boolean;
289286
isIssue: boolean;
290-
repositoryDefaultBranch: string;
291287
doneCheckoutBranch: string;
292288
owner: string;
293289
repo: string;
294290
number: number;
295291
}
296292

297-
const CheckoutButton: React.FC<CheckoutButtonProps> = ({ isCurrentlyCheckedOut, isIssue, repositoryDefaultBranch, doneCheckoutBranch, owner, repo, number }) => {
293+
const CheckoutButton: React.FC<CheckoutButtonProps> = ({ isCurrentlyCheckedOut, isIssue, doneCheckoutBranch, owner, repo, number }) => {
298294
const { exitReviewMode, checkout, openChanges } = useContext(PullRequestContext);
299295
const [isBusy, setBusy] = useState(false);
300296

@@ -335,13 +331,8 @@ const CheckoutButton: React.FC<CheckoutButtonProps> = ({ isCurrentlyCheckedOut,
335331
const actions: { label: string; value: string; action: (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void }[] = [];
336332

337333
if (isCurrentlyCheckedOut) {
338-
// Use doneCheckoutBranch which has the appropriate branch name already computed
339-
const buttonLabel = doneCheckoutBranch === repositoryDefaultBranch
340-
? `Checkout '${repositoryDefaultBranch}'`
341-
: `Checkout target branch '${doneCheckoutBranch}'`;
342-
343-
actions.push({
344-
label: buttonLabel,
334+
actions.push({
335+
label: `Checkout '${doneCheckoutBranch}'`,
345336
value: '',
346337
action: () => onClick('exitReviewMode')
347338
});

0 commit comments

Comments
 (0)