Update prController.py

This commit is contained in:
zzy15093679116 2023-12-07 14:59:21 +08:00
parent af3da08f90
commit 601fdbdcf8
1 changed files with 8 additions and 3 deletions

View File

@ -26,11 +26,14 @@ def hello():
@cross_origin() #prwelcome 接口用于处理 GitHub Webhook 数据。根据接收到的数据,判断 PR 的状态(是新创建还是关闭),然后调用 pullService 执行相应的数据库操作
def pr_welcome():
try:
# 获取请求中的JSON数据
payload = request.json
print(payload)
logger.info("获取webhook信息成功:" + str(payload))
# # 判断是新创建issue还是issue的状态发生改变
# 判断PR的状态是新创建还是关闭
if payload["action"] == 'opened':
# 提取必要的信息
pull_id = payload["pull_request"]["id"]
index = payload["pull_request"]["number"]
time = payload["pull_request"]["created_at"][:19]
@ -40,20 +43,22 @@ def pr_welcome():
check_time = created + datetime.timedelta(hours=2)
values = (pull_id, index, owner, repo, created, check_time, 0)
# print(values)
pullService.insert_pull(values)
pullService.insert_pull(values) # 调用pullService插入PR记录到数据库
# 关闭 更新数据库对应pr状态 (合并或者拒绝都属于关闭)
elif payload["action"] == 'closed':
index = payload["pull_request"]["number"]
owner = payload["pull_request"]["user"]["login"]
repo = payload["repository"]["full_name"]
pullService.update_pull(index, owner, repo)
pullService.update_pull(index, owner, repo) # 调用pullService更新数据库中对应的PR记录
# 返回成功响应
return jsonify({
"code": 0,
"msg": "success"
})
except Exception as e:
# 返回异常响应
return jsonify({
"code": -1,
"msg": "exception:" + str(e)