From 119b1163641c4c9e7be0b738d0c80784457fbee4 Mon Sep 17 00:00:00 2001 From: Eh2406 Date: Fri, 29 Sep 2017 15:08:09 -0400 Subject: [PATCH 1/2] retry if github error is 422 --- homu/utils.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/homu/utils.py b/homu/utils.py index cad0abcf..49af3a4e 100644 --- a/homu/utils.py +++ b/homu/utils.py @@ -8,7 +8,7 @@ import time -def github_set_ref(repo, ref, sha, *, force=False, auto_create=True): +def github_set_ref(repo, ref, sha, *, force=False, auto_create=True, retry=1): url = repo._build_url('git', 'refs', ref, base_url=repo._api) data = {'sha': sha, 'force': force} @@ -20,6 +20,9 @@ def github_set_ref(repo, ref, sha, *, force=False, auto_create=True): return repo.create_ref('refs/' + ref, sha) except github3.models.GitHubError: raise e + elif e.code == 422 and retry > 0: + time.sleep(5) + return github_set_ref(repo, ref, sha, force=force, auto_create=auto_create, retry=retry - 1) else: raise From 878e02e38548136f22c339e38a4f74c01f3b8455 Mon Sep 17 00:00:00 2001 From: Eh2406 Date: Mon, 2 Oct 2017 11:04:34 -0400 Subject: [PATCH 2/2] fix line length --- homu/utils.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/homu/utils.py b/homu/utils.py index 49af3a4e..48a03c62 100644 --- a/homu/utils.py +++ b/homu/utils.py @@ -22,7 +22,12 @@ def github_set_ref(repo, ref, sha, *, force=False, auto_create=True, retry=1): raise e elif e.code == 422 and retry > 0: time.sleep(5) - return github_set_ref(repo, ref, sha, force=force, auto_create=auto_create, retry=retry - 1) + return github_set_ref(repo, + ref, + sha, + force=force, + auto_create=auto_create, + retry=retry - 1) else: raise