File tree Expand file tree Collapse file tree 2 files changed +10
-8
lines changed Expand file tree Collapse file tree 2 files changed +10
-8
lines changed Original file line number Diff line number Diff line change @@ -66,20 +66,19 @@ and has a shebang. A simple example in Python could be:
66
66
67
67
#!/usr/bin/env python
68
68
# Python Example for Python GitHub Webhooks
69
+ # File: push-myrepo-master
69
70
70
- import os
71
71
import sys
72
72
import json
73
- from tempfile import mkstemp
74
73
75
74
payload = json.loads(sys.argv[1])
76
- _, tmpfile = mkstemp()
77
75
78
76
### 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:
81
81
f.write(json.dumps(payload))
82
- f.close()
83
82
84
83
85
84
Test
Original file line number Diff line number Diff line change 38
38
@application .route ('/' , methods = ['GET' , 'POST' ])
39
39
def index ():
40
40
"""
41
+ Main WSGI application entry.
41
42
"""
42
- hooks = join (normpath (abspath (dirname (__file__ ))), 'hooks' )
43
+
44
+ path = normpath (abspath (dirname (__file__ )))
45
+ hooks = join (path , 'hooks' )
43
46
44
47
whitelist = requests .get ('https://api.github.com/meta' ).json ()['hooks' ]
45
48
@@ -48,7 +51,7 @@ def index():
48
51
abort (501 )
49
52
50
53
# Load config
51
- with open ('config.json' , 'r' ) as cfg :
54
+ with open (join ( path , 'config.json' ) , 'r' ) as cfg :
52
55
config = loads (cfg .read ())
53
56
54
57
# Allow Github IPs only
You can’t perform that action at this time.
0 commit comments