Skip to content

Commit

Permalink
fix(notify): bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Airkro committed Dec 15, 2023
1 parent ae76298 commit 463cf7a
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 28 deletions.
48 changes: 41 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bring-it/cli",
"version": "0.8.0",
"version": "0.8.1",
"description": "Common command line interface of 'bring-it'",
"license": "MIT",
"author": {
Expand Down
4 changes: 2 additions & 2 deletions packages/notify/lib/action.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ export async function action({ mode }) {

dingtalk({
markdown: createContent(all),
title: all.project || 'bring-it',
title: all.project || '版本发布通知',
token: DingTalkRobotToken,
})
.then((resp) => {
logger.okay(resp.status);
logger.okay(resp);
})
.catch((error) => {
console.error(error);
Expand Down
44 changes: 33 additions & 11 deletions packages/notify/lib/utils.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { toMarkdown } from 'mdast-util-to-markdown';
import semverPrerelease from 'semver/functions/prerelease.js';

import { http } from '@bring-it/utils/index.mjs';

const unknown = '未知';

const {
BRANCH_NAME,
CCI_JOB_NAME,
Expand All @@ -13,7 +12,7 @@ const {
GIT_COMMIT,
GIT_HTTP_URL,
JOB_ID,
npm_package_version,
npm_package_version = '未知',
PROJECT_NAME,
PROJECT_WEB_URL,
} = process.env;
Expand All @@ -38,22 +37,41 @@ export function dingtalk({ markdown, title, token }) {
});
}

export function createContent({ project = '未命名项目', type, manual = true }) {
function isTest() {
return BRANCH_NAME !== 'master' || semverPrerelease(npm_package_version);
}

export function createContent({
project = '未命名项目',
type,
manual = true,
banner,
isLatest = false,
}) {
return toMarkdown({
type: 'root',
children: [
CCI_JOB_NAME
banner
? {
type: 'heading',
depth: 3,
type: 'paragraph',
children: [
{
type: 'text',
value: CCI_JOB_NAME,
type: 'image',
url: banner,
},
],
}
: undefined,
{
type: 'heading',
depth: 3,
children: [
{
type: 'text',
value: CCI_JOB_NAME || '自动化任务',
},
],
},
{
type: 'paragraph',
children: [
Expand Down Expand Up @@ -115,7 +133,11 @@ export function createContent({ project = '未命名项目', type, manual = true
children: [
{
type: 'text',
value: `版本编号:${npm_package_version || unknown}`,
value: `版本编号:${
isLatest
? ['latest', npm_package_version].join(' / ')
: npm_package_version
}`,
},
],
},
Expand All @@ -135,7 +157,7 @@ export function createContent({ project = '未命名项目', type, manual = true
children: [
{
type: 'text',
value: BRANCH_NAME === 'master' ? '外部正式' : '内部测试',
value: isTest() ? '内部测试' : '外部正式',
},
],
},
Expand Down
5 changes: 3 additions & 2 deletions packages/notify/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bring-it/notify",
"version": "0.1.2",
"version": "0.1.3",
"description": "Send releases notifications",
"license": "MIT",
"author": {
Expand Down Expand Up @@ -36,7 +36,8 @@
"prepublishOnly": "npm run build"
},
"devDependencies": {
"mdast-util-to-markdown": "^2.1.0"
"mdast-util-to-markdown": "^2.1.0",
"semver": "^7.5.4"
},
"peerDependencies": {
"@bring-it/cli": "^0.8.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/npm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bring-it/npm",
"version": "0.4.0",
"version": "0.4.1",
"description": "Publish npm packages when needed",
"license": "MIT",
"author": {
Expand Down
2 changes: 1 addition & 1 deletion packages/sample/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bring-it/sample",
"version": "0.3.0",
"version": "0.3.1",
"description": "Generate code sample files",
"license": "MIT",
"author": {
Expand Down
2 changes: 1 addition & 1 deletion packages/sentry/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bring-it/sentry",
"version": "0.3.0",
"version": "0.3.1",
"description": "Update sentry artifacts",
"license": "MIT",
"author": {
Expand Down
2 changes: 1 addition & 1 deletion packages/sftp/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bring-it/sftp",
"version": "0.2.0",
"version": "0.2.1",
"description": "SFTP deployment tool for frontend",
"license": "MIT",
"author": {
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,5 @@ export function http({ url, query, json, method = 'GET' }) {
'Content-Type': 'application/json',
},
body: JSON.stringify(json),
});
}).then((response) => response.json());
}

0 comments on commit 463cf7a

Please sign in to comment.