Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(platform/github): don't retry merge when blocked by required status check #21063

Merged
merged 3 commits into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions lib/modules/platform/github/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2815,6 +2815,27 @@ describe('modules/platform/github/index', () => {
})
).toBeFalse();
});

it('should handle merge block', async () => {
const scope = httpMock.scope(githubApiHost);
initRepoMock(scope, 'some/repo');
scope
.put('/repos/some/repo/pulls/1234/merge')
.reply(405, { message: 'Required status check "build" is expected.' });
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)', () => {
Expand Down
24 changes: 18 additions & 6 deletions lib/modules/platform/github/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import type {
} from '../../../util/git/types';
import * as hostRules from '../../../util/host-rules';
import * as githubHttp from '../../../util/http/github';
import type { GithubHttpOptions } from '../../../util/http/github';
import type { HttpResponse } from '../../../util/http/types';
import { regEx } from '../../../util/regex';
import { sanitize } from '../../../util/sanitize';
import { fromBase64, looseEquals } from '../../../util/string';
Expand Down Expand Up @@ -1605,15 +1607,15 @@ export async function mergePr({
const url = `repos/${
config.parentRepo ?? config.repository
}/pulls/${prNo}/merge`;
const options: any = {
body: {} as { merge_method?: string },
const options: GithubHttpOptions = {
body: {},
};
// istanbul ignore if
if (config.forkToken) {
options.token = config.forkToken;
}
let automerged = false;
let automergeResult: any;
let automergeResult: HttpResponse<unknown>;
if (config.mergeMethod) {
// This path is taken if we have auto-detected the allowed merge types from the repo
options.body.merge_method = config.mergeMethod;
Expand All @@ -1623,9 +1625,19 @@ export async function mergePr({
automerged = true;
} catch (err) {
if (err.statusCode === 404 || err.statusCode === 405) {
// istanbul ignore next
const body = err.response?.body;
if (
is.nonEmptyString(body?.message) &&
regEx(/^Required status check ".+" is expected\.$/).test(body.message)
) {
logger.debug(
{ response: body },
`GitHub blocking PR merge -- Missing required status check(s)`
);
return false;
}
logger.debug(
{ response: err.response ? err.response.body : undefined },
{ response: body },
'GitHub blocking PR merge -- will keep trying'
);
} else {
Expand Down Expand Up @@ -1661,7 +1673,7 @@ export async function mergePr({
}
}
logger.debug(
{ automergeResult: automergeResult.body, pr: prNo },
{ automergeResult: automergeResult!.body, pr: prNo },
secustor marked this conversation as resolved.
Show resolved Hide resolved
'PR merged'
);
const cachedPr = config.prList?.find(({ number }) => number === prNo);
Expand Down