diff --git a/packages/notify/lib/action.mjs b/packages/notify/lib/action.mjs index ffd734b..8ebae51 100644 --- a/packages/notify/lib/action.mjs +++ b/packages/notify/lib/action.mjs @@ -10,14 +10,6 @@ const { DingTalkRobotToken } = process.env; // eslint-disable-next-line consistent-return export async function action({ mode }) { - if (!DingTalkRobotToken) { - logger.fail('env.DingTalkRobotToken is required'); - - process.exitCode = -1; - - return false; - } - try { const { [mode]: config, ...rest } = await readConfig(task, logger); @@ -25,23 +17,33 @@ export async function action({ mode }) { logger.json({ mode, ...all }); + if (!(DingTalkRobotToken || all.subscribe?.length)) { + logger.fail('env.DingTalkRobotToken or config.subscribe is required'); + + return false; + } + const { markdown, levels } = createContent(all); logger.json({ levels }); if (markdown) { - dingtalk({ - markdown, - title: all.project || '版本发布通知', - token: DingTalkRobotToken, - }) - .then((resp) => { - logger.okay(resp); - }) - .catch((error) => { - console.error(error); - process.exitCode = 1; + if (all.subscribe?.length) { + for (const { DingTalkRobotToken: token, levels: lv } of all.subscribe) { + if ( + token && + lv?.length && + levels.some((level) => lv.includes(level)) + ) { + dingtalk({ markdown, token }); + } + } + } else { + dingtalk({ + markdown, + token: DingTalkRobotToken, }); + } } } catch (error) { logger.fail(error.message); diff --git a/packages/notify/lib/utils.mjs b/packages/notify/lib/utils.mjs index 63cf8d7..b61b699 100644 --- a/packages/notify/lib/utils.mjs +++ b/packages/notify/lib/utils.mjs @@ -37,9 +37,7 @@ function getVersion({ isLatest, version }) { return isLatest ? ['latest', name].join(' / ') : name; } -export function dingtalk({ markdown, title, token }) { - console.log({ title }); - +export function dingtalk({ markdown, token }) { console.log(markdown); return http({ @@ -49,7 +47,7 @@ export function dingtalk({ markdown, title, token }) { json: { msgtype: 'markdown', markdown: { - title, + title: '版本发布通知', text: markdown .split('更新历史:') .map((text, i) => @@ -61,7 +59,14 @@ export function dingtalk({ markdown, title, token }) { .trim(), }, }, - }); + }) + .then((resp) => { + console.log(resp); + }) + .catch((error) => { + console.error(error); + process.exitCode = 1; + }); } function isTest() { @@ -82,7 +87,7 @@ const configs = { order: 2, }, refactor: { - label: '重构', + label: '代码重构', order: 3, }, revert: { @@ -90,7 +95,7 @@ const configs = { order: 4, }, chore: { - label: '杂项', + label: '其他杂项', order: 5, }, style: { diff --git a/packages/notify/package.json b/packages/notify/package.json index 9cb25d1..1a3e98b 100644 --- a/packages/notify/package.json +++ b/packages/notify/package.json @@ -1,6 +1,6 @@ { "name": "@bring-it/notify", - "version": "0.2.8", + "version": "0.2.9", "description": "Send releases notifications", "license": "MIT", "author": {