t-comm
Version:
专业、稳定、纯粹的工具库
161 lines (156 loc) • 5.65 kB
JavaScript
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var tslib_es6 = require('../tslib.es6-01322ba9.js');
var lint_git = require('../lint/git.js');
var lint_message = require('../lint/message.js');
var wecomRobot_batchSend = require('../wecom-robot/batch-send.js');
var ts_tsError = require('./ts-error.js');
require('axios');
require('../git/git.js');
require('../node/node-command.js');
require('@babel/runtime/helpers/typeof');
require('../wecom-robot/base.js');
require('../wecom-robot/helper.js');
require('../wecom-robot/send-img.js');
require('../node-img/img.js');
var genTitle = function genTitle(prefix, checkAll, name) {
if (name === void 0) {
name = 'LINT';
}
return "".concat(prefix, "\u3010").concat(name, "\u3011");
};
function genRobotMessage(_a) {
var errorFiles = _a.errorFiles,
workspace = _a.workspace,
mrUrl = _a.mrUrl,
sourceBranch = _a.sourceBranch,
targetBranch = _a.targetBranch,
repo = _a.repo,
repoUrl = _a.repoUrl,
checkAll = _a.checkAll,
buildUrl = _a.buildUrl,
docLink = _a.docLink,
mentionList = _a.mentionList,
_b = _a.postFixList,
postFixList = _b === void 0 ? [] : _b;
var reportInfo = lint_message.genReportInfo({
workspace: workspace,
mrUrl: mrUrl,
sourceBranch: sourceBranch,
targetBranch: targetBranch,
repo: repo,
repoUrl: repoUrl,
checkAll: checkAll
});
if (!errorFiles.length) {
return tslib_es6.__spreadArray(tslib_es6.__spreadArray(tslib_es6.__spreadArray([genTitle('✅', checkAll, 'TS CHECK')], reportInfo, true), ['未发现代码规范异常'], false), postFixList, true).join(',');
}
return [tslib_es6.__spreadArray(tslib_es6.__spreadArray(tslib_es6.__spreadArray([genTitle('⚠️', checkAll, 'TS CHECK')], reportInfo, true), ["\u5171".concat(errorFiles.length, "\u4E2ATS\u7C7B\u578B\u9519\u8BEF"), "\u53EF\u5728[\u6D41\u6C34\u7EBF](".concat(buildUrl, ")\u4E2D\u67E5\u770B\u8BE6\u60C5\uFF0C\u6216\u672C\u5730\u8FD0\u884C `npx tsc --noEmit` \u7B49\u547D\u4EE4"), docLink ? "[\u8BF4\u660E\u6587\u6863](".concat(docLink, ")") : '', mentionList.map(function (mention) {
return "<@".concat(mention, ">");
}).join('')], false), postFixList || [], true).filter(function (item) {
return item;
}).join(',')].join('\n');
}
function checkTSErrorInMrOrAll(_a) {
var privateToken = _a.privateToken,
gitApiPrefix = _a.gitApiPrefix,
workspace = _a.workspace,
repo = _a.repo,
repoUrl = _a.repoUrl,
mrId = _a.mrId,
mrUrl = _a.mrUrl,
sourceBranch = _a.sourceBranch,
targetBranch = _a.targetBranch,
checkAll = _a.checkAll,
buildUrl = _a.buildUrl,
docLink = _a.docLink,
mentionList = _a.mentionList,
postFixList = _a.postFixList,
_b = _a.chatId,
chatId = _b === void 0 ? ['ALL'] : _b,
webhookUrl = _a.webhookUrl,
command = _a.command;
return tslib_es6.__awaiter(this, void 0, void 0, function () {
var errorFiles, _i, errorFiles_1, file, robotMessage, err_1, err_2;
return tslib_es6.__generator(this, function (_c) {
switch (_c.label) {
case 0:
errorFiles = ts_tsError.getTSErrorFiles({
root: workspace,
command: command
});
if (!(mrId && !checkAll)) return [3 /*break*/, 4];
_i = 0, errorFiles_1 = errorFiles;
_c.label = 1;
case 1:
if (!(_i < errorFiles_1.length)) return [3 /*break*/, 4];
file = errorFiles_1[_i];
return [4 /*yield*/, lint_git.createMRNote({
privateToken: privateToken,
gitApiPrefix: gitApiPrefix,
projectName: repo,
mrId: mrId,
body: "".concat(file.code ? "".concat(file.code, " - ") : '').concat(file.message) || '格式错误',
line: file.line,
path: file.file
})];
case 2:
_c.sent();
_c.label = 3;
case 3:
_i++;
return [3 /*break*/, 1];
case 4:
robotMessage = genRobotMessage({
errorFiles: errorFiles,
workspace: workspace,
mrUrl: mrUrl,
sourceBranch: sourceBranch,
targetBranch: targetBranch,
repo: repo,
repoUrl: repoUrl,
checkAll: checkAll,
buildUrl: buildUrl,
docLink: docLink,
mentionList: mentionList,
postFixList: postFixList
});
if (!(mrId && !checkAll)) return [3 /*break*/, 8];
_c.label = 5;
case 5:
_c.trys.push([5, 7,, 8]);
return [4 /*yield*/, lint_git.createMRComment({
projectName: repo,
mrId: mrId,
data: robotMessage,
privateToken: privateToken,
gitApiPrefix: gitApiPrefix
})];
case 6:
_c.sent();
return [3 /*break*/, 8];
case 7:
err_1 = _c.sent();
console.log('[createMRComment] err', err_1);
return [3 /*break*/, 8];
case 8:
_c.trys.push([8, 10,, 11]);
return [4 /*yield*/, wecomRobot_batchSend.batchSendWxRobotMarkdown({
content: robotMessage,
chatId: chatId,
webhookUrl: webhookUrl
})];
case 9:
_c.sent();
return [3 /*break*/, 11];
case 10:
err_2 = _c.sent();
console.log('[batchSendWxRobotMarkdown] err', err_2);
return [3 /*break*/, 11];
case 11:
return [2 /*return*/, errorFiles];
}
});
});
}
exports.checkTSErrorInMrOrAll = checkTSErrorInMrOrAll;