Skip to content

Commit 6f70b71

Browse files
committed
fix(github-actions): add an additional retry on failed attempts to set the merge status (#3011)
Add an additional retry if the branch manager fails to set the mergeability status on a pull request, after a short timeout. PR Close #3011
1 parent 4f0e673 commit 6f70b71

File tree

2 files changed

+55
-31
lines changed

2 files changed

+55
-31
lines changed

.github/local-actions/branch-manager/lib/main.ts

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
import {MergeConflictsFatalError} from '../../../../ng-dev/pr/merge/failures.js';
1313
import {createPullRequestValidationConfig} from '../../../../ng-dev/pr/common/validation/validation-config.js';
1414
import {InvalidTargetLabelError} from '../../../../ng-dev/pr/common/targeting/target-label.js';
15+
import {resolve} from 'path';
1516

1617
interface CommmitStatus {
1718
state: 'pending' | 'error' | 'failure' | 'success';
@@ -50,27 +51,40 @@ const sha = await (async () => {
5051
})();
5152

5253
/** Set the mergability status on the pull request provided in the environment. */
53-
async function setMergeabilityStatusOnPullRequest({state, description, targetUrl}: CommmitStatus) {
54-
await git.github.repos.createCommitStatus({
55-
owner,
56-
repo,
57-
sha,
58-
context: statusContextName,
59-
state,
60-
// Status descriptions are limited to 140 characters.
61-
description: description.substring(0, 139),
62-
target_url: targetUrl,
63-
});
54+
async function setMergeabilityStatusOnPullRequest(
55+
{state, description, targetUrl}: CommmitStatus,
56+
canRetry = true,
57+
) {
58+
try {
59+
await git.github.repos.createCommitStatus({
60+
owner,
61+
repo,
62+
sha,
63+
context: statusContextName,
64+
state,
65+
// Status descriptions are limited to 140 characters.
66+
description: description.substring(0, 139),
67+
target_url: targetUrl,
68+
});
69+
} catch {
70+
if (canRetry) {
71+
await new Promise((resolve) => setTimeout(resolve, 5000));
72+
await setMergeabilityStatusOnPullRequest({state, description, targetUrl}, false);
73+
}
74+
}
6475
}
6576

6677
async function main() {
6778
try {
6879
// This is intentionally not awaited because we are just setting the status to pending, and wanting
6980
// to continue working.
70-
let _unawaitedPromise = setMergeabilityStatusOnPullRequest({
71-
state: 'pending',
72-
description: 'Mergability check in progress',
73-
});
81+
let _unawaitedPromise = setMergeabilityStatusOnPullRequest(
82+
{
83+
state: 'pending',
84+
description: 'Mergability check in progress',
85+
},
86+
false,
87+
);
7488

7589
// Create a tmp directory to perform checks in and change working to directory to it.
7690
await cloneRepoIntoTmpLocation({owner, repo});

.github/local-actions/branch-manager/main.js

Lines changed: 26 additions & 16 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)