chore: rename approvePr to approvePrForAutomerge

This commit is contained in:
Felipe Santos 2024-12-02 17:18:17 +00:00
parent 7923d5b955
commit c4c81e30fc
4 changed files with 18 additions and 11 deletions

View file

@ -161,7 +161,7 @@ export async function updatePr(prConfig: UpdatePrConfig): Promise<void> {
); );
} }
if (prConfig.platformPrOptions?.autoApprove) { if (prConfig.platformPrOptions?.autoApprove) {
await approvePr(prConfig.number); await client.approveChange(prConfig.number);
} }
if (prConfig.state && prConfig.state === 'closed') { if (prConfig.state && prConfig.state === 'closed') {
await client.abandonChange(prConfig.number); await client.abandonChange(prConfig.number);
@ -196,7 +196,7 @@ export async function createPr(prConfig: CreatePRConfig): Promise<Pr | null> {
TAG_PULL_REQUEST_BODY, TAG_PULL_REQUEST_BODY,
); );
if (prConfig.platformPrOptions?.autoApprove) { if (prConfig.platformPrOptions?.autoApprove) {
await approvePr(pr._number); await client.approveChange(pr._number);
} }
return getPr(pr._number); return getPr(pr._number);
} }
@ -443,6 +443,13 @@ export function getIssueList(): Promise<Issue[]> {
return Promise.resolve([]); return Promise.resolve([]);
} }
export async function approvePr(number: number): Promise<void> { /**
* The Code-Review +2 posted when the change was created or updated in Gerrit
* may have been downgraded by a CI check utilizing the same account as
* Renovate (e.g. SonarQube which posts Code-Review +1). This function will
* post a +2 again on the change, if needed, before Renovate attempt to
* automerge it.
*/
export async function approvePrForAutomerge(number: number): Promise<void> {
await client.approveChange(number); await client.approveChange(number);
} }

View file

@ -283,10 +283,10 @@ export interface Platform {
maxBodyLength(): number; maxBodyLength(): number;
labelCharLimit?(): number; labelCharLimit?(): number;
/** /**
* For platforms that support `autoApprove`. It should handle when the PR * Platforms that support `autoApprove` can implement this function. It will be
* is already be approved. * invoked during automerge before the PR branch status is checked.
*/ */
approvePr?(number: number): Promise<void>; approvePrForAutomerge?(number: number): Promise<void>;
} }
export interface PlatformScm { export interface PlatformScm {

View file

@ -128,12 +128,12 @@ describe('workers/repository/update/pr/automerge', () => {
config.autoApprove = true; config.autoApprove = true;
config.automerge = true; config.automerge = true;
config.pruneBranchAfterAutomerge = true; config.pruneBranchAfterAutomerge = true;
platform.approvePr.mockResolvedValueOnce(); platform.approvePrForAutomerge.mockResolvedValueOnce();
platform.getBranchStatus.mockResolvedValueOnce('green'); platform.getBranchStatus.mockResolvedValueOnce('green');
platform.mergePr.mockResolvedValueOnce(true); platform.mergePr.mockResolvedValueOnce(true);
const res = await prAutomerge.checkAutoMerge(pr, config); const res = await prAutomerge.checkAutoMerge(pr, config);
expect(res).toEqual({ automerged: true, branchRemoved: true }); expect(res).toEqual({ automerged: true, branchRemoved: true });
expect(platform.approvePr).toHaveBeenCalledTimes(1); expect(platform.approvePrForAutomerge).toHaveBeenCalledTimes(1);
expect(platform.mergePr).toHaveBeenCalledTimes(1); expect(platform.mergePr).toHaveBeenCalledTimes(1);
}); });

View file

@ -71,9 +71,9 @@ export async function checkAutoMerge(
} }
// Usually the PR will already be approved, this is a last resort in case the // Usually the PR will already be approved, this is a last resort in case the
// approval was lost for some reason // approval was lost for some reason
if (config.autoApprove && platform.approvePr) { if (config.autoApprove && platform.approvePrForAutomerge) {
logger.debug('Auto-approving PR if needed before automerge'); logger.debug('Auto-approving PR for automerge');
await platform.approvePr(pr.number); await platform.approvePrForAutomerge(pr.number);
} }
const branchStatus = await resolveBranchStatus( const branchStatus = await resolveBranchStatus(
branchName, branchName,