Use custom HTTP headers and params for the GitHub API

This commit is contained in:
Jannik Vogel 2016-11-25 13:52:35 +01:00
parent 5d8699e86b
commit a387e6f0e2

View File

@ -33,6 +33,14 @@ MAIN_REPO = PULL_REPOS[1]
PUSH_REPO = 'git@github.com:citra-emu/citra-bleeding-edge' PUSH_REPO = 'git@github.com:citra-emu/citra-bleeding-edge'
# PUSH_REPO = 'git@github.com:jroweboy/lemon' # PUSH_REPO = 'git@github.com:jroweboy/lemon'
GITHUB_API_HEADERS = {
'User-Agent': 'citra-emu/lemonbot'
}
GITHUB_API_PARAMS = {
'client_id': 'xxxx',
'client_secret': 'yyyy'
}
class TagMergeBot: class TagMergeBot:
''' Fetches all the pull requests on a repository and merges all the pull requests with a specified tag on them. ''' ''' Fetches all the pull requests on a repository and merges all the pull requests with a specified tag on them. '''
def __init__(self, main_repo, pull_repos, push_repo): def __init__(self, main_repo, pull_repos, push_repo):
@ -69,13 +77,13 @@ class TagMergeBot:
self.current_prs = {} self.current_prs = {}
for repo in self.repos: for repo in self.repos:
self.current_prs[repo['remote_name']] = [] self.current_prs[repo['remote_name']] = []
res = requests.get(GITHUB_API+'/{owner}/{repo}/issues?labels={labels}&per_page=100'.format(labels=LABEL_TO_FETCH, owner=repo['owner'], repo=repo['name'])) res = requests.get(GITHUB_API+'/{owner}/{repo}/issues?labels={labels}&per_page=100'.format(labels=LABEL_TO_FETCH, owner=repo['owner'], repo=repo['name']), params=GITHUB_API_PARAMS, headers=GITHUB_API_HEADERS)
if res.status_code != 200: if res.status_code != 200:
logger.error("Could not retrive pull requests from github. Status: {status}".format(status=res.status_code)) logger.error("Could not retrive pull requests from github. Status: {status}".format(status=res.status_code))
return False return False
issues = res.json() issues = res.json()
for issue in issues: for issue in issues:
pr_response = requests.get(issue['pull_request']['url']) pr_response = requests.get(issue['pull_request']['url'], params=GITHUB_API_PARAMS, headers=GITHUB_API_HEADERS)
if res.status_code != 200: if res.status_code != 200:
logger.warn("Couldn't fetch the PRs details for PR {pr}. Status: {status}".format(pr=issue[''], status=res.status_code)) logger.warn("Couldn't fetch the PRs details for PR {pr}. Status: {status}".format(pr=issue[''], status=res.status_code))
continue continue