Skip to content
This repository was archived by the owner on Mar 14, 2023. It is now read-only.

Commit 7d54c0a

Browse files
authored
Merge pull request #214 from rust-lang/more-log-info
increase information contained in error logs
2 parents 748c035 + a890a07 commit 7d54c0a

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

highfive/app.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
from __future__ import print_function
2+
3+
import datetime
14
import hashlib
25
import hmac
36
import json
47
import sys
8+
import traceback
59

610
from .config import Config, InvalidTokenException
711
from .newpr import HighfiveHandler, UnsupportedRepoError
@@ -24,15 +28,19 @@ def create_app(config, webhook_secret=None, config_dir=None):
2428
def new_pr():
2529
raw_data = flask.request.get_data()
2630

31+
# Load all the headers
32+
try:
33+
event = str(flask.request.headers['X-GitHub-Event'])
34+
delivery = str(flask.request.headers['X-GitHub-Delivery'])
35+
signature = str(flask.request.headers['X-Hub-Signature'])
36+
except KeyError:
37+
return 'Error: some required webhook headers are missing\n', 400
38+
2739
# Check the signature only if the secret is configured
2840
if 'payload' in flask.request.form and webhook_secret is not None:
2941
expected = hmac.new(str(webhook_secret), digestmod=hashlib.sha1)
3042
expected.update(raw_data)
3143
expected = expected.hexdigest()
32-
try:
33-
signature = str(flask.request.headers['X-Hub-Signature'])
34-
except KeyError:
35-
return 'Error: missing signature\n', 400
3644
if not hmac.compare_digest('sha1='+expected, signature):
3745
return 'Error: invalid signature\n', 403
3846

@@ -42,9 +50,18 @@ def new_pr():
4250
return 'Error: missing or invalid payload\n', 400
4351
try:
4452
handler = HighfiveHandler(Payload(payload), config, config_dir)
45-
return handler.run(flask.request.headers['X-GitHub-Event'])
53+
return handler.run(event)
4654
except UnsupportedRepoError:
4755
return 'Error: this repository is not configured!\n', 400
56+
except:
57+
print()
58+
print('An exception occured while processing a webhook!')
59+
print('Time:', datetime.datetime.now())
60+
print('Delivery ID:', delivery)
61+
print('Event name:', event)
62+
print('Payload:', json.dumps(payload))
63+
print(traceback.format_exc())
64+
return 'Internal server error\n', 500
4865

4966
@app.route('/')
5067
def index():
@@ -62,9 +79,9 @@ def cli(port, github_token, webhook_secret, config_dir):
6279
try:
6380
config = Config(github_token)
6481
except InvalidTokenException:
65-
print 'error: invalid github token provided!'
82+
print('error: invalid github token provided!')
6683
sys.exit(1)
67-
print 'Found a valid GitHub token for user @' + config.github_username
84+
print('Found a valid GitHub token for user @' + config.github_username)
6885

6986
app = create_app(config, webhook_secret, config_dir)
7087
waitress.serve(app, port=port)

0 commit comments

Comments
 (0)