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) {
await approvePr(prConfig.number);
await client.approveChange(prConfig.number);
}
if (prConfig.state && prConfig.state === 'closed') {
await client.abandonChange(prConfig.number);
@ -196,7 +196,7 @@ export async function createPr(prConfig: CreatePRConfig): Promise<Pr | null> {
TAG_PULL_REQUEST_BODY,
);
if (prConfig.platformPrOptions?.autoApprove) {
await approvePr(pr._number);
await client.approveChange(pr._number);
}
return getPr(pr._number);
}
@ -443,6 +443,13 @@ export function getIssueList(): Promise<Issue[]> {
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);
}

View file

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

View file

@ -128,12 +128,12 @@ describe('workers/repository/update/pr/automerge', () => {
config.autoApprove = true;
config.automerge = true;
config.pruneBranchAfterAutomerge = true;
platform.approvePr.mockResolvedValueOnce();
platform.approvePrForAutomerge.mockResolvedValueOnce();
platform.getBranchStatus.mockResolvedValueOnce('green');
platform.mergePr.mockResolvedValueOnce(true);
const res = await prAutomerge.checkAutoMerge(pr, config);
expect(res).toEqual({ automerged: true, branchRemoved: true });
expect(platform.approvePr).toHaveBeenCalledTimes(1);
expect(platform.approvePrForAutomerge).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
// 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);
if (config.autoApprove && platform.approvePrForAutomerge) {
logger.debug('Auto-approving PR for automerge');
await platform.approvePrForAutomerge(pr.number);
}
const branchStatus = await resolveBranchStatus(
branchName,