UNPKG

t-comm

Version:

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

72 lines (69 loc) 2.6 kB
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray'; import { getMentionRtx } from '../rtx/mention.mjs'; import 'axios'; /** * 构建审核通知内容数组 * * 统一拼接审核通知消息,各流水线只需传入标题和差异化字段即可。 * * @example H5 发布 * ```ts * const content = buildAuditContent({ * title: '【H5发布审核】', * projectName: 'pmd-mobile/match/gp', * creator: 'novlan1', * auditor: 'junshao', * buildUrl: 'https://devops.woa.com/xxx', * extraLines: [ * `子工程:\`gp-hor\``, * `灰度比例:50%`, * ], * }); * ``` * * @example 回滚审核 * ```ts * const content = buildAuditContent({ * title: '【`回滚`审核】', * projectName: 'pmd-mobile/match/gp', * creator: 'novlan1', * auditor: 'junshao', * buildUrl: 'https://devops.woa.com/xxx', * extraLines: [`子工程:\`gp-hor\``], * }); * ``` */ function buildAuditContent(options) { var title = options.title, projectName = options.projectName, creator = options.creator, auditor = options.auditor, buildUrl = options.buildUrl, _options$extraLines = options.extraLines, extraLines = _options$extraLines === void 0 ? [] : _options$extraLines; var auditorStr = getMentionRtx(auditor || ''); var titleLine = projectName ? "".concat(title, "\u9879\u76EE\uFF1A`").concat(projectName, "`") : title; return [titleLine].concat(_toConsumableArray(extraLines), ["\u53D1\u8D77\u4EBA\uFF1A<@".concat(creator, ">"), "\u5BA1\u6838\u4EBA\uFF1A".concat(auditorStr), "[".concat(buildUrl, "](").concat(buildUrl, ")")]); } /** * 从审核意见中提取真实审核人 * * 当审核由 pmd-mcp 等自动化工具代为操作时,审核意见中会携带真实审核人信息, * 格式为 "by pmd-mcp, from novlan1)",此函数提取其中的真实用户名。 * * @param suggest - 审核意见字符串 * @returns 提取到的审核人用户名,未匹配则返回空字符串 * * @example * ```ts * getReviewerFromSuggest('by pmd-mcp, from novlan1)') // => 'novlan1' * getReviewerFromSuggest('by pmd-mcp, from novlan1') // => 'novlan1' * getReviewerFromSuggest('LGTM') // => '' * getReviewerFromSuggest('') // => '' * ``` */ function getReviewerFromSuggest(suggest) { var match = suggest === null || suggest === void 0 ? void 0 : suggest.match(/from\s+([a-zA-Z0-9_]+)\s*\)?/); return (match === null || match === void 0 ? void 0 : match[1]) || ''; } export { buildAuditContent, getReviewerFromSuggest };