Skip to content

Commit

Permalink
feat(notify): subscribe
Browse files Browse the repository at this point in the history
  • Loading branch information
Airkro committed Dec 22, 2023
1 parent 602aeeb commit b690954
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 27 deletions.
40 changes: 21 additions & 19 deletions packages/notify/lib/action.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,40 @@ 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);

const all = { ...rest, ...config };

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);
Expand Down
19 changes: 12 additions & 7 deletions packages/notify/lib/utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -49,7 +47,7 @@ export function dingtalk({ markdown, title, token }) {
json: {
msgtype: 'markdown',
markdown: {
title,
title: '版本发布通知',
text: markdown
.split('更新历史:')
.map((text, i) =>
Expand All @@ -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() {
Expand All @@ -82,15 +87,15 @@ const configs = {
order: 2,
},
refactor: {
label: '重构',
label: '代码重构',
order: 3,
},
revert: {
label: '回滚',
order: 4,
},
chore: {
label: '杂项',
label: '其他杂项',
order: 5,
},
style: {
Expand Down
2 changes: 1 addition & 1 deletion packages/notify/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bring-it/notify",
"version": "0.2.8",
"version": "0.2.9",
"description": "Send releases notifications",
"license": "MIT",
"author": {
Expand Down

0 comments on commit b690954

Please sign in to comment.