Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feat: allow previously merged PRs, but block automerge (#22279)
  • Loading branch information
rarkins committed May 17, 2023
1 parent 98d9851 commit b5d74a8
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 2 deletions.
15 changes: 15 additions & 0 deletions lib/workers/repository/update/branch/index.spec.ts
Expand Up @@ -289,6 +289,21 @@ describe('workers/repository/update/branch/index', () => {
expect(scm.deleteBranch).toHaveBeenCalledTimes(1);
});

it('allows branch but disables automerge if merged PR found', async () => {
schedule.isScheduledNow.mockReturnValueOnce(false);
scm.branchExists.mockResolvedValue(true);
config.automerge = true;
config.updateType = 'digest';
checkExisting.prAlreadyExisted.mockResolvedValueOnce(
partial<Pr>({
number: 13,
state: 'merged',
})
);
await branchWorker.processBranch(config);
expect(reuse.shouldReuseExistingBranch).toHaveBeenCalledTimes(0);
});

it('skips branch if closed minor PR found', async () => {
schedule.isScheduledNow.mockReturnValueOnce(false);
scm.branchExists.mockResolvedValue(true);
Expand Down
15 changes: 13 additions & 2 deletions lib/workers/repository/update/branch/index.ts
Expand Up @@ -113,8 +113,19 @@ export async function processBranch(
const artifactErrorTopic = emojify(':warning: Artifact update problem');
try {
// Check if branch already existed
const existingPr = branchPr ? undefined : await prAlreadyExisted(config);
if (existingPr && !dependencyDashboardCheck) {
const existingPr =
!branchPr || config.automerge
? await prAlreadyExisted(config)
: undefined;
if (existingPr?.state === 'merged') {
logger.debug(`Matching PR #${existingPr.number} was merged previously`);
if (config.automerge) {
logger.debug('Disabling automerge because PR was merged previously');
config.automerge = false;
config.automergedPreviously = true;
}
}
if (!branchPr && existingPr && !dependencyDashboardCheck) {
logger.debug(
{ prTitle: config.prTitle },
'Closed PR already exists. Skipping branch.'
Expand Down
10 changes: 10 additions & 0 deletions lib/workers/repository/update/pr/body/config-description.spec.ts
Expand Up @@ -87,5 +87,15 @@ describe('workers/repository/update/pr/body/config-description', () => {
const res = getPrConfigDescription({ ...config, automerge: true });
expect(res).toContain(`**Automerge**: Enabled.`);
});

it('renders blocked automerge', () => {
const res = getPrConfigDescription({
...config,
automergedPreviously: true,
});
expect(res).toContain(
`**Automerge**: Disabled because a matching PR was automerged previously.`
);
});
});
});
2 changes: 2 additions & 0 deletions lib/workers/repository/update/pr/body/config-description.ts
Expand Up @@ -15,6 +15,8 @@ export function getPrConfigDescription(config: BranchConfig): string {
prBody += emojify(':vertical_traffic_light: **Automerge**: ');
if (config.automerge) {
prBody += 'Enabled.';
} else if (config.automergedPreviously) {
prBody += 'Disabled because a matching PR was automerged previously.';
} else {
prBody +=
'Disabled by config. Please merge this manually once you are satisfied.';
Expand Down
1 change: 1 addition & 0 deletions lib/workers/types.ts
Expand Up @@ -111,6 +111,7 @@ export interface BranchConfig
PlatformPrOptions {
automergeComment?: string;
automergeType?: string;
automergedPreviously?: boolean;
baseBranch: string;
errors?: ValidationMessage[];
hasTypes?: boolean;
Expand Down

0 comments on commit b5d74a8

Please sign in to comment.