mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-14 08:36:26 +00:00
fix(github): try automerge PR even if approving reviews required (#21883)
This commit is contained in:
parent
ab04c11f42
commit
91cbe5bdcc
2 changed files with 32 additions and 31 deletions
|
@ -2839,6 +2839,28 @@ describe('modules/platform/github/index', () => {
|
|||
})
|
||||
).toBeFalse();
|
||||
});
|
||||
|
||||
it('should handle approvers required', async () => {
|
||||
const scope = httpMock.scope(githubApiHost);
|
||||
initRepoMock(scope, 'some/repo');
|
||||
scope.put('/repos/some/repo/pulls/1234/merge').reply(405, {
|
||||
message:
|
||||
'At least 1 approving review is required by reviewers with write access.',
|
||||
});
|
||||
await github.initRepo({ repository: 'some/repo' });
|
||||
const pr = {
|
||||
number: 1234,
|
||||
head: {
|
||||
ref: 'someref',
|
||||
},
|
||||
};
|
||||
expect(
|
||||
await github.mergePr({
|
||||
branchName: '',
|
||||
id: pr.number,
|
||||
})
|
||||
).toBeFalse();
|
||||
});
|
||||
});
|
||||
|
||||
describe('massageMarkdown(input)', () => {
|
||||
|
|
|
@ -593,15 +593,6 @@ export async function getRepoForceRebase(): Promise<boolean> {
|
|||
config.repoForceRebase = false;
|
||||
const branchProtection = await getBranchProtection(config.defaultBranch);
|
||||
logger.debug('Found branch protection');
|
||||
if (
|
||||
branchProtection.required_pull_request_reviews
|
||||
?.required_approving_review_count > 0
|
||||
) {
|
||||
logger.debug(
|
||||
'Branch protection: PR Reviews are required before merging'
|
||||
);
|
||||
config.prReviewsRequired = true;
|
||||
}
|
||||
if (branchProtection.required_status_checks) {
|
||||
if (branchProtection.required_status_checks.strict) {
|
||||
logger.debug(
|
||||
|
@ -1606,28 +1597,6 @@ export async function mergePr({
|
|||
id: prNo,
|
||||
}: MergePRConfig): Promise<boolean> {
|
||||
logger.debug(`mergePr(${prNo}, ${branchName})`);
|
||||
// istanbul ignore if
|
||||
if (config.prReviewsRequired) {
|
||||
logger.debug(
|
||||
{ branch: branchName, prNo },
|
||||
'Branch protection: Attempting to merge PR when PR reviews are enabled'
|
||||
);
|
||||
const repository = config.parentRepo ?? config.repository;
|
||||
const reviews = await githubApi.getJson<{ state: string }[]>(
|
||||
`repos/${repository}/pulls/${prNo}/reviews`
|
||||
);
|
||||
const isApproved = reviews.body.some(
|
||||
(review) => review.state === 'APPROVED'
|
||||
);
|
||||
if (!isApproved) {
|
||||
logger.debug(
|
||||
{ branch: branchName, prNo },
|
||||
'Branch protection: Cannot automerge PR until there is an approving review'
|
||||
);
|
||||
return false;
|
||||
}
|
||||
logger.debug('Found approving reviews');
|
||||
}
|
||||
const url = `repos/${
|
||||
config.parentRepo ?? config.repository
|
||||
}/pulls/${prNo}/merge`;
|
||||
|
@ -1660,6 +1629,16 @@ export async function mergePr({
|
|||
);
|
||||
return false;
|
||||
}
|
||||
if (
|
||||
is.nonEmptyString(body?.message) &&
|
||||
body.message.includes('approving review')
|
||||
) {
|
||||
logger.debug(
|
||||
{ response: body },
|
||||
`GitHub blocking PR merge -- Needs approving review(s)`
|
||||
);
|
||||
return false;
|
||||
}
|
||||
logger.debug(
|
||||
{ response: body },
|
||||
'GitHub blocking PR merge -- will keep trying'
|
||||
|
|
Loading…
Reference in a new issue