Repository: kafka
Updated Branches:
  refs/heads/trunk e14ae66e7 -> 34a6be2cc


MINOR: Support GitHub OAuth tokens in kafka-merge-pr.py

Author: Guozhang Wang <[email protected]>

Reviewers: Gwen Shapira

Closes #590 from guozhangwang/KOAuth


Project: http://git-wip-us.apache.org/repos/asf/kafka/repo
Commit: http://git-wip-us.apache.org/repos/asf/kafka/commit/34a6be2c
Tree: http://git-wip-us.apache.org/repos/asf/kafka/tree/34a6be2c
Diff: http://git-wip-us.apache.org/repos/asf/kafka/diff/34a6be2c

Branch: refs/heads/trunk
Commit: 34a6be2ccd95d50e7659a57c943436e579521471
Parents: e14ae66
Author: Guozhang Wang <[email protected]>
Authored: Wed Nov 25 15:03:10 2015 -0800
Committer: Gwen Shapira <[email protected]>
Committed: Wed Nov 25 15:03:10 2015 -0800

----------------------------------------------------------------------
 kafka-merge-pr.py | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kafka/blob/34a6be2c/kafka-merge-pr.py
----------------------------------------------------------------------
diff --git a/kafka-merge-pr.py b/kafka-merge-pr.py
index 186e65c..01b25c7 100644
--- a/kafka-merge-pr.py
+++ b/kafka-merge-pr.py
@@ -54,6 +54,11 @@ PUSH_REMOTE_NAME = os.environ.get("PUSH_REMOTE_NAME", 
"apache")
 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)
@@ -71,9 +76,17 @@ DEFAULT_FIX_VERSION = os.environ.get("DEFAULT_FIX_VERSION", 
"0.9.1.0")
 
 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)
 
 

Reply via email to