zhaoyingbo f5ee6f8555
All checks were successful
CI Monitor MIflow / build-image (push) Successful in 45s
feat: 修改监控Stage的方式
2024-08-08 11:04:09 +00:00

22 lines
846 B
TypeScript

import managePipelineEvent from "../../controllers/managePipelineEvent"
import netTool from "../../service/netTool"
import { Gitlab } from "../../types/gitlab"
/**
* 处理管理Gitlab事件的请求。
* @param {Request} req - 请求对象。
* @returns {Promise<Response>} - 响应对象。
*/
export const manageGitlabEventReq = async (req: Request): Promise<Response> => {
const apiKey = req.headers.get("x-gitlab-token")
if (!apiKey) return netTool.badRequest("x-gitlab-token is required!")
const eventType = req.headers.get("x-gitlab-event")
// 只处理流水线钩子
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 netTool.ok()
}