From 6ac7b9e0896ace6ec29b846f26f882f5e46d172d Mon Sep 17 00:00:00 2001 From: Felipe Santos Date: Sat, 30 Nov 2024 04:04:20 -0300 Subject: [PATCH] chore(gerrit): try auto-approve right before auto-merge --- lib/modules/platform/gerrit/index.ts | 4 ++++ lib/modules/platform/types.ts | 1 + lib/workers/repository/update/pr/automerge.ts | 6 ++++++ 3 files changed, 11 insertions(+) diff --git a/lib/modules/platform/gerrit/index.ts b/lib/modules/platform/gerrit/index.ts index d4f5b3c8123780..43133bd9250304 100644 --- a/lib/modules/platform/gerrit/index.ts +++ b/lib/modules/platform/gerrit/index.ts @@ -436,3 +436,7 @@ export function findIssue(title: string): Promise { export function getIssueList(): Promise { return Promise.resolve([]); } + +export async function approvePr(number: number): Promise { + await client.approveChange(number); +} diff --git a/lib/modules/platform/types.ts b/lib/modules/platform/types.ts index cc770c1d8e43ee..67e95722462fa4 100644 --- a/lib/modules/platform/types.ts +++ b/lib/modules/platform/types.ts @@ -282,6 +282,7 @@ export interface Platform { maxBodyLength(): number; labelCharLimit?(): number; + approvePr?(number: number): Promise; } export interface PlatformScm { diff --git a/lib/workers/repository/update/pr/automerge.ts b/lib/workers/repository/update/pr/automerge.ts index 2ace410741b3b8..4bbe2aaab1d53e 100644 --- a/lib/workers/repository/update/pr/automerge.ts +++ b/lib/workers/repository/update/pr/automerge.ts @@ -69,6 +69,12 @@ export async function checkAutoMerge( prAutomergeBlockReason: 'PlatformNotReady', }; } + // Usually the PR will already be approved, this is a last resort in case the + // approval was lost for some reason + if (config.autoApprove && platform.approvePr) { + logger.debug('Auto-approving PR if needed before automerge'); + await platform.approvePr(pr.number); + } const branchStatus = await resolveBranchStatus( branchName, !!config.internalChecksAsSuccess,