Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2371,6 +2371,7 @@ ${contents}
origin.remote.owner,
args.compareBranch,
origin.remote.repositoryName,
defaults.repo,
);

try {
Expand Down
47 changes: 25 additions & 22 deletions src/github/createPRViewProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const ISSUE_CLOSING_KEYWORDS = new RegExp('closes|closed|close|fixes|fixed|fix|r

export interface BasePullRequestDataModel {
baseOwner: string;
repositoryName: string;
baseRepositoryName: string;
}

export abstract class BaseCreatePullRequestViewProvider<T extends BasePullRequestDataModel = BasePullRequestDataModel> extends WebviewViewBase implements vscode.WebviewViewProvider {
Expand Down Expand Up @@ -195,7 +195,7 @@ export abstract class BaseCreatePullRequestViewProvider<T extends BasePullReques

// Called once the detected base branch is known, before getTitleAndDescription runs.
// Subclasses can override to update model state that getTitleAndDescription depends on.
protected onBaseBranchDetected(_baseOwner: string, _baseBranch: string): void { }
protected onBaseBranchDetected(_baseRemote: RemoteInfo, _baseBranch: string): void { }

protected getTitleAndDescriptionProvider(name?: string) {
return this._folderRepositoryManager.getTitleAndDescriptionProvider(name);
Expand Down Expand Up @@ -223,7 +223,7 @@ export abstract class BaseCreatePullRequestViewProvider<T extends BasePullReques
const defaultBaseBranch = detectedBaseMetadata?.branch ?? this._pullRequestDefaults.base;

// Notify subclasses so they can update model state before getTitleAndDescription runs.
this.onBaseBranchDetected(defaultBaseRemote.owner, defaultBaseBranch);
this.onBaseBranchDetected(defaultBaseRemote, defaultBaseBranch);

let defaultTitleAndDescription: { title: string; description: string };
let mergeConfiguration: RepoAccessAndMergeMethods | undefined;
Expand Down Expand Up @@ -413,11 +413,11 @@ export abstract class BaseCreatePullRequestViewProvider<T extends BasePullReques
}

private async getBaseRemote(): Promise<GitHubRemote> {
return (await this._folderRepositoryManager.getGitHubRemotes()).find(remote => compareIgnoreCase(remote.owner, this.model.baseOwner) === 0 && compareIgnoreCase(remote.repositoryName, this.model.repositoryName) === 0)!;
return (await this._folderRepositoryManager.getGitHubRemotes()).find(remote => compareIgnoreCase(remote.owner, this.model.baseOwner) === 0 && compareIgnoreCase(remote.repositoryName, this.model.baseRepositoryName) === 0)!;
}

private getBaseGitHubRepo(): GitHubRepository | undefined {
return this._folderRepositoryManager.gitHubRepositories.find(repo => compareIgnoreCase(repo.remote.owner, this.model.baseOwner) === 0 && compareIgnoreCase(repo.remote.repositoryName, this.model.repositoryName) === 0);
return this._folderRepositoryManager.gitHubRepositories.find(repo => compareIgnoreCase(repo.remote.owner, this.model.baseOwner) === 0 && compareIgnoreCase(repo.remote.repositoryName, this.model.baseRepositoryName) === 0);
}

private milestone: IMilestone | undefined;
Expand Down Expand Up @@ -513,7 +513,7 @@ export abstract class BaseCreatePullRequestViewProvider<T extends BasePullReques
let newLabels: DisplayLabel[] = [];

const labelsToAdd = await vscode.window.showQuickPick<vscode.QuickPickItem & { name: string }>(
getLabelOptions(this._folderRepositoryManager, this.labels, this.model.baseOwner, this.model.repositoryName).then(options => {
getLabelOptions(this._folderRepositoryManager, this.labels, this.model.baseOwner, this.model.baseRepositoryName).then(options => {
newLabels = options.newLabels;
return options.labelPicks;
}),
Expand Down Expand Up @@ -691,8 +691,8 @@ export class CreatePullRequestViewProvider extends BaseCreatePullRequestViewProv
const stackCandidateSequence = ++this._stackCandidateSequence;
let baseRemote: RemoteInfo | undefined;
let baseBranch: string | undefined;
if (e.baseOwner) {
const gitHubRemote = this._folderRepositoryManager.findRepo(repo => compareIgnoreCase(repo.remote.owner, e.baseOwner!) === 0 && compareIgnoreCase(repo.remote.repositoryName, this.model.repositoryName) === 0)?.remote;
if (e.baseOwner || e.baseRepositoryName) {
const gitHubRemote = this._folderRepositoryManager.findRepo(repo => compareIgnoreCase(repo.remote.owner, this.model.baseOwner) === 0 && compareIgnoreCase(repo.remote.repositoryName, this.model.baseRepositoryName) === 0)?.remote;
baseRemote = gitHubRemote ? serializeRemoteInfo(gitHubRemote) : undefined;
baseBranch = this.model.baseBranch;
}
Comment on lines +694 to 698
Expand All @@ -709,14 +709,19 @@ export class CreatePullRequestViewProvider extends BaseCreatePullRequestViewProv
if (e.compareBranch) {
compareBranch = e.compareBranch;
}
const warning = await this.existingPRMessage();
// A later change posts its own update, so this one doesn't need its own stack lookup.
if (stackCandidateSequence !== this._stackCandidateSequence) {
return;
}
const params: Partial<CreateParamsNew> = {
baseRemote,
baseBranch,
compareRemote,
compareBranch,
warning: await this.existingPRMessage(),
warning,
stackCandidate: await this.getStackCandidateForView(
{ owner: this.model.baseOwner, repositoryName: this.model.repositoryName },
{ owner: this.model.baseOwner, repositoryName: this.model.baseRepositoryName },
this.model.baseBranch,
{ owner: this.model.compareOwner, repositoryName: this.model.repositoryName },
this.model.compareBranch
Expand Down Expand Up @@ -754,9 +759,9 @@ export class CreatePullRequestViewProvider extends BaseCreatePullRequestViewProv
return;
}
this._defaultCompareBranch = compareBranch.name;
const { baseOwner, baseBranch, compareOwner } = this.model;
const { baseOwner, baseRepositoryName, baseBranch, compareOwner } = this.model;
const isCurrentSelection = () =>
this.model.baseOwner === baseOwner && this.model.baseBranch === baseBranch
this.model.baseOwner === baseOwner && this.model.baseRepositoryName === baseRepositoryName && this.model.baseBranch === baseBranch
&& this.model.compareOwner === compareOwner && this.model.compareBranch === compareBranch.name;
try {
const titleAndDescription = await this.changeBranch(compareBranch.name, false);
Expand All @@ -766,7 +771,7 @@ export class CreatePullRequestViewProvider extends BaseCreatePullRequestViewProv
const [warning, stackCandidate] = await Promise.all([
this.existingPRMessage(),
this.getStackCandidateForView(
{ owner: baseOwner, repositoryName: this.model.repositoryName },
{ owner: baseOwner, repositoryName: baseRepositoryName },
baseBranch,
{ owner: compareOwner, repositoryName: this.model.repositoryName },
compareBranch.name
Expand Down Expand Up @@ -935,7 +940,7 @@ export class CreatePullRequestViewProvider extends BaseCreatePullRequestViewProv
const user = /\$\{user\}/.test(template) ? await this.lookupTemplateValue('user', () => this._folderRepositoryManager.getCurrentUser()) : undefined;
return variableSubstitution(template, issue, {
owner: this.model.baseOwner,
repo: this.model.repositoryName,
repo: this.model.baseRepositoryName,
base: baseBranch,
}, user?.login);
}
Expand Down Expand Up @@ -1114,9 +1119,8 @@ Don't forget to commit your template file to the repository so that it can be us
}
}

protected override onBaseBranchDetected(baseOwner: string, baseBranch: string): void {
this.model.baseOwner = baseOwner;
this.model.baseBranch = baseBranch;
protected override onBaseBranchDetected(baseRemote: RemoteInfo, baseBranch: string): void {
this.model.setBase(baseRemote.owner, baseRemote.repositoryName, baseBranch);
}

protected override async getCreateParams(): Promise<CreateParamsNew> {
Expand Down Expand Up @@ -1207,10 +1211,9 @@ Don't forget to commit your template file to the repository so that it can be us
if (isBase) {
const warning = await this.existingPRMessage();
commands.setContext(contexts.CREATE_PR_PERMISSIONS, viewerPermission);
const baseRemoteChanged = this.model.baseOwner !== result.remote.owner;
const baseRemoteChanged = this.model.baseOwner !== result.remote.owner || this.model.baseRepositoryName !== result.remote.repositoryName;
const baseBranchChanged = baseRemoteChanged || this.model.baseBranch !== result.branch;
this.model.baseOwner = result.remote.owner;
this.model.baseBranch = result.branch;
this.model.setBase(result.remote.owner, result.remote.repositoryName, result.branch);

// Save the selected base branch to recently used branches
this.saveRecentlyUsedBranch(result.remote.owner, result.remote.repositoryName, result.branch);
Expand All @@ -1219,7 +1222,7 @@ Don't forget to commit your template file to the repository so that it can be us
const [mergeConfiguration, titleAndDescription, mergeQueueMethodForBranch] = await Promise.all([
this.getMergeConfiguration(result.remote.owner, result.remote.repositoryName),
this.getTitleAndDescription(compareBranch, this.model.baseBranch),
this._folderRepositoryManager.mergeQueueMethodForBranch(this.model.baseBranch, this.model.baseOwner, this.model.repositoryName)]);
this._folderRepositoryManager.mergeQueueMethodForBranch(this.model.baseBranch, this.model.baseOwner, this.model.baseRepositoryName)]);
let autoMergeDefault = false;
if (mergeConfiguration?.viewerCanAutoMerge) {
const defaultCreateOption = vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).get<'lastUsed' | 'create' | 'createDraft' | 'createAutoMerge'>(DEFAULT_CREATE_OPTION, 'lastUsed');
Expand Down Expand Up @@ -1268,7 +1271,7 @@ Don't forget to commit your template file to the repository so that it can be us
defaultCompareBranch: defaultBranch,
defaultDescription: titleAndDescription.description,
stackCandidate: await this.getStackCandidateForView(
{ owner: this.model.baseOwner, repositoryName: this.model.repositoryName },
{ owner: this.model.baseOwner, repositoryName: this.model.baseRepositoryName },
this.model.baseBranch, result.remote, result.branch),
warning: await this.existingPRMessage()
};
Expand Down
Loading
Loading