Handle github exceptions better when trying to get a PR

When we use getPull() function after a github event, it seems there
might be race where the PR may not exist just yet. So, rather then
raising an exception, log a warning and allow the loop to try again.

Change-Id: I66aaa74e0fdeade253df1e44a659f513accdfe37
Signed-off-by: Paul Belanger <pabelanger@redhat.com>
This commit is contained in:
Paul Belanger 2019-04-10 12:51:11 -04:00
parent 1596f3c8c8
commit e8444f3983
1 changed files with 10 additions and 5 deletions

View File

@ -1144,11 +1144,16 @@ class GithubConnection(BaseConnection):
github = self.getGithubClient(project_name)
owner, proj = project_name.split('/')
for retry in range(5):
probj = github.pull_request(owner, proj, number)
if probj is not None:
break
self.log.warning("Pull request #%s of %s/%s returned None!" % (
number, owner, proj))
try:
probj = github.pull_request(owner, proj, number)
if probj is not None:
break
self.log.warning("Pull request #%s of %s/%s returned None!" % (
number, owner, proj))
except github3.exceptions.GitHubException:
self.log.warning(
"Failed to get pull request #%s of %s/%s; retrying" %
(number, owner, proj))
time.sleep(1)
pr = probj.as_dict()
try: