diff --git a/lib/modules/platform/gerrit/index.ts b/lib/modules/platform/gerrit/index.ts index d4f5b3c8123780c..43133bd9250304a 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 cc770c1d8e43ee8..67e95722462fa4d 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 2ace410741b3b8f..4bbe2aaab1d53ee 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,