fy-convertor
Version:
Convert excel/xml/json/bin/protocl/ts/as ...
73 lines • 2.5 kB
JavaScript
import axios from "axios";
import ip from "ip";
import { RepoHolder } from "../core/RepoHolder.js";
import { Hudson } from "./hudson.js";
import moment from "moment";
export class Alert {
static ins;
static get Instance() {
if (!Alert.ins)
Alert.ins = new Alert();
return Alert.ins;
}
chatid = null;
setChatId(chatid) {
this.chatid = chatid;
}
async sendBuildFailureAlert(msg) {
if (!this.chatid)
return;
const startUser = await Hudson.getStartUser();
const theIp = ip.address();
const content = `# <font color=\"warning\">${Hudson.getJobName()} #${Hudson.getBuildNumber()} 失败</font>
>发起人:@${startUser}
>时间:${moment().format(moment.HTML5_FMT.TIME)}
>${msg}
>点击查看日志:[构建日志](http://${theIp}:8080/hudson/job/${Hudson.getJobName()}/${Hudson.getBuildNumber()}/consoleText)`;
// 先群发消息
await this.sendRobotMsg('markdown', content);
}
async alertErrorFile(file) {
if (!this.chatid)
return;
const info = await RepoHolder.Instance.svnClient.info([file], { showItem: 'last-changed-author' });
const touser = info.trim();
await this.sendRobotMsg('text', '文件错误,速改!\n' + file, touser);
}
async sendRobotMsg(type, msg, mention) {
if (!this.chatid)
return;
let payload;
if (type == 'text') {
payload = {
chatid: this.chatid,
mention,
payload: {
msgtype: 'text',
text: {
content: msg
}
}
};
}
else {
payload = {
chatid: this.chatid,
payload: {
msgtype: 'markdown',
markdown: {
content: msg
}
}
};
}
await this.sendRobotMsgInternal(payload);
}
async sendRobotMsgInternal(payload) {
const result = await axios.post('http://builder.fygame.com:3000/api/app/robotmsg', { data: payload }, { timeout: 3000, proxy: false }).catch((e) => { });
if (result?.data !== 'ok') {
console.error('robot msg sent failed:', payload);
}
}
}
//# sourceMappingURL=alert.wx.js.map