UNPKG

t-comm

Version:

专业、稳定、纯粹的工具库

157 lines (154 loc) 5.48 kB
import { b as __awaiter, c as __generator, a as __spreadArray } from '../tslib.es6-096fffdd.js'; import { createMRComment, createMRNote } from '../lint/git.mjs'; import { genReportInfo } from '../lint/message.mjs'; import { batchSendWxRobotMarkdown } from '../wecom-robot/batch-send.mjs'; import { getTSErrorFiles } from './ts-error.mjs'; import 'axios'; import '../git/git.mjs'; import '../node/node-command.mjs'; import '@babel/runtime/helpers/typeof'; import '../wecom-robot/base.mjs'; import '../wecom-robot/helper.mjs'; import '../wecom-robot/send-img.mjs'; import '../node-img/img.mjs'; 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 = genReportInfo({ workspace: workspace, mrUrl: mrUrl, sourceBranch: sourceBranch, targetBranch: targetBranch, repo: repo, repoUrl: repoUrl, checkAll: checkAll }); if (!errorFiles.length) { return __spreadArray(__spreadArray(__spreadArray([genTitle('✅', checkAll, 'TS CHECK')], reportInfo, true), ['未发现代码规范异常'], false), postFixList, true).join(','); } return [__spreadArray(__spreadArray(__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 __awaiter(this, void 0, void 0, function () { var errorFiles, _i, errorFiles_1, file, robotMessage, err_1, err_2; return __generator(this, function (_c) { switch (_c.label) { case 0: errorFiles = 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*/, 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*/, 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*/, 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]; } }); }); } export { checkTSErrorInMrOrAll };