UNPKG

t-comm

Version:

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

190 lines (187 loc) 8.06 kB
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray'; import _regeneratorRuntime from '@babel/runtime/regenerator'; import { _ as __awaiter } from '../tslib.es6-848120af.js'; import { createMRComment, createMRNote } from '../lint/git.mjs'; import { genReportInfo } from '../lint/message.mjs'; import { T_GIT_BASE_URL } from '../tgit/helper.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 '../nodejs/child_process.mjs'; import '../nodejs/fs.mjs'; import '../nodejs/path.mjs'; import '../validate/validate.mjs'; import '../wecom-robot/base.mjs'; import '../wecom-robot/helper.mjs'; import '../wecom-robot/send-img.mjs'; import '../node-img/img.mjs'; import '../nodejs/crypto.mjs'; import '../nodejs/request.mjs'; function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; } function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } } function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } var genTitle = function genTitle(prefix, checkAll) { var name = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'LINT'; return "".concat(prefix, "\u3010").concat(name, "\u3011"); }; function genRobotMessage(_ref) { var errorFiles = _ref.errorFiles, workspace = _ref.workspace, mrUrl = _ref.mrUrl, sourceBranch = _ref.sourceBranch, targetBranch = _ref.targetBranch, repo = _ref.repo, repoUrl = _ref.repoUrl, checkAll = _ref.checkAll, buildUrl = _ref.buildUrl, docLink = _ref.docLink, mentionList = _ref.mentionList, _ref$postFixList = _ref.postFixList, postFixList = _ref$postFixList === void 0 ? [] : _ref$postFixList; var reportInfo = genReportInfo({ workspace: workspace, mrUrl: mrUrl, sourceBranch: sourceBranch, targetBranch: targetBranch, repo: repo, repoUrl: repoUrl, checkAll: checkAll }); if (!errorFiles.length) { return [genTitle('✅', checkAll, 'TS CHECK')].concat(_toConsumableArray(reportInfo), ['未发现代码规范异常'], _toConsumableArray(postFixList)).join(','); } return [[genTitle('⚠️', checkAll, 'TS CHECK')].concat(_toConsumableArray(reportInfo), ["\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.length ? mentionList.map(function (mention) { return "<@".concat(mention, ">"); }).join('') : ''], _toConsumableArray(postFixList || [])).filter(function (item) { return item; }).join(',')].join('\n'); } function checkTSErrorInMrOrAll(_ref2) { var privateToken = _ref2.privateToken, _ref2$gitApiPrefix = _ref2.gitApiPrefix, gitApiPrefix = _ref2$gitApiPrefix === void 0 ? T_GIT_BASE_URL : _ref2$gitApiPrefix, workspace = _ref2.workspace, repo = _ref2.repo, repoUrl = _ref2.repoUrl, mrId = _ref2.mrId, mrUrl = _ref2.mrUrl, sourceBranch = _ref2.sourceBranch, targetBranch = _ref2.targetBranch, checkAll = _ref2.checkAll, buildUrl = _ref2.buildUrl, docLink = _ref2.docLink, mentionList = _ref2.mentionList, postFixList = _ref2.postFixList, _ref2$chatId = _ref2.chatId, chatId = _ref2$chatId === void 0 ? ['ALL'] : _ref2$chatId, webhookUrl = _ref2.webhookUrl, command = _ref2.command; return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime.mark(function _callee() { var errorFiles, _iterator, _step, file, robotMessage, _t, _t2, _t3; return _regeneratorRuntime.wrap(function (_context) { while (1) switch (_context.prev = _context.next) { case 0: errorFiles = getTSErrorFiles({ root: workspace, command: command }); if (!(mrId && !checkAll)) { _context.next = 7; break; } _iterator = _createForOfIteratorHelper(errorFiles); _context.prev = 1; _iterator.s(); case 2: if ((_step = _iterator.n()).done) { _context.next = 4; break; } file = _step.value; _context.next = 3; return 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 3: _context.next = 2; break; case 4: _context.next = 6; break; case 5: _context.prev = 5; _t = _context["catch"](1); _iterator.e(_t); case 6: _context.prev = 6; _iterator.f(); return _context.finish(6); case 7: 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)) { _context.next = 11; break; } _context.prev = 8; _context.next = 9; return createMRComment({ projectName: repo, mrId: mrId, data: robotMessage, privateToken: privateToken, gitApiPrefix: gitApiPrefix }); case 9: _context.next = 11; break; case 10: _context.prev = 10; _t2 = _context["catch"](8); console.log('[createMRComment] err', _t2); case 11: _context.prev = 11; _context.next = 12; return batchSendWxRobotMarkdown({ content: robotMessage, chatId: chatId, webhookUrl: webhookUrl }); case 12: _context.next = 14; break; case 13: _context.prev = 13; _t3 = _context["catch"](11); console.log('[batchSendWxRobotMarkdown] err', _t3); case 14: return _context.abrupt("return", errorFiles); case 15: case "end": return _context.stop(); } }, _callee, null, [[1, 5, 6, 7], [8, 10], [11, 13]]); })); } export { checkTSErrorInMrOrAll };