feat: abandoned (#18785)

This commit is contained in:
RahulGautamSingh 2022-11-07 02:15:29 +05:30 committed by GitHub
parent 496c7f09b7
commit 4e5f6c5266
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 5 deletions

View file

@ -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(

View file

@ -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',