Skip to content

Commit

Permalink
fix: always add additionalReviewers to PR (#8550)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamko147 committed Feb 5, 2021
1 parent 9f9a6dc commit 60174c4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
14 changes: 14 additions & 0 deletions lib/workers/pr/__snapshots__/index.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down
9 changes: 9 additions & 0 deletions lib/workers/pr/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 4 additions & 7 deletions lib/workers/pr/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 60174c4

Please sign in to comment.