diff --git a/lib/workers/pr.js b/lib/workers/pr.js index c99c1ea3d96b4ff4a2badb0dd983c7ef5d3df4e6..8432e1263de1f8ae33f305d1aa4e6f332dd4b902 100644 --- a/lib/workers/pr.js +++ b/lib/workers/pr.js @@ -57,11 +57,17 @@ async function ensurePr(upgradeConfig) { if (config.labels.length > 0) { await config.api.addLabels(pr.number, config.labels); } - if (config.assignees.length > 0) { - await config.api.addAssignees(pr.number, config.assignees); - } - if (config.reviewers.length > 0) { - await config.api.addReviewers(pr.number, config.reviewers); + // Don't assign or review if automerging + if (config.automerge === 'none' || + (config.automerge === 'minor' && config.upgradeType !== 'minor')) { + if (config.assignees.length > 0) { + await config.api.addAssignees(pr.number, config.assignees); + } + if (config.reviewers.length > 0) { + await config.api.addReviewers(pr.number, config.reviewers); + } + } else { + logger.debug(`Skipping assignees and reviewers as automerge=${config.automerge}`); } logger.info(`Created ${pr.displayNumber}`); return pr; diff --git a/test/workers/pr.spec.js b/test/workers/pr.spec.js index 3411fa864d8cc22b91165c5f11e0a885142cc1ce..ee785202ad07a3414b9d8949dd541a78025f8c81 100644 --- a/test/workers/pr.spec.js +++ b/test/workers/pr.spec.js @@ -149,6 +149,44 @@ describe('workers/pr', () => { expect(config.api.addAssignees.mock.calls.length).toBe(1); expect(config.api.addReviewers.mock.calls.length).toBe(1); }); + it('should not add assignees and reviewers to new PR if automerging any', async () => { + config.api.getBranchPr = jest.fn(); + config.api.addAssignees = jest.fn(); + config.api.addReviewers = jest.fn(); + config.assignees = ['bar']; + config.reviewers = ['baz']; + config.automerge = 'any'; + const pr = await prWorker.ensurePr(config); + expect(pr).toMatchObject({ displayNumber: 'New Pull Request' }); + expect(config.api.addAssignees.mock.calls.length).toBe(0); + expect(config.api.addReviewers.mock.calls.length).toBe(0); + }); + it('should not add assignees and reviewers to new PR if automerging minor', async () => { + config.api.getBranchPr = jest.fn(); + config.api.addAssignees = jest.fn(); + config.api.addReviewers = jest.fn(); + config.assignees = ['bar']; + config.reviewers = ['baz']; + config.upgradeType = 'minor'; + config.automerge = 'minor'; + const pr = await prWorker.ensurePr(config); + expect(pr).toMatchObject({ displayNumber: 'New Pull Request' }); + expect(config.api.addAssignees.mock.calls.length).toBe(0); + expect(config.api.addReviewers.mock.calls.length).toBe(0); + }); + it('should add assignees and reviewers to new PR if automerging minor and its major', async () => { + config.api.getBranchPr = jest.fn(); + config.api.addAssignees = jest.fn(); + config.api.addReviewers = jest.fn(); + config.assignees = ['bar']; + config.reviewers = ['baz']; + config.upgradeType = 'major'; + config.automerge = 'minor'; + const pr = await prWorker.ensurePr(config); + expect(pr).toMatchObject({ displayNumber: 'New Pull Request' }); + expect(config.api.addAssignees.mock.calls.length).toBe(1); + expect(config.api.addReviewers.mock.calls.length).toBe(1); + }); it('should return unmodified existing PR', async () => { config.depName = 'dummy'; config.currentVersion = '1.0.0';