aboutsummaryrefslogtreecommitdiff
path: root/contrib/devtools/github-merge.py
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2019-01-14 16:33:57 +0100
committerWladimir J. van der Laan <laanwj@gmail.com>2019-01-14 16:48:23 +0100
commitf1bd219a5b318e4bea361e1247a233e4f251f517 (patch)
tree69ceda55d55309a578ea4ab112a0740f70f6b4ad /contrib/devtools/github-merge.py
parenta4c5bbfcd3a12f310b26cccc78ded32dd3f32ebb (diff)
downloadbitcoin-f1bd219a5b318e4bea361e1247a233e4f251f517.tar.xz
contrib: Allow use of github API authentication in github-merge
The API request limit for unauthenticated requests is quite low. I started running into rate limiting errors. The limit for authenticated requests is much higher. This patch adds an optional configuration setting `user.ghtoken` that, when set, is used to authenticate requests to the API.
Diffstat (limited to 'contrib/devtools/github-merge.py')
-rwxr-xr-xcontrib/devtools/github-merge.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/contrib/devtools/github-merge.py b/contrib/devtools/github-merge.py
index bbebd11e8e..ab834b7623 100755
--- a/contrib/devtools/github-merge.py
+++ b/contrib/devtools/github-merge.py
@@ -47,13 +47,15 @@ def git_config_get(option, default=None):
except subprocess.CalledProcessError:
return default
-def retrieve_pr_info(repo,pull):
+def retrieve_pr_info(repo,pull,ghtoken):
'''
Retrieve pull request information from github.
Return None if no title can be found, or an error happens.
'''
try:
req = Request("https://api.github.com/repos/"+repo+"/pulls/"+pull)
+ if ghtoken is not None:
+ req.add_header('Authorization', 'token ' + ghtoken)
result = urlopen(req)
reader = codecs.getreader('utf-8')
obj = json.load(reader(result))
@@ -140,6 +142,7 @@ def parse_arguments():
In addition, you can set the following git configuration variables:
githubmerge.repository (mandatory),
user.signingkey (mandatory),
+ user.ghtoken (default: none).
githubmerge.host (default: git@github.com),
githubmerge.branch (no default),
githubmerge.testcmd (default: none).
@@ -158,6 +161,7 @@ def main():
host = git_config_get('githubmerge.host','git@github.com')
opt_branch = git_config_get('githubmerge.branch',None)
testcmd = git_config_get('githubmerge.testcmd')
+ ghtoken = git_config_get('user.ghtoken')
signingkey = git_config_get('user.signingkey')
if repo is None:
print("ERROR: No repository configured. Use this command to set:", file=stderr)
@@ -178,7 +182,7 @@ def main():
pull = str(args.pull[0])
# Receive pull information from github
- info = retrieve_pr_info(repo,pull)
+ info = retrieve_pr_info(repo,pull,ghtoken)
if info is None:
sys.exit(1)
title = info['title'].strip()