Skip to content

Commit a4e344c

Browse files
When a branch is deleted in github, two things happen:
- You receive action "delete" with branch name. - You receive "push" with state "deleted". This triggers hooks for handling push and deletion - and what is even worse - they can be called in random order. This is simpler and give some abstraction over hook scripts that they will be run only once on particular action that happen. Note: Adapted from pull request #8 by cypreess.
1 parent 27c9516 commit a4e344c

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

webhooks.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ def index():
141141
}
142142
logging.info('Metadata:\n{}'.format(dumps(meta)))
143143

144+
# Skip push-delete
145+
if event == 'push' and payload['deleted']:
146+
logging.info('Skipping push-delete event for {}'.format(dumps(meta)))
147+
return dumps({'status': 'skipped'})
148+
144149
# Possible hooks
145150
scripts = []
146151
if branch and name:
@@ -153,7 +158,7 @@ def index():
153158
# Check permissions
154159
scripts = [s for s in scripts if isfile(s) and access(s, X_OK)]
155160
if not scripts:
156-
return ''
161+
return dumps({'status': 'nop'})
157162

158163
# Save payload to temporal file
159164
osfd, tmpfile = mkstemp()
@@ -187,7 +192,7 @@ def index():
187192

188193
info = config.get('return_scripts_info', False)
189194
if not info:
190-
return ''
195+
return dumps({'status': 'done'})
191196

192197
output = dumps(ran, sort_keys=True, indent=4)
193198
logging.info(output)

0 commit comments

Comments
 (0)