Skip to content

Commit ef35a9c

Browse files
authored
Add "auto" option for create base branch (#5860)
Fixes #5859
1 parent 73b2c29 commit ef35a9c

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -439,12 +439,13 @@
439439
},
440440
"githubPullRequests.createDefaultBaseBranch": {
441441
"type": "string",
442-
"enum": ["repositoryDefault", "createdFromBranch"],
442+
"enum": ["repositoryDefault", "createdFromBranch", "auto"],
443443
"markdownEnumDescriptions": [
444444
"%githubPullRequests.createDefaultBaseBranch.repositoryDefault%",
445-
"%githubPullRequests.createDefaultBaseBranch.createdFromBranch%"
445+
"%githubPullRequests.createDefaultBaseBranch.createdFromBranch%",
446+
"%githubPullRequests.createDefaultBaseBranch.auto%"
446447
],
447-
"default": "createdFromBranch",
448+
"default": "auto",
448449
"markdownDescription": "%githubPullRequests.createDefaultBaseBranch.description%"
449450
},
450451
"githubIssues.ignoreMilestones": {

package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
"githubPullRequests.createDefaultBaseBranch.description": "Controls what the base branch picker defaults to when creating a pull request",
8686
"githubPullRequests.createDefaultBaseBranch.repositoryDefault": "The default branch of the repository",
8787
"githubPullRequests.createDefaultBaseBranch.createdFromBranch": "The branch that the current branch was created from, if known",
88+
"githubPullRequests.createDefaultBaseBranch.auto": "When the current repository is a fork, this will work like \"repositoryDefault\". Otherwise, it will work like \"createdFromBranch\".",
8889
"githubIssues.ignoreMilestones.description": "An array of milestones titles to never show issues from.",
8990
"githubIssues.createIssueTriggers.description": "Strings that will cause the 'Create issue from comment' code action to show.",
9091
"githubIssues.createIssueTriggers.items": "String that enables the 'Create issue from comment' code action. Should not contain whitespace.",

src/github/createPRViewProviderNew.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,12 +307,18 @@ export class CreatePullRequestViewProviderNew extends WebviewViewBase implements
307307
return this._alreadyInitializing;
308308
}
309309

310-
private async detectBaseMetadata(defaultCompareBranch: string): Promise<BaseBranchMetadata | undefined> {
311-
if (vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).get<'repositoryDefault' | 'createdFromBranch'>(CREATE_BASE_BRANCH) !== 'createdFromBranch') {
310+
private async detectBaseMetadata(defaultCompareBranch: Branch, owner: string, repositoryName: string): Promise<BaseBranchMetadata | undefined> {
311+
const settingValue = vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).get<'repositoryDefault' | 'createdFromBranch' | 'auto'>(CREATE_BASE_BRANCH);
312+
if (!defaultCompareBranch.name || settingValue === 'repositoryDefault') {
312313
return undefined;
313314
}
315+
const githubRepo = this._folderRepositoryManager.findRepo(repo => compareIgnoreCase(repo.remote.owner, owner) === 0 && compareIgnoreCase(repo.remote.repositoryName, repositoryName) === 0);
316+
if (settingValue === 'auto' && (await githubRepo?.getMetadata())?.fork) {
317+
return undefined;
318+
}
319+
314320
try {
315-
const baseFromProvider = await this._folderRepositoryManager.repository.getBranchBase(defaultCompareBranch);
321+
const baseFromProvider = await this._folderRepositoryManager.repository.getBranchBase(defaultCompareBranch.name);
316322
if (baseFromProvider?.name) {
317323
const repo = this._folderRepositoryManager.findRepo(repo => repo.remote.remoteName === baseFromProvider.remote);
318324
if (repo) {
@@ -332,7 +338,7 @@ export class CreatePullRequestViewProviderNew extends WebviewViewBase implements
332338
private async doInitializeParams(): Promise<CreateParamsNew> {
333339
const defaultCompareBranch = await this._folderRepositoryManager.repository.getBranch(this._defaultCompareBranch);
334340
const [detectedBaseMetadata, remotes, defaultOrigin] = await Promise.all([
335-
this.detectBaseMetadata(defaultCompareBranch.name!),
341+
this.detectBaseMetadata(defaultCompareBranch, this.model.compareOwner, this.model.repositoryName),
336342
this._folderRepositoryManager.getGitHubRemotes(),
337343
this._folderRepositoryManager.getOrigin(defaultCompareBranch)]);
338344

0 commit comments

Comments
 (0)