Skip to content

Commit 119b116

Browse files
committed
retry if github error is 422
1 parent 4424aed commit 119b116

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

homu/utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import time
99

1010

11-
def github_set_ref(repo, ref, sha, *, force=False, auto_create=True):
11+
def github_set_ref(repo, ref, sha, *, force=False, auto_create=True, retry=1):
1212
url = repo._build_url('git', 'refs', ref, base_url=repo._api)
1313
data = {'sha': sha, 'force': force}
1414

@@ -20,6 +20,9 @@ def github_set_ref(repo, ref, sha, *, force=False, auto_create=True):
2020
return repo.create_ref('refs/' + ref, sha)
2121
except github3.models.GitHubError:
2222
raise e
23+
elif e.code == 422 and retry > 0:
24+
time.sleep(5)
25+
return github_set_ref(repo, ref, sha, force=force, auto_create=auto_create, retry=retry - 1)
2326
else:
2427
raise
2528

0 commit comments

Comments
 (0)