From 563f4f6d9d46361f4943574afed0647a9ae3df22 Mon Sep 17 00:00:00 2001 From: Karl Fessel Date: Tue, 3 Mar 2020 17:04:58 +0100 Subject: [PATCH] tools/backport_pr: Add Token Scope check --- dist/tools/backport_pr/backport_pr.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/dist/tools/backport_pr/backport_pr.py b/dist/tools/backport_pr/backport_pr.py index 217501a87b..85faa2bd12 100755 --- a/dist/tools/backport_pr/backport_pr.py +++ b/dist/tools/backport_pr/backport_pr.py @@ -135,6 +135,20 @@ def main(): if status != 200: print("Could not retrieve user: {}".format(user['message'])) exit(1) + # Token-scope-check: Is the token is powerful enough to complete + # the Backport? + response_headers = dict(g.getheaders()) + # agithub documentation says it's lower case header field-names but + # at this moment it's not + if 'X-OAuth-Scopes' in response_headers: + scopes = response_headers['X-OAuth-Scopes'] + else: + scopes = response_headers['x-oauth-scopes'] + scopes_list = [x.strip() for x in scopes.split(',')] + if not ('public_repo' in scopes_list or 'repo' in scopes_list): + print("missing public_repo scope from token settings." + " Please add it on the GitHub webinterface") + exit(1) username = user['login'] status, pulldata = g.repos[ORG][REPO].pulls[args.PR].get() if status != 200: