Skip to content

Commit

Permalink
MINOR: Support GitHub OAuth tokens in kafka-merge-pr.py
Browse files Browse the repository at this point in the history
Author: Guozhang Wang <[email protected]>

Reviewers: Gwen Shapira

Closes apache#590 from guozhangwang/KOAuth
  • Loading branch information
guozhangwang authored and gwenshap committed Nov 25, 2015
1 parent e14ae66 commit 34a6be2
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions kafka-merge-pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@
JIRA_USERNAME = os.environ.get("JIRA_USERNAME", "")
# ASF JIRA password
JIRA_PASSWORD = os.environ.get("JIRA_PASSWORD", "")
# OAuth key used for issuing requests against the GitHub API. If this is not defined, then requests
# will be unauthenticated. You should only need to configure this if you find yourself regularly
# exceeding your IP's unauthenticated request rate limit. You can create an OAuth key at
# https://github.com/settings/tokens. This script only requires the "public_repo" scope.
GITHUB_OAUTH_KEY = os.environ.get("GITHUB_OAUTH_KEY")

GITHUB_USER = os.environ.get("GITHUB_USER", "apache")
GITHUB_BASE = "https://github.com/%s/%s/pull" % (GITHUB_USER, PROJECT_NAME)
Expand All @@ -71,9 +76,17 @@

def get_json(url):
try:
return json.load(urllib2.urlopen(url))
request = urllib2.Request(url)
if GITHUB_OAUTH_KEY:
request.add_header('Authorization', 'token %s' % GITHUB_OAUTH_KEY)
return json.load(urllib2.urlopen(request))
except urllib2.HTTPError as e:
print "Unable to fetch URL, exiting: %s" % url
if "X-RateLimit-Remaining" in e.headers and e.headers["X-RateLimit-Remaining"] == '0':
print "Exceeded the GitHub API rate limit; see the instructions in " + \
"kafka-merge-pr.py to configure an OAuth token for making authenticated " + \
"GitHub requests."
else:
print "Unable to fetch URL, exiting: %s" % url
sys.exit(-1)


Expand Down

0 comments on commit 34a6be2

Please sign in to comment.