-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebhook.py
31 lines (23 loc) · 840 Bytes
/
webhook.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# -*- coding: utf-8 -*-
import importlib
import subprocess
from flask import Flask, request, jsonify
app = Flask(__name__)
@app.route('/', methods=['POST'])
def webhook():
if request.get_json():
ref = request.get_json().get('ref')
branch = ref[ref.rfind("/") + 1:]
try:
settings = importlib.import_module("settings.%s" % branch)
except ImportError, e:
return 'Settings import failed. Details: %s' % e.message
exit_code = subprocess.call(['./webhook.sh', settings.PROJECT_DIR, settings.VIRTUALENV, settings.GUNICORN_PID_FILE, branch, settings.SETTINGS_MODULE, settings.LOGS_DIR])
response = {
'exit_code': exit_code,
'branch': branch
}
return jsonify(**response)
return ''
if __name__ == '__main__':
app.run()