Update prController.py

This commit is contained in:
Apirl 2023-12-21 13:18:55 +08:00
parent 020b3675a4
commit d489b77fb8
1 changed files with 18 additions and 15 deletions

View File

@ -1,17 +1,20 @@
#!/usr/bin/python
import sys
sys.path.append('..')
from flask import Flask, jsonify, request
from flask_cors import CORS, cross_origin
import json
import services.pullService as pullService
import datetime
from commons.logUtil import logger
sys.path.append('..') # 将上层目录添加到模块搜索路径中
app = Flask(__name__)
from flask import Flask, jsonify, request # 导入Flask相关模块
from flask_cors import CORS, cross_origin # 导入处理CORS的模块
import json # 导入处理JSON的模块
import services.pullService as pullService # 导入自定义的pullService模块
import datetime # 导入处理日期时间的模块
from commons.logUtil import logger # 导入自定义的日志工具模块
app = Flask(__name__) # 创建Flask应用实例
# 测试
# 测试路由返回JSON响应
@app.route('/hello', methods=['get'])
@cross_origin()
def hello():
@ -20,15 +23,15 @@ def hello():
"msg": "hello"
})
# 处理Gitlink Webhook的路由
# 功能:每当有一个新的PR创建/关闭时,根据状态执行存储或更新操作
@app.route('/prwelcome', methods=['POST'])
@cross_origin()
def pr_welcome():
try:
payload = request.json
print(payload)
logger.info("获取webhook信息成功:" + str(payload))
payload = request.json # 从请求中获取JSON数据
print(payload) # 打印获取到的JSON数据
logger.info("获取webhook信息成功:" + str(payload)) # 记录日志
# # 判断是新创建issue还是issue的状态发生改变
if payload["action"] == 'opened':
pull_id = payload["pull_request"]["id"]
@ -40,14 +43,14 @@ 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)# 执行插入操作
# 关闭 更新数据库对应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)# 执行更新操作
return jsonify({
"code": 0,