Skip to content

Commit 60aca42

Browse files
authored
Create pull request should notify if a pull request is already created (#6806)
Fixes #6132
1 parent d222c35 commit 60aca42

5 files changed

Lines changed: 24 additions & 5 deletions

File tree

common/views.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ export interface CreateParamsNew {
121121
validate?: boolean;
122122
showTitleValidationError?: boolean;
123123
createError?: string;
124+
warning?: string;
124125

125126
autoMergeDefault: boolean;
126127
autoMerge?: boolean;

src/github/createPRViewProvider.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import {
3333
} from './folderRepositoryManager';
3434
import { GitHubRepository } from './githubRepository';
3535
import { IAccount, ILabel, IMilestone, IProject, isTeam, ITeam, MergeMethod, RepoAccessAndMergeMethods } from './interface';
36-
import { BaseBranchMetadata } from './pullRequestGitHelper';
36+
import { BaseBranchMetadata, PullRequestGitHelper } from './pullRequestGitHelper';
3737
import { PullRequestModel } from './pullRequestModel';
3838
import { getDefaultMergeMethod } from './pullRequestOverview';
3939
import { getAssigneesQuickPickItems, getLabelOptions, getMilestoneFromQuickPick, getProjectFromQuickPick, reviewersQuickPick } from './quickPicks';
@@ -605,7 +605,8 @@ export class CreatePullRequestViewProvider extends BaseCreatePullRequestViewProv
605605
baseRemote,
606606
baseBranch,
607607
compareRemote,
608-
compareBranch
608+
compareBranch,
609+
warning: await this.existingPRMessage(),
609610
};
610611
// TODO: consider updating title and description
611612
return this._postMessage({
@@ -616,19 +617,25 @@ export class CreatePullRequestViewProvider extends BaseCreatePullRequestViewProv
616617
}));
617618
}
618619

620+
private async existingPRMessage(): Promise<string | undefined> {
621+
const existingPR = await PullRequestGitHelper.getMatchingPullRequestMetadataForBranch(this._folderRepositoryManager.repository, this.model.compareBranch);
622+
return existingPR ? vscode.l10n.t('A pull request already exists for this branch.') : '';
623+
}
624+
619625
public async setDefaultCompareBranch(compareBranch: Branch | undefined) {
620626
const branchChanged = compareBranch && (compareBranch.name !== this.model.compareBranch);
621627
const currentCompareRemote = this._folderRepositoryManager.gitHubRepositories.find(repo => repo.remote.owner === this.model.compareOwner)?.remote.remoteName;
622628
const branchRemoteChanged = compareBranch && (compareBranch.upstream?.remote !== currentCompareRemote);
623629
if (branchChanged || branchRemoteChanged) {
624630
this._defaultCompareBranch = compareBranch!.name!;
625631
this.model.setCompareBranch(compareBranch!.name);
626-
this.changeBranch(compareBranch!.name!, false).then(titleAndDescription => {
632+
this.changeBranch(compareBranch!.name!, false).then(async titleAndDescription => {
627633
const params: Partial<CreateParamsNew> = {
628634
defaultTitle: titleAndDescription.title,
629635
defaultDescription: titleAndDescription.description,
630636
compareBranch: compareBranch?.name,
631-
defaultCompareBranch: compareBranch?.name
637+
defaultCompareBranch: compareBranch?.name,
638+
warning: await this.existingPRMessage(),
632639
};
633640
if (!branchRemoteChanged) {
634641
return this._postMessage({

src/github/pullRequestOverview.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import {
2929
ReviewState,
3030
} from './interface';
3131
import { IssueOverviewPanel } from './issueOverview';
32-
import { PullRequestGitHelper } from './pullRequestGitHelper';
3332
import { PullRequestModel } from './pullRequestModel';
3433
import { PullRequestView } from './pullRequestOverviewCommon';
3534
import { pickEmail, reviewersQuickPick } from './quickPicks';

webviews/createPullRequestViewNew/app.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,11 @@ export function main() {
342342
{params.createError}
343343
</ErrorBoundary>
344344
</div>
345+
<div className={!!params.warning ? 'wrapper validation-warning' : 'hidden'} aria-live='assertive'>
346+
<ErrorBoundary>
347+
{params.warning}
348+
</ErrorBoundary>
349+
</div>
345350

346351
<div className='group-actions'>
347352
<button disabled={isBusy} className='secondary' onClick={() => ctx.cancelCreate()}>

webviews/createPullRequestViewNew/index.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,13 @@ textarea {
162162
color: var(--vscode-inputValidation-errorForeground);
163163
}
164164

165+
.validation-warning {
166+
padding: 5px;
167+
border: 1px solid var(--vscode-inputValidation-warningBorder);
168+
background-color: var(--vscode-inputValidation-warningBackground);
169+
color: var(--vscode-inputValidation-warningForeground);
170+
}
171+
165172
.below-input-error {
166173
border-top: none !important;
167174
}

0 commit comments

Comments
 (0)