gitlab_monitor/index.ts
zhaoyingbo 7d90bd368e
All checks were successful
CI Monitor CI/CD / build-image (push) Successful in 23s
CI Monitor CI/CD / deploy (push) Successful in 30s
feat: 添加通过ChatID发送CI报告的功能
2024-05-21 06:54:31 +00:00

46 lines
1.3 KiB
TypeScript

import { scheduleJob } from "node-schedule";
import managePipeline from "./controllers/managePipeLine";
import manageProject from "./controllers/manageProject";
import manageUser from "./controllers/manageUser";
import manageRobot from "./controllers/manageRobot";
const main = async () => {
const fullProjList = await manageProject.getFullProjList();
const fullPipelineList = await Promise.all(
fullProjList.map((v) => managePipeline.getFullPipelineList(v))
);
const fullUserMap = await manageUser.getFullUserMap(fullPipelineList);
const fullProjectMap = await manageProject.getFullProjectMap(fullProjList);
await managePipeline.insertFullPipelineList(
fullPipelineList,
fullUserMap,
fullProjectMap
);
};
main();
scheduleJob("*/15 * * * *", main);
scheduleJob("0 10 * * 5", manageRobot.sendCIReportByCron);
Bun.serve({
async fetch(req) {
const url = new URL(req.url);
if (url.pathname === "/ci") {
const chat_id = url.searchParams.get("chat_id");
console.log("🚀 ~ fetch ~ chat_id:", chat_id);
if (!chat_id)
return new Response("chat_id is required!", { status: 400 });
manageRobot.sendCIReportByChatId(chat_id);
return Response.json({
code: 0,
msg: "success",
data: "reporting...",
});
}
return new Response("OK");
},
port: 3000,
});