diff --git a/lib/workers/pr/index.js b/lib/workers/pr/index.js index 3a39a7820026eb433241ba60600a913eb6d9b033..8bfdd4d85f4a0d280142687d1358a82a7fec6496 100644 --- a/lib/workers/pr/index.js +++ b/lib/workers/pr/index.js @@ -17,6 +17,8 @@ async function ensurePr(prConfig) { logger.trace({ config }, 'ensurePr'); // If there is a group, it will use the config of the first upgrade in the array const { branchName, upgrades } = config; + // Check if existing PR exists + const existingPr = await platform.getBranchPr(branchName); config.upgrades = []; const branchStatus = await platform.getBranchStatus( branchName, @@ -41,7 +43,7 @@ async function ensurePr(prConfig) { return null; } logger.debug('Branch status success'); - } else if (config.prCreation === 'not-pending') { + } else if (config.prCreation === 'not-pending' && !existingPr) { logger.debug('Checking branch combined status'); if (branchStatus === 'pending' || branchStatus === 'running') { logger.debug(`Branch status is "${branchStatus}" - checking timeout`); @@ -157,8 +159,6 @@ async function ensurePr(prConfig) { } try { - // Check if existing PR exists - const existingPr = await platform.getBranchPr(branchName); if (existingPr) { if (config.automerge && branchStatus === 'failure') { logger.debug(`Setting assignees and reviewers as status checks failed`); diff --git a/test/workers/pr/index.spec.js b/test/workers/pr/index.spec.js index 50d8ffb8fba291e76710054768030c018f070a2c..231a56e37cfd111a2e1ea9117adcb281b3e329fa 100644 --- a/test/workers/pr/index.spec.js +++ b/test/workers/pr/index.spec.js @@ -107,9 +107,11 @@ describe('workers/pr', () => { jest.clearAllMocks(); }); it('should return null if check fails', async () => { - platform.getBranchPr.mockImplementationOnce(() => { + platform.updatePr.mockImplementationOnce(() => { throw new Error('oops'); }); + config.newVersion = '1.2.0'; + platform.getBranchPr.mockReturnValueOnce(existingPr); const pr = await prWorker.ensurePr(config); expect(pr).toBe(null); });