diff --git a/lib/workers/branch/index.js b/lib/workers/branch/index.js index 8c8fd159f051ee0de0691e67d8be6f8db72a7216..c8873b0b4a3aaf422d3ceb8afe060cc42322103f 100644 --- a/lib/workers/branch/index.js +++ b/lib/workers/branch/index.js @@ -41,13 +41,13 @@ async function processBranch(branchConfig, packageFiles) { ); // Check if branch already existed - let pr = await prAlreadyExisted(config); - if (pr) { + const existingPr = await prAlreadyExisted(config); + if (existingPr) { logger.info( { prTitle: config.prTitle }, 'Closed PR already exists. Skipping branch.' ); - if (pr.state === 'closed') { + if (existingPr.state === 'closed') { const subject = 'Renovate Ignore Notification'; let content; if (config.type === 'major') { @@ -69,38 +69,33 @@ async function processBranch(branchConfig, packageFiles) { } content += '\n\nIf this PR was closed by mistake or you changed your mind, you can simply rename this PR and you will soon get a fresh replacement PR opened.'; - await platform.ensureComment(pr.number, subject, content); + await platform.ensureComment(existingPr.number, subject, content); if (branchExists) { await platform.deleteBranch(config.branchName); } - } else if (pr.state === 'merged') { - logger.info({ pr: pr.number }, 'Merged PR is blocking this branch'); + } else if (existingPr.state === 'merged') { + logger.info( + { pr: existingPr.number }, + 'Merged PR is blocking this branch' + ); } return 'already-existed'; } if (branchExists) { logger.debug('Checking if PR has been edited'); - pr = await platform.findPr(config.branchName, config.prTitle, 'open'); - } - if (pr) { - logger.debug({ pr }, 'Found existing PR'); - pr = await platform.getPr(pr.number); - if (pr.state.startsWith('open')) { - logger.debug('Existing PR is open'); - if (!pr.canRebase) { + const branchPr = await platform.getBranchPr(config.branchName); + if (branchPr) { + logger.debug({ branchPr }, 'Found existing PR'); + if (!branchPr.canRebase) { const subject = 'PR has been edited'; logger.info(subject); let content = 'As this PR has been edited, Renovate will stop updating it in order to not cause any conflicts or other problems.'; content += ' If you wish to abandon your edits and have Renovate recreate this PR then you should rename this PR and then close it.'; - await platform.ensureComment(pr.number, subject, content); + await platform.ensureComment(branchPr.number, subject, content); return 'pr-edited'; } - } else { - logger.info('PR state is not open - aborting'); - logger.debug({ pr }); - return 'pr-closed'; } } diff --git a/test/workers/branch/index.spec.js b/test/workers/branch/index.spec.js index 4faa49b1d71e0a8086b3037198cc33b1414e905f..cb2b176e0eeb9d6d63b4dc11bbee06ebb1077dc2 100644 --- a/test/workers/branch/index.spec.js +++ b/test/workers/branch/index.spec.js @@ -112,19 +112,13 @@ describe('workers/branch', () => { it('skips branch if edited PR found', async () => { schedule.isScheduledNow.mockReturnValueOnce(false); platform.branchExists.mockReturnValueOnce(true); - platform.findPr.mockReturnValueOnce({}); - platform.getPr.mockReturnValueOnce({ state: 'open', canRebase: false }); + platform.getBranchPr.mockReturnValueOnce({ + state: 'open', + canRebase: false, + }); const res = await branchWorker.processBranch(config); expect(res).toEqual('pr-edited'); }); - it('warns if edited PR is actually closed', async () => { - schedule.isScheduledNow.mockReturnValueOnce(false); - platform.branchExists.mockReturnValueOnce(true); - platform.findPr.mockReturnValueOnce({}); - platform.getPr.mockReturnValueOnce({ state: 'closed' }); - const res = await branchWorker.processBranch(config); - expect(res).not.toEqual('pr-edited'); - }); it('returns if pr creation limit exceeded', async () => { getUpdated.getUpdatedPackageFiles.mockReturnValueOnce({ updatedPackageFiles: [],