t-comm
Version:
专业、稳定、纯粹的工具库
134 lines (131 loc) • 4.29 kB
JavaScript
import { a as __spreadArray } from '../tslib.es6-096fffdd.js';
import { timeStampFormat } from '../time/time.mjs';
import { parseRobotMessage, genRobotMessage } from '../wecom-robot/message.mjs';
import { EMOJI_MAP } from './config.mjs';
var TRIGGER_MAP = {
MANUAL: '手动',
TIME_TRIGGER: '定时',
WEB_HOOK: 'WebHook',
SERVICE: '内部服务',
PIPELINE: '子流水线',
REMOTE: '远程'
};
function getStartTypeDesc(data) {
var bkStartType = data.bkStartType;
var content = '';
if (bkStartType && TRIGGER_MAP[bkStartType]) {
content = TRIGGER_MAP[bkStartType];
} else if (bkStartType) {
content = bkStartType;
}
if (content) {
return [{
content: content,
label: '触发方式'
}];
}
return [];
}
function getFailedTestUnits(_a) {
var passes = _a.passes,
tests = _a.tests,
testList = _a.testList;
if (passes == tests) return {};
if (!(testList === null || testList === void 0 ? void 0 : testList.length)) return {};
var failedTests = testList.filter(function (item) {
return !!item.fail;
});
var failTestTitles = failedTests.map(function (item) {
return item.title;
});
if (!(failTestTitles === null || failTestTitles === void 0 ? void 0 : failTestTitles.length)) return {};
return {
errorTitle: "\u5931\u8D25\uFF1A".concat(failTestTitles.join('、')),
errorDetail: getFailedDetail(failedTests)
};
}
function getFailedDetail(failedTests) {
return failedTests.map(function (item) {
var errMsg = (item.err.estack || '').replace(/[\n]+/g, '; ');
return "".concat(item.title, ": ").concat(errMsg);
}).filter(function (item) {
return item;
});
}
function getE2ETestRobotMessage(data, notificationList) {
var _a;
if (notificationList === void 0) {
notificationList = [];
}
var start = data.start,
duration = data.duration,
passes = data.passes,
tests = data.tests,
_b = data.projectLink,
projectLink = _b === void 0 ? '' : _b,
_c = data.checkUrl,
checkUrl = _c === void 0 ? '' : _c,
_d = data.name,
name = _d === void 0 ? '' : _d,
_e = data.comment,
comment = _e === void 0 ? '' : _e,
_f = data.fileList,
fileList = _f === void 0 ? [] : _f;
var hasFailed = passes !== tests;
var time = timeStampFormat(new Date(start).getTime(), 'MM-dd hh:mm:ss');
var title = ">".concat(hasFailed ? EMOJI_MAP.FAIL : EMOJI_MAP.PASS, "\u3010\u81EA\u52A8\u5316\u6D4B\u8BD5\u3011");
var errorDetailList = [];
var messageList = [__spreadArray(__spreadArray(["".concat(title).concat(parseRobotMessage({
content: "".concat(name, "-").concat(comment),
link: projectLink
})), {
content: "".concat(passes, "/").concat(tests),
label: '成功/全部'
}, {
content: "".concat(Math.ceil(duration / 1000), "s"),
label: '耗时'
}], getStartTypeDesc(data), true), [{
content: time,
link: checkUrl
}], false)];
if (hasFailed) {
(_a = messageList[0]).push.apply(_a, notificationList.map(function (item) {
return "<@".concat(item, ">");
}));
}
var fileMessageList = (fileList || []).filter(function (fileInfo) {
var tests = fileInfo.tests,
passes = fileInfo.passes;
return tests !== passes;
}).map(function (fileInfo) {
var _a;
var file = fileInfo.file,
tests = fileInfo.tests,
passes = fileInfo.passes,
link = fileInfo.link,
testList = fileInfo.testList;
var fileName = parseRobotMessage({
content: file,
link: link
});
var failedInfo = getFailedTestUnits({
testList: testList,
passes: passes,
tests: tests
});
if ((_a = failedInfo.errorDetail) === null || _a === void 0 ? void 0 : _a.length) {
errorDetailList.push(['\n']);
errorDetailList.push(failedInfo.errorDetail);
}
return ["- ".concat(fileName), "".concat(passes, "/").concat(tests), (failedInfo === null || failedInfo === void 0 ? void 0 : failedInfo.errorTitle) || ''];
});
messageList.push.apply(messageList, fileMessageList);
messageList.push.apply(messageList, ['\n', '\n']);
messageList.push.apply(messageList, errorDetailList);
return {
message: genRobotMessage(messageList),
start: start,
hasFailed: hasFailed
};
}
export { TRIGGER_MAP, getE2ETestRobotMessage };