From 463cf7a16a2f1fd0591baf75b364d29a7e555772 Mon Sep 17 00:00:00 2001 From: Eric Date: Fri, 15 Dec 2023 19:26:28 +0800 Subject: [PATCH] fix(notify): bug --- package-lock.json | 48 +++++++++++++++++++++++++++++----- packages/cli/package.json | 2 +- packages/notify/lib/action.mjs | 4 +-- packages/notify/lib/utils.mjs | 44 +++++++++++++++++++++++-------- packages/notify/package.json | 5 ++-- packages/npm/package.json | 2 +- packages/sample/package.json | 2 +- packages/sentry/package.json | 2 +- packages/sftp/package.json | 2 +- packages/utils/index.mjs | 2 +- 10 files changed, 85 insertions(+), 28 deletions(-) diff --git a/package-lock.json b/package-lock.json index 3dae2ed..faae577 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6834,7 +6834,7 @@ }, "packages/cli": { "name": "@bring-it/cli", - "version": "0.8.0", + "version": "0.8.1", "license": "MIT", "dependencies": { "globby": "^14.0.0", @@ -6854,10 +6854,11 @@ }, "packages/notify": { "name": "@bring-it/notify", - "version": "0.1.2", + "version": "0.1.3", "license": "MIT", "devDependencies": { - "mdast-util-to-markdown": "^2.1.0" + "mdast-util-to-markdown": "^2.1.0", + "semver": "^7.5.4" }, "engines": { "node": "^18.0.0 || ^20.0.0", @@ -6867,9 +6868,42 @@ "@bring-it/cli": "^0.8.0" } }, + "packages/notify/node_modules/lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dev": true, + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "packages/notify/node_modules/semver": { + "version": "7.5.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", + "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", + "dev": true, + "dependencies": { + "lru-cache": "^6.0.0" + }, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "packages/notify/node_modules/yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", + "dev": true + }, "packages/npm": { "name": "@bring-it/npm", - "version": "0.4.0", + "version": "0.4.1", "license": "MIT", "devDependencies": { "execa": "^8.0.1", @@ -6921,7 +6955,7 @@ }, "packages/sample": { "name": "@bring-it/sample", - "version": "0.3.0", + "version": "0.3.1", "license": "MIT", "dependencies": { "globby": "^14.0.0" @@ -6935,7 +6969,7 @@ }, "packages/sentry": { "name": "@bring-it/sentry", - "version": "0.3.0", + "version": "0.3.1", "license": "MIT", "dependencies": { "globby": "^14.0.0" @@ -6950,7 +6984,7 @@ }, "packages/sftp": { "name": "@bring-it/sftp", - "version": "0.2.0", + "version": "0.2.1", "license": "MIT", "dependencies": { "globby": "^14.0.0" diff --git a/packages/cli/package.json b/packages/cli/package.json index 45555a6..b0d84ad 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -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": { diff --git a/packages/notify/lib/action.mjs b/packages/notify/lib/action.mjs index 8149c35..85fe165 100644 --- a/packages/notify/lib/action.mjs +++ b/packages/notify/lib/action.mjs @@ -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); diff --git a/packages/notify/lib/utils.mjs b/packages/notify/lib/utils.mjs index f4d4819..ae92a7f 100644 --- a/packages/notify/lib/utils.mjs +++ b/packages/notify/lib/utils.mjs @@ -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, @@ -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; @@ -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: [ @@ -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 + }`, }, ], }, @@ -135,7 +157,7 @@ export function createContent({ project = '未命名项目', type, manual = true children: [ { type: 'text', - value: BRANCH_NAME === 'master' ? '外部正式' : '内部测试', + value: isTest() ? '内部测试' : '外部正式', }, ], }, diff --git a/packages/notify/package.json b/packages/notify/package.json index d0d2285..d8cc572 100644 --- a/packages/notify/package.json +++ b/packages/notify/package.json @@ -1,6 +1,6 @@ { "name": "@bring-it/notify", - "version": "0.1.2", + "version": "0.1.3", "description": "Send releases notifications", "license": "MIT", "author": { @@ -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" diff --git a/packages/npm/package.json b/packages/npm/package.json index c0ffec5..02c82ab 100644 --- a/packages/npm/package.json +++ b/packages/npm/package.json @@ -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": { diff --git a/packages/sample/package.json b/packages/sample/package.json index e835a0e..54e03e4 100644 --- a/packages/sample/package.json +++ b/packages/sample/package.json @@ -1,6 +1,6 @@ { "name": "@bring-it/sample", - "version": "0.3.0", + "version": "0.3.1", "description": "Generate code sample files", "license": "MIT", "author": { diff --git a/packages/sentry/package.json b/packages/sentry/package.json index 1fde8b7..e104874 100644 --- a/packages/sentry/package.json +++ b/packages/sentry/package.json @@ -1,6 +1,6 @@ { "name": "@bring-it/sentry", - "version": "0.3.0", + "version": "0.3.1", "description": "Update sentry artifacts", "license": "MIT", "author": { diff --git a/packages/sftp/package.json b/packages/sftp/package.json index 39968e6..5d21c61 100644 --- a/packages/sftp/package.json +++ b/packages/sftp/package.json @@ -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": { diff --git a/packages/utils/index.mjs b/packages/utils/index.mjs index bde3ede..87e7f52 100644 --- a/packages/utils/index.mjs +++ b/packages/utils/index.mjs @@ -87,5 +87,5 @@ export function http({ url, query, json, method = 'GET' }) { 'Content-Type': 'application/json', }, body: JSON.stringify(json), - }); + }).then((response) => response.json()); }