Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow previously merged PRs, but block automerge #22279

Merged
merged 2 commits into from May 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
secustor marked this conversation as resolved.
Show resolved Hide resolved
}
}
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