diff --git a/lib/workers/pr/__snapshots__/index.spec.ts.snap b/lib/workers/pr/__snapshots__/index.spec.ts.snap index 8139e6ef30af4381ce8718a3ea59d182c4a41d84..591c3d6cc335820f0041f84639946ba050029859 100644 --- a/lib/workers/pr/__snapshots__/index.spec.ts.snap +++ b/lib/workers/pr/__snapshots__/index.spec.ts.snap @@ -14,6 +14,20 @@ Array [ ] `; +exports[`workers/pr ensurePr should add and deduplicate additionalReviewers to empty reviewers on new PR 1`] = ` +Array [ + Array [ + undefined, + Array [ + "bar", + "baz", + "boo", + "foo", + ], + ], +] +`; + exports[`workers/pr ensurePr should add assignees and reviewers to new PR 1`] = ` Array [ Array [ diff --git a/lib/workers/pr/index.spec.ts b/lib/workers/pr/index.spec.ts index cd5ec032bfd08ea85b5fcc61ca8376a39dbea363..028d6b3d617a08ed05b07d525ce8241954e482f0 100644 --- a/lib/workers/pr/index.spec.ts +++ b/lib/workers/pr/index.spec.ts @@ -514,6 +514,15 @@ describe('workers/pr', () => { expect(platform.addReviewers).toHaveBeenCalledTimes(1); expect(platform.addReviewers.mock.calls).toMatchSnapshot(); }); + it('should add and deduplicate additionalReviewers to empty reviewers on new PR', async () => { + config.reviewers = []; + config.additionalReviewers = ['bar', 'baz', '@boo', '@foo', 'bar']; + const { prResult, pr } = await prWorker.ensurePr(config); + expect(prResult).toEqual(PrResult.Created); + expect(pr).toMatchObject({ displayNumber: 'New Pull Request' }); + expect(platform.addReviewers).toHaveBeenCalledTimes(1); + expect(platform.addReviewers.mock.calls).toMatchSnapshot(); + }); it('should return unmodified existing PR', async () => { platform.getBranchPr.mockResolvedValueOnce(existingPr); config.semanticCommitScope = null; diff --git a/lib/workers/pr/index.ts b/lib/workers/pr/index.ts index 53b03a1b933e6f093b3cbbd18caac16ec64310f8..5809e76340ddedc0e3d283d2bc1ee5cff21a08ea 100644 --- a/lib/workers/pr/index.ts +++ b/lib/workers/pr/index.ts @@ -70,15 +70,12 @@ export async function addAssigneesReviewers( if (config.reviewersFromCodeOwners) { reviewers = await addCodeOwners(reviewers, pr); } + if (config.additionalReviewers.length > 0) { + reviewers = reviewers.concat(config.additionalReviewers); + } if (reviewers.length > 0) { try { - reviewers = reviewers.map(noLeadingAtSymbol); - if (config.additionalReviewers.length > 0) { - const additionalReviewers = config.additionalReviewers.map( - noLeadingAtSymbol - ); - reviewers = [...new Set(reviewers.concat(additionalReviewers))]; - } + reviewers = [...new Set(reviewers.map(noLeadingAtSymbol))]; if (config.reviewersSampleSize !== null) { reviewers = sampleSize(reviewers, config.reviewersSampleSize); }