File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree 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:
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
8584Test
Original file line number Diff line number Diff line change 3838@application .route ('/' , methods = ['GET' , 'POST' ])
3939def 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
You can’t perform that action at this time.
0 commit comments