Skip to content

Instantly share code, notes, and snippets.

@NickWoodhams
Created June 3, 2013 08:26
Show Gist options
  • Save NickWoodhams/5696838 to your computer and use it in GitHub Desktop.
Save NickWoodhams/5696838 to your computer and use it in GitHub Desktop.
Flask Github post-receive hook
@app.route('/post-receive-hook', methods=['GET', 'POST'])
def post_receive_hook():
if request.method == "POST" and request.form['payload']:
payload = json.loads(request.form['payload'])
pprint(payload)
output = subprocess.Popen('sh /home/user/post-receive-script.sh'.split(), stdout=subprocess.PIPE).communicate()[0]
print output # for debugging
return "Hi!"
else:
abort(404)
cd /home/user/project-git-repo
git reset --hard HEAD
git pull
touch "/etc/uwsgi/apps-available/project.ini" # restart uwsgi emperor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment