1 Star 0 Fork 1

balabala/test-webhook

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
app.py 2.10 KB
一键复制 编辑 原始数据 按行查看 历史
姜威 提交于 2021-08-31 10:47 . 修改url
"""
# coding:utf-8
@Time : 2021/08/30
@Author : jiangwei
@mail : qq804022023@gmail.com
@File : app.py
@Desc : app
@Software: PyCharm
"""
from flask import Flask, jsonify, request
from utils import check_sign, send_greeting_for_pr, add_label_for_merge, send_greeting_for_issue
app = Flask(__name__)
@app.route('/web-hook/test-handler', methods=['POST'])
def push_handler():
datas = request.json
if not check_sign(datas.get('timestamp'), datas.get('sign')):
return jsonify({'code': 500, 'msg': 'Sign authorization wrong!'})
return jsonify({'code': 200, 'info': f'{datas.get("hook_name")} Success'})
@app.route('/web-hook/pr-handler', methods=['POST'])
def pull_request_handler():
datas: dict = request.json
if not check_sign(datas.get('timestamp'), datas.get('sign')):
return jsonify({'code': 500, 'msg': 'Sign authorization wrong!'})
if datas.get('action') == 'open':
res = send_greeting_for_pr(datas=datas)
if res.status_code:
return jsonify({'code': res.status_code, 'msg': 'greeting message send successful.'})
elif datas.get('action') == 'merge':
res = add_label_for_merge(datas)
if res.status_code:
return jsonify({'code': res.status_code, 'msg': 'greeting message send successful.'})
else:
return jsonify({'code': 200, 'msg': 'not supported webhook action'})
return jsonify({'code': 500, 'msg': 'execute remote server failed.'})
@app.route('/web-hook/issue-handler', methods=['POST'])
def issue_handler():
datas: dict = request.json
if not check_sign(datas.get('timestamp'), datas.get('sign')):
return jsonify({'code': 500, 'msg': 'Sign authorization wrong!'})
if datas.get('action') == 'open':
res = send_greeting_for_issue(datas)
if res.status_code:
return jsonify({'code': res.status_code, 'msg': 'greeting message send successful.'})
else:
return jsonify({'code': 500, 'msg': 'not supported webhook action'})
return jsonify({'code': 500, 'msg': 'execute remote server failed.'})
if __name__ == '__main__':
app.run(port=9090, debug=False)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/xueyang721/test-webhook.git
git@gitee.com:xueyang721/test-webhook.git
xueyang721
test-webhook
test-webhook
master

搜索帮助