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

View File

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