UNPKG

t-comm

Version:

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

102 lines (99 loc) 4.02 kB
import { a as __spreadArray, _ as __assign } from '../tslib.es6-096fffdd.js'; var DISABLE_STATUS = [100, -1]; function isWhiteProject(whiteList, codeUrl) { if (codeUrl === void 0) { codeUrl = ''; } var projectName = getWholeProjectName(codeUrl); if (whiteList.includes(projectName)) return true; return false; } function getWholeProjectName(codeUrl) { if (codeUrl === void 0) { codeUrl = ''; } var reg = /https?:\/\/[\w\-.]+\/([/\w-]+)(.git)?/; var match = codeUrl.match(reg); return (match === null || match === void 0 ? void 0 : match[1]) || codeUrl; } function parseOpenSourceReport(_a) { var reportArr = _a.reportArr, date = _a.date, formattedDate = _a.formattedDate, searchInfo = _a.searchInfo, requestInfo = _a.requestInfo, _b = _a.maxShowLinkNum, maxShowLinkNum = _b === void 0 ? 0 : _b, _c = _a.whiteList, whiteList = _c === void 0 ? [] : _c, _d = _a.filterOrgPath, filterOrgPath = _d === void 0 ? '' : _d; var problemArr = reportArr.filter(function (item) { return !DISABLE_STATUS.includes(item.code_specification_score) || !DISABLE_STATUS.includes(item.code_security_score); }).filter(function (item) { return !isWhiteProject(whiteList, item.code_url); }).filter(function (item) { return !filterOrgPath || filterOrgPath === item.org_path; }).sort(function (a, b) { var aSpec = a.code_specification_score; var aSecurity = a.code_security_score; var bSpec = b.code_specification_score; var bSecurity = b.code_security_score; var getScore = function getScore(score) { return DISABLE_STATUS.indexOf(score) > -1 ? 100 : score; }; return getScore(aSpec) + getScore(aSecurity) - (getScore(bSpec) + getScore(bSecurity)); }); if (!problemArr.length) { console.log('[parseOpenSourceReport] Error: 没有开源治理问题数据'); // 没问题时也返回数据 // return; } var list = problemArr.reduce(function (acc, item, index) { var temp = []; if (!DISABLE_STATUS.includes(item.code_specification_score)) { temp.push("\u89C4\u8303: ".concat(parseInt("".concat(item.code_specification_score), 10), "\u5206")); } if (!DISABLE_STATUS.includes(item.code_security_score)) { temp.push("\u5B89\u5168: ".concat(parseInt("".concat(item.code_security_score), 10), "\u5206")); } var _a = item.owners, owners = _a === void 0 ? '' : _a; temp.push(owners.split(';').map(function (item) { return "<@".concat(item, ">"); })); var showProject = "[".concat(item.project_name, "](").concat(item.codecc_url, ")"); if (index < maxShowLinkNum) { acc.push("".concat(index + 1, ". ").concat(showProject, ": ").concat(temp.join(', '))); } else if (index === maxShowLinkNum) { acc.push("... \u5DF2\u7701\u7565".concat(problemArr.length - maxShowLinkNum, "\u6761 ...")); } else ; return acc; }, []); if (!reportArr.length && !list.length) { list.push('抱歉,未拉取到数据~'); } else if (!list.length) { list.push('恭喜,暂未发现问题,请继续保持 🚀'); } var chatContent = __spreadArray([">\u3010".concat((requestInfo === null || requestInfo === void 0 ? void 0 : requestInfo.groupName) || (requestInfo === null || requestInfo === void 0 ? void 0 : requestInfo.centerName) || '', "\u5F00\u6E90\u6CBB\u7406\u95EE\u9898\u3011[").concat(formattedDate, "](").concat(getTechMapWebsiteUrl(date, searchInfo), ")")], list, true); return chatContent.join('\n'); } function getTechMapWebsiteUrl(date, searchInfo) { if (searchInfo === void 0) { searchInfo = { prefix: '' }; } var data = __assign({ org: 0, step: 'days', period_type: 'date', data_date: "".concat(date), displayGroup: ['sum'], compare: false, sort_column: 'code_specification_score', sort_direction: 'asc' }, searchInfo || {}); return "".concat(searchInfo.prefix).concat(encodeURIComponent(JSON.stringify(data))); } export { parseOpenSourceReport };