Skip to content

Commit ed56e6d

Browse files
Fixed a bug in configuration read.
1 parent f75a8be commit ed56e6d

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

README.rst

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,19 @@ and has a shebang. A simple example in Python could be:
6666

6767
#!/usr/bin/env python
6868
# Python Example for Python GitHub Webhooks
69+
# File: push-myrepo-master
6970

70-
import os
7171
import sys
7272
import json
73-
from tempfile import mkstemp
7473

7574
payload = json.loads(sys.argv[1])
76-
_, tmpfile = mkstemp()
7775

7876
### Do something with the payload
79-
if payload['repository']['name'] == 'my-repo-name':
80-
f = open(tmpfile, 'w')
77+
name = payload['repository']['name']
78+
outfile = '/tmp/hook-{}.log'.format(name)
79+
80+
with open(outfile, 'w') as f:
8181
f.write(json.dumps(payload))
82-
f.close()
8382

8483

8584
Test

webhooks.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,11 @@
3838
@application.route('/', methods=['GET', 'POST'])
3939
def index():
4040
"""
41+
Main WSGI application entry.
4142
"""
42-
hooks = join(normpath(abspath(dirname(__file__))), 'hooks')
43+
44+
path = normpath(abspath(dirname(__file__)))
45+
hooks = join(path, 'hooks')
4346

4447
whitelist = requests.get('https://api.github.com/meta').json()['hooks']
4548

@@ -48,7 +51,7 @@ def index():
4851
abort(501)
4952

5053
# Load config
51-
with open('config.json', 'r') as cfg:
54+
with open(join(path, 'config.json'), 'r') as cfg:
5255
config = loads(cfg.read())
5356

5457
# Allow Github IPs only

0 commit comments

Comments
 (0)