feat: 添加通过ChatID发送CI报告的功能
This commit is contained in:
parent
6cb7a26ad5
commit
7d90bd368e
@ -96,6 +96,10 @@ const getProjDiffInfo = async () => {
|
|||||||
return group.slice(0, 5);
|
return group.slice(0, 5);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取机器人消息
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
const getRobotMsg = async () =>
|
const getRobotMsg = async () =>
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
type: "template",
|
type: "template",
|
||||||
@ -112,11 +116,24 @@ const getRobotMsg = async () =>
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const sendRobotMsg = async () => await service.sendMessage(await getRobotMsg());
|
/**
|
||||||
|
* 通过ChatID发送CI报告
|
||||||
|
* @param chat_id
|
||||||
|
*/
|
||||||
|
const sendCIReportByChatId = async (chat_id: string) => {
|
||||||
|
await service.sendMessage.byChatId(chat_id, await getRobotMsg());
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过定时任务发送CI报告
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
const sendCIReportByCron = async () =>
|
||||||
|
await service.sendMessage.byGroupId("52usf3w8l6z4vs1", await getRobotMsg());
|
||||||
|
|
||||||
const manageRobot = {
|
const manageRobot = {
|
||||||
getRobotMsg,
|
sendCIReportByChatId,
|
||||||
sendRobotMsg,
|
sendCIReportByCron,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default manageRobot;
|
export default manageRobot;
|
||||||
|
15
index.ts
15
index.ts
@ -22,13 +22,22 @@ main();
|
|||||||
|
|
||||||
scheduleJob("*/15 * * * *", main);
|
scheduleJob("*/15 * * * *", main);
|
||||||
|
|
||||||
scheduleJob("0 10 * * 5", manageRobot.sendRobotMsg);
|
scheduleJob("0 10 * * 5", manageRobot.sendCIReportByCron);
|
||||||
|
|
||||||
Bun.serve({
|
Bun.serve({
|
||||||
async fetch(req) {
|
async fetch(req) {
|
||||||
const url = new URL(req.url);
|
const url = new URL(req.url);
|
||||||
if (url.pathname === '/ci') {
|
if (url.pathname === "/ci") {
|
||||||
return Response.json(await manageRobot.getRobotMsg());
|
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");
|
return new Response("OK");
|
||||||
},
|
},
|
||||||
|
@ -62,26 +62,41 @@ const fetchPipelineDetails = async (
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const sendMessage = async (content: string) => {
|
const sendMessage = async (body: string) => {
|
||||||
try {
|
try {
|
||||||
const response = await fetch("https://egg.imoaix.cn/message", {
|
const response = await fetch("https://egg.imoaix.cn/message", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body,
|
||||||
group_id: "52usf3w8l6z4vs1",
|
|
||||||
msg_type: "interactive",
|
|
||||||
content,
|
|
||||||
}),
|
|
||||||
});
|
});
|
||||||
const body = await response.json();
|
const res = await response.json();
|
||||||
return body;
|
return res;
|
||||||
} catch {
|
} catch {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
sendMessage.byGroupId = async (group_id: string, content: string) => {
|
||||||
|
const body = JSON.stringify({
|
||||||
|
group_id,
|
||||||
|
msg_type: "interactive",
|
||||||
|
content,
|
||||||
|
});
|
||||||
|
return sendMessage(body);
|
||||||
|
};
|
||||||
|
|
||||||
|
sendMessage.byChatId = async (chat_id: string, content: string) => {
|
||||||
|
const body = JSON.stringify({
|
||||||
|
receive_id: chat_id,
|
||||||
|
receive_id_type: "chat_id",
|
||||||
|
msg_type: "interactive",
|
||||||
|
content,
|
||||||
|
});
|
||||||
|
return sendMessage(body);
|
||||||
|
};
|
||||||
|
|
||||||
const service = {
|
const service = {
|
||||||
fetchProjectDetails,
|
fetchProjectDetails,
|
||||||
fetchPipelines,
|
fetchPipelines,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user