diff --git a/highfive/newpr.py b/highfive/newpr.py index 2634303e..802a90ac 100755 --- a/highfive/newpr.py +++ b/highfive/newpr.py @@ -12,6 +12,7 @@ import gzip import re import os +from retry import retry from highfive import irc, payload @@ -47,6 +48,9 @@ class UnsupportedRepoError(IOError): pass +class HttpClientError(Exception): + pass + class HighfiveHandler(object): def __init__(self, payload): self.payload = payload @@ -102,6 +106,7 @@ def api_req(self, method, url, data=None, media_type=None): body = f.read() return { "header": header, "body": body } + @retry(HttpClientError, delay=1, backoff=2, max_delay=3) def set_assignee(self, assignee, owner, repo, issue, user, author, to_mention): try: self.api_req( @@ -111,6 +116,8 @@ def set_assignee(self, assignee, owner, repo, issue, user, author, to_mention): except urllib2.HTTPError, e: if e.code == 201: pass + elif e.code == 400: + raise HttpClientError else: raise e @@ -146,6 +153,7 @@ def get_irc_nick(self, gh_name): return None + @retry(HttpClientError, delay=1, backoff=2, max_delay=3) def is_collaborator(self, commenter, owner, repo): """Returns True if `commenter` is a collaborator in the repo.""" try: @@ -156,6 +164,8 @@ def is_collaborator(self, commenter, owner, repo): except urllib2.HTTPError, e: if e.code == 404: return False + elif e.code == 400: + raise HttpClientError else: raise e @@ -172,6 +182,7 @@ def post_warnings(self, diff, owner, repo, issue): if warnings: self.post_comment(warning_summary % '\n'.join(map(lambda x: '* ' + x, warnings)), owner, repo, issue) + @retry(HttpClientError, delay=1, backoff=2, max_delay=3) def post_comment(self, body, owner, repo, issue): try: self.api_req( @@ -180,6 +191,8 @@ def post_comment(self, body, owner, repo, issue): except urllib2.HTTPError, e: if e.code == 201: pass + elif e.code == 400: + raise HttpClientError else: raise e @@ -211,6 +224,7 @@ def unexpected_branch(self): return (expected_target, actual_target) \ if expected_target != actual_target else False + @retry(HttpClientError, delay=1, backoff=2, max_delay=3) def is_new_contributor(self, username, owner, repo): # If this is a fork, we do not treat anyone as a new user. This is # because the API endpoint called in this function indicates all @@ -227,6 +241,8 @@ def is_new_contributor(self, username, owner, repo): except urllib2.HTTPError, e: if e.code == 422: return True + elif e.code == 400: + raise HttpClientError else: raise e diff --git a/setup.py b/setup.py index 4e84a2e2..dbe64d19 100644 --- a/setup.py +++ b/setup.py @@ -9,4 +9,5 @@ author_email='no-idea@no-server.no-suffix', url='https://github.com/rust-lang-nursery/highfive', packages=['highfive'], + install_requires=['retry'], )