Skip to content

Commit

Permalink
add retry for the mergeability computation
Browse files Browse the repository at this point in the history
Signed-off-by: TomeHirata <tomu.hirata@gmail.com>
  • Loading branch information
TomeHirata committed Nov 1, 2023
1 parent 9ca5fc6 commit eccd76c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
27 changes: 17 additions & 10 deletions .github/workflows/auto-merge.js
Expand Up @@ -4,6 +4,8 @@ module.exports = async ({ github, context }) => {
} = context;

const MERGE_INTERVAL_MS = 5000; // 5 seconds pause after a merge
const MAX_RETRIES = 3;
const RETRY_INTERVAL_MS = 10000; // 10 seconds

async function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
Expand All @@ -18,16 +20,21 @@ module.exports = async ({ github, context }) => {
}

async function fetchPullRequestDetails(prNumber) {
const pullRequest = await github.rest.pulls
.get({
owner,
repo,
pull_number: prNumber,
})
.then((res) => res.data);

if (pullRequest.mergeable !== null) {
return pullRequest;
for (let i = 0; i < MAX_RETRIES; i++) {
const pullRequest = await github.rest.pulls
.get({
owner,
repo,
pull_number: prNumber,
})
.then((res) => res.data);

if (pullRequest.mergeable !== null) {
return pullRequest;
}

console.log(`Waiting for mergeability calculation for PR #${prNumber}...`);
await sleep(RETRY_INTERVAL_MS);
}
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/remove-automerge-label.yml
Expand Up @@ -8,7 +8,7 @@ on:
jobs:
remove-label:
runs-on: ubuntu-latest
if: ${{ !contains(fromJSON('["OWNER", "COLLABORATOR"]'), github.event.pull_request.author_association )}}
if: ${{ !contains(fromJSON('["OWNER", "COLLABORATOR", "MEMBER"]'), github.event.pull_request.author_association )}}
steps:
- uses: actions/checkout@v4
- name: Remove automerge label
Expand Down

0 comments on commit eccd76c

Please sign in to comment.