From 8d516e34916d5f5169b603994bd2e9ff37e040cf Mon Sep 17 00:00:00 2001 From: Rhys Arkins <rhys@keylocation.sg> Date: Fri, 21 Apr 2017 07:23:36 +0200 Subject: [PATCH] Feature: Don't assign/review automerge PRs (#180) * Skip assignees and reviewers if automerging * Add tests --- lib/workers/pr.js | 16 +++++++++++----- test/workers/pr.spec.js | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 5 deletions(-) diff --git a/lib/workers/pr.js b/lib/workers/pr.js index c99c1ea3d9..8432e1263d 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 3411fa864d..ee785202ad 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'; -- GitLab