diff --git a/lib/workers/branch/index.js b/lib/workers/branch/index.js index 1079a085f4cdf9f933b1a3abeac6eb3285270c82..a491e6609860613d234ef23cdc6624f789958686 100644 --- a/lib/workers/branch/index.js +++ b/lib/workers/branch/index.js @@ -40,30 +40,34 @@ async function processBranch(branchConfig) { { prTitle: config.prTitle }, 'Closed PR already exists. Skipping branch.' ); - const subject = 'Renovate Ignore Notification'; - let content; - if (config.isMajor) { - content = `As this PR has been closed unmerged, Renovate will ignore this upgrade and you will not receive PRs for *any* future ${ - config.newVersionMajor - }.x releases. However, if you upgrade to ${ - config.newVersionMajor - }.x manually then Renovate will then reenable updates for minor and patch updates automatically.`; - } else if (config.isDigest) { - content = `As this PR has been closed unmerged, Renovate will ignore this upgrade type and you will not receive PRs for *any* future ${ - config.depName - }:${ - config.currentTag - } digest updates. Digest updates will resume if you update the specified tag at any time.`; - } else { - content = `As this PR has been closed unmerged, Renovate will now ignore this update (${ - config.newVersion - }). You will still receive a PR once a newer version is released, so if you wish to permanently ignore this dependency, please add it to the \`ignoreDeps\` array of your renovate config.`; - } - content += - '\n\nIf this PR was closed by mistake or you changed your mind, you can simply reopen or rename it to reactivate Renovate for this dependency version.'; - await platform.ensureComment(pr.number, subject, content); - if (branchExists) { - await platform.deleteBranch(config.branchName); + if (pr.state === 'closed') { + const subject = 'Renovate Ignore Notification'; + let content; + if (config.isMajor) { + content = `As this PR has been closed unmerged, Renovate will ignore this upgrade and you will not receive PRs for *any* future ${ + config.newVersionMajor + }.x releases. However, if you upgrade to ${ + config.newVersionMajor + }.x manually then Renovate will then reenable updates for minor and patch updates automatically.`; + } else if (config.isDigest) { + content = `As this PR has been closed unmerged, Renovate will ignore this upgrade type and you will not receive PRs for *any* future ${ + config.depName + }:${ + config.currentTag + } digest updates. Digest updates will resume if you update the specified tag at any time.`; + } else { + content = `As this PR has been closed unmerged, Renovate will now ignore this update (${ + config.newVersion + }). You will still receive a PR once a newer version is released, so if you wish to permanently ignore this dependency, please add it to the \`ignoreDeps\` array of your renovate config.`; + } + content += + '\n\nIf this PR was closed by mistake or you changed your mind, you can simply reopen or rename it to reactivate Renovate for this dependency version.'; + await platform.ensureComment(pr.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'); } return 'already-existed'; } diff --git a/test/workers/branch/index.spec.js b/test/workers/branch/index.spec.js index 7b2627f40a83d08c59465ce6d13561ea609b8e86..5a504983455762d77bd42d6e4f36f6f1f076a327 100644 --- a/test/workers/branch/index.spec.js +++ b/test/workers/branch/index.spec.js @@ -63,7 +63,10 @@ describe('workers/branch', () => { schedule.isScheduledNow.mockReturnValueOnce(false); platform.branchExists.mockReturnValueOnce(true); config.isMajor = true; - checkExisting.prAlreadyExisted.mockReturnValueOnce({ number: 13 }); + checkExisting.prAlreadyExisted.mockReturnValueOnce({ + number: 13, + state: 'closed', + }); await branchWorker.processBranch(config); expect(parent.getParentBranch.mock.calls.length).toBe(0); }); @@ -71,14 +74,30 @@ describe('workers/branch', () => { schedule.isScheduledNow.mockReturnValueOnce(false); platform.branchExists.mockReturnValueOnce(true); config.isDigest = true; - checkExisting.prAlreadyExisted.mockReturnValueOnce({ number: 13 }); + checkExisting.prAlreadyExisted.mockReturnValueOnce({ + number: 13, + state: 'closed', + }); await branchWorker.processBranch(config); expect(parent.getParentBranch.mock.calls.length).toBe(0); }); it('skips branch if closed minor PR found', async () => { schedule.isScheduledNow.mockReturnValueOnce(false); platform.branchExists.mockReturnValueOnce(true); - checkExisting.prAlreadyExisted.mockReturnValueOnce({ number: 13 }); + checkExisting.prAlreadyExisted.mockReturnValueOnce({ + number: 13, + state: 'closed', + }); + await branchWorker.processBranch(config); + expect(parent.getParentBranch.mock.calls.length).toBe(0); + }); + it('skips branch if merged PR found', async () => { + schedule.isScheduledNow.mockReturnValueOnce(false); + platform.branchExists.mockReturnValueOnce(true); + checkExisting.prAlreadyExisted.mockReturnValueOnce({ + number: 13, + state: 'merged', + }); await branchWorker.processBranch(config); expect(parent.getParentBranch.mock.calls.length).toBe(0); });