feat: 优化代码逻辑,使用异步函数处理事件管理
All checks were successful
CI Monitor MIflow / build-image (push) Successful in 45s

This commit is contained in:
zhaoyingbo 2024-08-09 02:29:32 +00:00
parent d748879b4c
commit b398dba6c1
2 changed files with 20 additions and 16 deletions

View File

@ -281,21 +281,25 @@ const manageRawEvent = async (
const stage = params.get("stage")
// 获取下一步操作
const action = await getNextAction(pipeline, stage)
// 发送通知
if (action === NEXT_ACTION.NOTIFY) {
sendNotify(pipeline, apiKey)
}
// 添加监控
if (action === NEXT_ACTION.ADD_MONITOR) {
addMonitor(pipeline, apiKey, stage!)
}
// 删除监控
if (action === NEXT_ACTION.REMOVE_MONITOR) {
removeMonitor(pipeline, apiKey, stage!)
}
// 删除监控并发送通知
if (action === NEXT_ACTION.NOTIFY_AND_REMOVE_MONITOR) {
removeMonitorAndNotify(pipeline, apiKey, stage!)
switch (action) {
// 发送通知
case NEXT_ACTION.NOTIFY:
await sendNotify(pipeline, apiKey)
break
// 添加监控
case NEXT_ACTION.ADD_MONITOR:
await addMonitor(pipeline, apiKey, stage!)
break
// 删除监控
case NEXT_ACTION.REMOVE_MONITOR:
await removeMonitor(pipeline, apiKey, stage!)
break
// 删除监控并发送通知
case NEXT_ACTION.NOTIFY_AND_REMOVE_MONITOR:
await removeMonitorAndNotify(pipeline, apiKey, stage!)
break
default:
break
}
// 返回成功
return netTool.ok()

View File

@ -15,7 +15,7 @@ export const manageGitlabEventReq = async (req: Request): Promise<Response> => {
if (eventType === "Pipeline Hook") {
const body = (await req.json()) as Gitlab.PipelineEvent
const params = new URLSearchParams(req.url.split("?")[1])
return managePipelineEvent.manageRawEvent(body, apiKey, params)
return await managePipelineEvent.manageRawEvent(body, apiKey, params)
}
return netTool.ok()
}