From 6c7de9e016aebdb9dfef7987f3449a5907ba0883 Mon Sep 17 00:00:00 2001 From: Alexander Turenko Date: Mon, 8 Nov 2021 11:17:13 +0300 Subject: [PATCH 1/2] Raise HTTPError if a request fails This way we'll see a problem in GitHub's UI, where delivered and failed webhook payloads are shown. Before this change the payload was marked as successfully delivered and only message like 'Created issue: 400' is shown in logs on Heroku. Part of #11 --- tarantoolbot.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tarantoolbot.py b/tarantoolbot.py index 714dfd5..3dea1cf 100644 --- a/tarantoolbot.py +++ b/tarantoolbot.py @@ -89,6 +89,7 @@ def send_comment(body, issue_api, to): body = {'body': '@{}: {}'.format(to, body)} url = '{}/comments?access_token={}'.format(issue_api, token) r = requests.post(url, json=body) + r.raise_for_status() print('Sent comment: {}'.format(r.status_code)) ## @@ -99,6 +100,7 @@ def get_comments(issue_api): body = {'since': '1970-01-01T00:00:00Z'} url = '{}/comments?access_token={}'.format(issue_api, token) r = requests.get(url, json=body) + r.raise_for_status() return r.json() ## @@ -117,6 +119,7 @@ def create_issue(title, description, src_url, author): body = {'title': title, 'body': description} url = '{}/issues?access_token={}'.format(doc_repo_url, token) r = requests.post(url, json=body) + r.raise_for_status() print('Created issue: {}'.format(r.status_code)) ## From 84bba7748172c96321a9a66c25c468dc074961c4 Mon Sep 17 00:00:00 2001 From: Alexander Turenko Date: Mon, 8 Nov 2021 11:45:17 +0300 Subject: [PATCH 2/2] Use Authorization header for auth on GitHub API `access_token` query parameter does not work anymore. See https://developer.github.com/changes/2020-02-10-deprecating-auth-through-query-param/ Fixes #11 --- tarantoolbot.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/tarantoolbot.py b/tarantoolbot.py index 3dea1cf..d9cad94 100644 --- a/tarantoolbot.py +++ b/tarantoolbot.py @@ -87,8 +87,11 @@ def parse_comment(body): def send_comment(body, issue_api, to): create_event(to, 'send_comment', body) body = {'body': '@{}: {}'.format(to, body)} - url = '{}/comments?access_token={}'.format(issue_api, token) - r = requests.post(url, json=body) + url = '{}/comments'.format(issue_api) + headers = { + 'Authorization': 'token {}'.format(token), + } + r = requests.post(url, json=body, headers=headers) r.raise_for_status() print('Sent comment: {}'.format(r.status_code)) @@ -98,8 +101,11 @@ def send_comment(body, issue_api, to): def get_comments(issue_api): body = {'since': '1970-01-01T00:00:00Z'} - url = '{}/comments?access_token={}'.format(issue_api, token) - r = requests.get(url, json=body) + url = '{}/comments'.format(issue_api) + headers = { + 'Authorization': 'token {}'.format(token), + } + r = requests.get(url, json=body, headers=headers) r.raise_for_status() return r.json() @@ -117,8 +123,11 @@ def create_issue(title, description, src_url, author): description = '{}\nRequested by @{} in {}.'.format(description, author, src_url) body = {'title': title, 'body': description} - url = '{}/issues?access_token={}'.format(doc_repo_url, token) - r = requests.post(url, json=body) + url = '{}/issues'.format(doc_repo_url) + headers = { + 'Authorization': 'token {}'.format(token), + } + r = requests.post(url, json=body, headers=headers) r.raise_for_status() print('Created issue: {}'.format(r.status_code))