From a53037e37421fc962f4f80e99ba9e82c984f38b3 Mon Sep 17 00:00:00 2001 From: renxia Date: Wed, 23 Oct 2024 15:04:54 +0800 Subject: [PATCH] =?UTF-8?q?wip:=20=E6=9B=B4=E6=96=B0=E5=86=85=E7=BD=AE?= =?UTF-8?q?=E7=9A=84=20jira=20=E6=8F=90=E4=BA=A4=E8=A7=84=E8=8C=83?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/node-ci.yml | 10 ++++++---- .github/workflows/npm-publish.yml | 8 ++++---- src/lint/jira-check.ts | 25 ++++++++++++++----------- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/.github/workflows/node-ci.yml b/.github/workflows/node-ci.yml index 2e0e2ac..88193ec 100644 --- a/.github/workflows/node-ci.yml +++ b/.github/workflows/node-ci.yml @@ -28,15 +28,17 @@ jobs: include: - node-version: 20 os: ubuntu-latest + - node-version: 22 + os: ubuntu-latest name: Node ${{ matrix.node-version }} on ${{ matrix.os }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: 'recursive' - - uses: pnpm/action-setup@v2.2.1 + - uses: pnpm/action-setup@v4 with: - version: 8 - - uses: actions/setup-node@v3 + version: 9 + - uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} # cache: 'pnpm' diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index a5c49b2..75dad8c 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -18,21 +18,21 @@ jobs: group: ${{ github.workflow }}-${{ github.ref }} steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: submodules: 'recursive' - name: Install Node.js - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: 20 registry-url: https://registry.npmjs.com - - uses: pnpm/action-setup@v2 + - uses: pnpm/action-setup@v4 name: Install pnpm id: pnpm-install with: - version: 8 + version: 9 run_install: false - name: Get pnpm store directory diff --git a/src/lint/jira-check.ts b/src/lint/jira-check.ts index 949d3e7..cc3358a 100644 --- a/src/lint/jira-check.ts +++ b/src/lint/jira-check.ts @@ -2,7 +2,7 @@ * @Author: lzw * @Date: 2021-08-15 22:39:01 * @LastEditors: renxia - * @LastEditTime: 2024-04-10 10:55:59 + * @LastEditTime: 2024-10-23 14:57:12 * @Description: Jira check */ @@ -18,6 +18,7 @@ import type { AnyObject } from '../types'; import type { JiraCheckConfig, JiraCheckResult, JiraError, JiraReqConfig, JiraIssueItem } from '../types/jira.js'; import { LintBase } from './LintBase.js'; import { shouldIgnoreCommitLint } from './commit-lint.js'; +import { pathToFileURL } from 'node:url'; export class JiraCheck extends LintBase { private reqeust: Request; @@ -60,9 +61,11 @@ export class JiraCheck extends LintBase { if (jiraPath) { type JCType = (JiraReqConfig & { default?: JiraReqConfig }) | (() => Promise); - let jiraConfig: JCType = jiraPath.endsWith('.json') ? readJsonFileSync(jiraPath) : await import(jiraPath); + let jiraConfig: JCType = jiraPath.endsWith('.json') + ? readJsonFileSync(jiraPath) + : await import(pathToFileURL(jiraPath).href); + if ('default' in jiraConfig) jiraConfig = jiraConfig.default; if (typeof jiraConfig === 'function') jiraConfig = await jiraConfig(); - if (jiraConfig.default) Object.assign(jiraConfig, jiraConfig.default); if (jiraConfig.cookie) headers.cookie = jiraConfig.cookie; if (jiraConfig.JSESSIONID && !headers.cookie.includes('JSESSIONID=')) { headers.cookie += `;JSESSIONID=${jiraConfig.JSESSIONID}`; @@ -113,7 +116,7 @@ export class JiraCheck extends LintBase { await this.initRequest(); const result = await this.reqeust.get(url); if (!Array.isArray(result.data)) { - this.logger.warn('获取 issuetype 列表异常:', result.data || result.headers); + this.logger.warn('获取 issuetype 列表异常:', String(result.data).trim().slice(0, 300) || result.headers); return []; } @@ -331,9 +334,9 @@ export class JiraCheck extends LintBase { logger.info('='.repeat(40)); if (jiraIDs) { - /** 智能匹配正则表达式,commit覆盖, JIRA号后需要输入至少一个中文、【|[、英文或者空格进行隔开 例子: JGCPS-1234测试提交123 或 [JGCPS-1234] 测试提交123 => [ET][2.9.1][feature][JGCPS-1234]测试提交123 */ - const smartRegWithMessage = new RegExp(`^\\[?${issuePrefix}\\d+\\]?([A-Za-z\\u4e00-\\u9fa5\\s【\\[]+.+)`); - /** 智能匹配正则表达式,单纯匹配jira 例子: JGCPS-1234 或 [JGCPS-1234] => [ET][2.9.1][feature][JGCPS-1234]JIRA本身的标题 */ + /** 智能匹配正则表达式,commit覆盖, JIRA号后需要输入至少一个中文、【|[、英文或者空格进行隔开 例子: JGCPS-1234测试提交123 或 [JGCPS-1234] 测试提交123 => JGCPS-1234 [ET][2.9.1][feature]测试提交123 */ + const smartRegWithMessage = new RegExp(`^\\[?${issuePrefix}\\d+\\]?\\s*([A-Za-z\\u4e00-\\u9fa5\\s【\\[]+.+)`); + /** 智能匹配正则表达式,单纯匹配jira 例子: JGCPS-1234 或 [JGCPS-1234] => JGCPS-1234 [ET][2.9.1][feature]JIRA本身的标题 */ const smartRegWithJIRA = new RegExp(`^\\[?${issuePrefix}(\\d+)\\]?`, 'g'); const issueTypeList = await this.getIssueType(); /** 禁止提交的类型 */ @@ -391,23 +394,23 @@ export class JiraCheck extends LintBase { } const issueText = issueTypeToDesc[issuetype] || 'feature'; // 如果是其他类型,默认feature - const reg = new RegExp(`^${config.commitMsgPrefix.replace(/([.[-])/g, '\\$1')}\\[${versionName}]\\[${issueText}]\\[${jiraID}]`); + const reg = new RegExp(`^$${jiraID} ${config.commitMsgPrefix.replace(/([.[-])/g, '\\$1')}\\[${versionName}]\\[${issueText}]`); smartCommit = commitMessage; // 如果匹配到commit中包含中文,则保留提交信息 if (smartRegWithMessage.test(commitMessage)) { // 如果用户需要手动填入commit信息 const message = commitMessage.match(smartRegWithMessage)[1].trim(); - smartCommit = `${config.commitMsgPrefix}[${versionName}][${issueText}][${jiraID}] ${message}`; + smartCommit = `${jiraID} ${config.commitMsgPrefix}[${versionName}][${issueText}] ${message}`; } else if (smartRegWithJIRA.test(commitMessage)) { // 如果只匹配到JIRA号 - smartCommit = `${config.commitMsgPrefix}[${versionName}][${issueText}][${jiraID}] ${summary as string}`; + smartCommit = `${jiraID} ${config.commitMsgPrefix}[${versionName}][${issueText}] ${summary as string}`; } else if (!reg.test(commitMessage)) { // 如果都是自己填的 logger.debug(reg, commitMessage, reg.test(commitMessage)); logger.error('commit 格式校验不通过,请参考正确提交格式'); logger.log('=================== Example ==================='); - logger.log(greenBright(`${config.commitMsgPrefix}[${versionName}][${issueText}][${jiraID}] 描述问题或改进`)); + logger.log(greenBright(`${jiraID} ${config.commitMsgPrefix}[${versionName}][${issueText}] 描述问题或改进`)); logger.log('=================== Example ==================='); return result; }