From 4e5f6c52664e2cb5484e3c7e3c69cd82c6cc955c Mon Sep 17 00:00:00 2001 From: RahulGautamSingh Date: Mon, 7 Nov 2022 02:15:29 +0530 Subject: [PATCH] feat: abandoned (#18785) --- lib/workers/repository/finalise/prune.spec.ts | 24 +++++++++++++++---- lib/workers/repository/finalise/prune.ts | 11 ++++++++- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/lib/workers/repository/finalise/prune.spec.ts b/lib/workers/repository/finalise/prune.spec.ts index 1e00542a30..70889c7594 100644 --- a/lib/workers/repository/finalise/prune.spec.ts +++ b/lib/workers/repository/finalise/prune.spec.ts @@ -99,22 +99,38 @@ describe('workers/repository/finalise/prune', () => { expect(platform.updatePr).toHaveBeenCalledTimes(0); }); - it('posts comment if someone pushed to PR', async () => { + it('notifies via PR changes if someone pushed to PR', async () => { config.branchList = ['renovate/a', 'renovate/b']; git.getBranchList.mockReturnValueOnce( config.branchList.concat(['renovate/c']) ); platform.getBranchPr.mockResolvedValueOnce({} as never); git.isBranchModified.mockResolvedValueOnce(true); - platform.findPr.mockResolvedValueOnce({ title: 'foo' } as never); + platform.findPr.mockResolvedValueOnce({ + title: 'foo', + } as never); await cleanup.pruneStaleBranches(config, config.branchList); expect(git.getBranchList).toHaveBeenCalledTimes(1); expect(git.deleteBranch).toHaveBeenCalledTimes(0); - expect(platform.updatePr).toHaveBeenCalledTimes(0); + expect(platform.updatePr).toHaveBeenCalledTimes(1); expect(platform.ensureComment).toHaveBeenCalledTimes(1); }); - it('skips comment if dry run', async () => { + it('skips appending - abandoned to PR title if already present', async () => { + config.branchList = ['renovate/a', 'renovate/b']; + git.getBranchList.mockReturnValueOnce( + config.branchList.concat(['renovate/c']) + ); + platform.getBranchPr.mockResolvedValueOnce({} as never); + git.isBranchModified.mockResolvedValueOnce(true); + platform.findPr.mockResolvedValueOnce({ + title: 'foo - abandoned', + } as never); + await cleanup.pruneStaleBranches(config, config.branchList); + expect(platform.updatePr).toHaveBeenCalledTimes(0); + }); + + it('skips changes to PR if dry run', async () => { config.branchList = ['renovate/a', 'renovate/b']; GlobalConfig.set({ dryRun: 'full' }); git.getBranchList.mockReturnValueOnce( diff --git a/lib/workers/repository/finalise/prune.ts b/lib/workers/repository/finalise/prune.ts index 9f8208b1cd..18b895d482 100644 --- a/lib/workers/repository/finalise/prune.ts +++ b/lib/workers/repository/finalise/prune.ts @@ -33,8 +33,17 @@ async function cleanUpBranches( 'Branch is modified - skipping PR autoclosing' ); if (GlobalConfig.get('dryRun')) { - logger.info(`DRY-RUN: Would add Autoclosing Skipped comment to PR`); + logger.info(`DRY-RUN: Would update PR title and ensure comment.`); } else { + if (!pr.title.endsWith('- abandoned')) { + const newPrTitle = pr.title + ' - abandoned'; + await platform.updatePr({ + number: pr.number, + prTitle: newPrTitle, + state: PrState.Open, + }); + } + await ensureComment({ number: pr.number, topic: 'Autoclosing Skipped',