Skip to content

Commit 1fabadb

Browse files
committed
sync-gitster-git: handle 502 gracefully
There are a lot of branches in `gitster/git`. A _lot_. So let's be nice to GitHub and back off (but do try again) if encountering a 502 (which indicates that GitHub is as overloaded as the rest of us). Signed-off-by: Johannes Schindelin <[email protected]>
1 parent f69d3e6 commit 1fabadb

File tree

1 file changed

+29
-12
lines changed

1 file changed

+29
-12
lines changed

.github/workflows/sync-gitster-git.yml

+29-12
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,36 @@ jobs:
1818
id: check
1919
with:
2020
script: |
21+
const sleep = async (milliseconds) => {
22+
return new Promise(resolve => setTimeout(resolve, milliseconds))
23+
}
24+
2125
const getRefs = async (repository) => {
22-
const [owner, repo] = repository.split('/')
23-
const { data } = await github.rest.git.listMatchingRefs({
24-
owner,
25-
repo,
26-
// We want to match `maint-*` as well as `[a-z][a-z]/*`
27-
// sadly, this is not possible via GitHub's REST API,
28-
// hence we do it below via the `filter()` call.
29-
ref: 'heads/'
30-
})
31-
return data
32-
.filter(e => e.ref.match(/^refs\/heads\/(maint-\d|[a-z][a-z]\/)/))
33-
.sort((a, b) => a.ref.localeCompare(b.ref))
26+
let attemptCounter = 1
27+
for (;;) {
28+
try {
29+
const [owner, repo] = repository.split('/')
30+
const { data } = await github.rest.git.listMatchingRefs({
31+
owner,
32+
repo,
33+
// We want to match `maint-*` as well as `[a-z][a-z]/*`
34+
// sadly, this is not possible via GitHub's REST API,
35+
// hence we do it below via the `filter()` call.
36+
ref: 'heads/'
37+
})
38+
return data
39+
.filter(e => e.ref.match(/^refs\/heads\/(maint-\d|[a-z][a-z]\/)/))
40+
.sort((a, b) => a.ref.localeCompare(b.ref))
41+
} catch (e) {
42+
if (e?.status !== 502) throw e
43+
}
44+
45+
if (++attemptCounter > 10) throw new Error('Giving up listing refs after 10 attempts')
46+
47+
const seconds = attemptCounter * attemptCounter + 15 * Math.random()
48+
core.info(`Encountered a Server Error; retrying in ${seconds} seconds`)
49+
await sleep(1000 * seconds)
50+
}
3451
}
3552
3653
const sourceRefs = await getRefs(process.env.SOURCE_REPOSITORY)

0 commit comments

Comments
 (0)