-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
38 lines (33 loc) · 1.12 KB
/
app.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
32
33
34
35
36
37
38
from flask import Flask
from flask import request
import json
from deploy_fe import deploy_fe
from deploy_be import deploy_be
from logger import logger
from config import WEB_REPO_NAME, BACKEND_REPO_NAME
app = Flask(__name__)
@app.route('/webhook', methods=['POST'])
def webhook():
payload = request.form.get('payload')
logger.debug(payload)
if payload:
payload = json.loads(payload)
ref = payload.get('ref')
base_ref = payload.get('base_ref') or ref
logger.debug(f'ref=>{ref}')
logger.debug(f'base_ref=>{base_ref}')
if ref.startswith('refs/tags'):
repo_name = payload['repository']['name']
logger.debug(f'repo_name=>{repo_name}')
tag = ref.split("/")[-1]
if repo_name == WEB_REPO_NAME:
deploy_fe(tag, base_ref)
elif repo_name == BACKEND_REPO_NAME:
deploy_be(tag, base_ref)
else:
logger.debug('ignore commit')
else:
logger.debug(payload)
return 'ok'
if __name__ == '__main__':
app.run(host='0.0.0.0', debug=True)