From 828c134ce26bcc87b45186a0f7aff72462a884b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=8E=E4=BC=9F=E6=9D=B0?= <674416404@qq.com> Date: Mon, 12 Aug 2024 21:09:20 +0800 Subject: [PATCH 01/22] test(ChangelogReg): test case --- src/renderer.ts | 6 +-- test/__snapshots__/renderer.test.ts.snap | 48 ++++++++++++++++++++++++ test/renderer.test.ts | 19 ++++++++++ 3 files changed, 69 insertions(+), 4 deletions(-) create mode 100644 test/__snapshots__/renderer.test.ts.snap create mode 100644 test/renderer.test.ts diff --git a/src/renderer.ts b/src/renderer.ts index 4d6c451..8a2517b 100644 --- a/src/renderer.ts +++ b/src/renderer.ts @@ -5,7 +5,7 @@ const skipChangelogLabel = ['skip-changelog'] const fixLabel = ['fix', 'bug', 'hotfix'] const breakingLabel = ['break', 'breaking', 'breaking changes'] const featureLabel = ['feature', 'feat', 'enhancement'] - +export const ChangelogReg = /-\s([A-Z]+)(?:\(([A-Z]*)\))?:\s(.+)/gi export function getPReformatNotes(body: string) { const reg = /in\shttps:\/\/github\.com\/.+\/pull\/(\d+)\s/g @@ -53,9 +53,7 @@ export function renderMarkdown(pullRequestList: PullsData[]) { } if (pr.body.includes('### 📝 更新日志')) { - const reg = /-\s([A-Z]+)\(([A-Z]+)\):\s(.+)/gi - - const arr = [...pr.body.matchAll(reg)] + const arr = [...pr.body.matchAll(ChangelogReg)] if (arr.length === 0) { info(`没有找到任何一条日志内容 number:${pr.number}, body:${pr.body}`) diff --git a/test/__snapshots__/renderer.test.ts.snap b/test/__snapshots__/renderer.test.ts.snap new file mode 100644 index 0000000..74a9bf0 --- /dev/null +++ b/test/__snapshots__/renderer.test.ts.snap @@ -0,0 +1,48 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`renderer > changelogReg 1`] = ` +[ + [ + "- A(A): a bug fix", + "A", + "A", + "a bug fix", + ], + [ + "- B(B): a feature", + "B", + "B", + "a feature", + ], + [ + "- C(C): a bug fix", + "C", + "C", + "a bug fix", + ], + [ + "- D(D): a feature", + "D", + "D", + "a feature", + ], + [ + "- E(): a bug fix", + "E", + "", + "a bug fix", + ], + [ + "- F: a bug fix", + "F", + undefined, + "a bug fix", + ], + [ + "- g(g): a minor fix", + "g", + "g", + "a minor fix", + ], +] +`; diff --git a/test/renderer.test.ts b/test/renderer.test.ts new file mode 100644 index 0000000..808ef30 --- /dev/null +++ b/test/renderer.test.ts @@ -0,0 +1,19 @@ +import { assert, describe, expect, it } from 'vitest' +import { ChangelogReg } from '../src/renderer' + +describe('renderer', () => { + it('changelogReg', () => { + const changelog = ` +- A(A): a bug fix +- B(B): a feature +- C(C): a bug fix +- D(D): a feature +- E(): a bug fix +- F: a bug fix +- g(g): a minor fix +- H(H H): a major update +` + const result = changelog.matchAll(ChangelogReg) + expect([...result]).toMatchSnapshot() + }) +}) From 62d165a86846b4d6cf8c64aaf8b8199b196d7ac1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=8E=E4=BC=9F=E6=9D=B0?= <674416404@qq.com> Date: Mon, 12 Aug 2024 21:11:49 +0800 Subject: [PATCH 02/22] chore: fix lint --- test/renderer.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/renderer.test.ts b/test/renderer.test.ts index 808ef30..550a36e 100644 --- a/test/renderer.test.ts +++ b/test/renderer.test.ts @@ -1,4 +1,4 @@ -import { assert, describe, expect, it } from 'vitest' +import { describe, expect, it } from 'vitest' import { ChangelogReg } from '../src/renderer' describe('renderer', () => { From b41469d179398a4f13144fc1503e1bae59ba1126 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=8E=E4=BC=9F=E6=9D=B0?= <674416404@qq.com> Date: Mon, 12 Aug 2024 21:18:59 +0800 Subject: [PATCH 03/22] test(ChangelogReg): test case --- test/__snapshots__/renderer.test.ts.snap | 58 ++++++++++++++++++------ test/renderer.test.ts | 21 +++++---- 2 files changed, 57 insertions(+), 22 deletions(-) diff --git a/test/__snapshots__/renderer.test.ts.snap b/test/__snapshots__/renderer.test.ts.snap index 74a9bf0..9822514 100644 --- a/test/__snapshots__/renderer.test.ts.snap +++ b/test/__snapshots__/renderer.test.ts.snap @@ -3,44 +3,74 @@ exports[`renderer > changelogReg 1`] = ` [ [ - "- A(A): a bug fix", + "- fix(A): a bug fix", + "fix", "A", + "a bug fix", + ], + [ + "- hotfix(A): a bug fix", + "hotfix", "A", "a bug fix", ], [ - "- B(B): a feature", + "- bug(A): a bug fix", + "bug", + "A", + "a bug fix", + ], + [ + "- feat(B): a feature", + "feat", "B", + "a feature", + ], + [ + "- feature(B): a feature", + "feature", "B", "a feature", ], [ - "- C(C): a bug fix", + "- enhancement(B): a feature", + "enhancement", + "B", + "a feature", + ], + [ + "- break(C): a major update", + "break", "C", + "a major update", + ], + [ + "- breaking(C): a major update", + "breaking", "C", - "a bug fix", + "a major update", ], [ - "- D(D): a feature", - "D", + "- feat(D): a feature", + "feat", "D", "a feature", ], [ - "- E(): a bug fix", - "E", + "- docs(): a doc change", + "docs", "", - "a bug fix", + "a doc change", ], [ - "- F: a bug fix", - "F", + "- chore: a chore", + "chore", undefined, - "a bug fix", + "a chore", ], [ - "- g(g): a minor fix", - "g", + "- break(g): a minor fix", + "break", "g", "a minor fix", ], diff --git a/test/renderer.test.ts b/test/renderer.test.ts index 550a36e..9bac7b3 100644 --- a/test/renderer.test.ts +++ b/test/renderer.test.ts @@ -4,14 +4,19 @@ import { ChangelogReg } from '../src/renderer' describe('renderer', () => { it('changelogReg', () => { const changelog = ` -- A(A): a bug fix -- B(B): a feature -- C(C): a bug fix -- D(D): a feature -- E(): a bug fix -- F: a bug fix -- g(g): a minor fix -- H(H H): a major update +- fix(A): a bug fix +- hotfix(A): a bug fix +- bug(A): a bug fix +- feat(B): a feature +- feature(B): a feature +- enhancement(B): a feature +- break(C): a major update +- breaking(C): a major update +- feat(D): a feature +- docs(): a doc change +- chore: a chore +- break(g): a minor fix +- break(H H): a major update ` const result = changelog.matchAll(ChangelogReg) expect([...result]).toMatchSnapshot() From f8e8c8b0f73ecee4515f306a92b336356836b720 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=8E=E4=BC=9F=E6=9D=B0?= <674416404@qq.com> Date: Mon, 12 Aug 2024 21:25:51 +0800 Subject: [PATCH 04/22] =?UTF-8?q?feat:=20=E5=AE=8C=E5=96=84ChangelogReg=20?= =?UTF-8?q?=E6=AD=A3=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/renderer.ts | 2 +- test/__snapshots__/renderer.test.ts.snap | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/renderer.ts b/src/renderer.ts index 8a2517b..2fd42a9 100644 --- a/src/renderer.ts +++ b/src/renderer.ts @@ -5,7 +5,7 @@ const skipChangelogLabel = ['skip-changelog'] const fixLabel = ['fix', 'bug', 'hotfix'] const breakingLabel = ['break', 'breaking', 'breaking changes'] const featureLabel = ['feature', 'feat', 'enhancement'] -export const ChangelogReg = /-\s([A-Z]+)(?:\(([A-Z]*)\))?:\s(.+)/gi +export const ChangelogReg = /-\s([A-Z]+)(?:\(([A-Z\s]*)\))?:\s(.+)/gi export function getPReformatNotes(body: string) { const reg = /in\shttps:\/\/github\.com\/.+\/pull\/(\d+)\s/g diff --git a/test/__snapshots__/renderer.test.ts.snap b/test/__snapshots__/renderer.test.ts.snap index 9822514..70a3200 100644 --- a/test/__snapshots__/renderer.test.ts.snap +++ b/test/__snapshots__/renderer.test.ts.snap @@ -74,5 +74,11 @@ exports[`renderer > changelogReg 1`] = ` "g", "a minor fix", ], + [ + "- break(H H): a major update", + "break", + "H H", + "a major update", + ], ] `; From 2cb5dd7e31a668a628321dac2651d1eefd64f852 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=8E=E4=BC=9F=E6=9D=B0?= <674416404@qq.com> Date: Mon, 12 Aug 2024 21:37:17 +0800 Subject: [PATCH 05/22] chore: add fixtures --- test/fixtures/changelog.ts | 15 +++++++++++++++ test/renderer.test.ts | 16 +--------------- 2 files changed, 16 insertions(+), 15 deletions(-) create mode 100644 test/fixtures/changelog.ts diff --git a/test/fixtures/changelog.ts b/test/fixtures/changelog.ts new file mode 100644 index 0000000..8162aef --- /dev/null +++ b/test/fixtures/changelog.ts @@ -0,0 +1,15 @@ +export const changelog = ` +- fix(A): a bug fix +- hotfix(A): a bug fix +- bug(A): a bug fix +- feat(B): a feature +- feature(B): a feature +- enhancement(B): a feature +- break(C): a major update +- breaking(C): a major update +- feat(D): a feature +- docs(): a doc change +- chore: a chore +- break(g): a minor fix +- break(H H): a major update +` diff --git a/test/renderer.test.ts b/test/renderer.test.ts index 9bac7b3..d376c6a 100644 --- a/test/renderer.test.ts +++ b/test/renderer.test.ts @@ -1,23 +1,9 @@ import { describe, expect, it } from 'vitest' import { ChangelogReg } from '../src/renderer' +import { changelog } from './fixtures/changelog' describe('renderer', () => { it('changelogReg', () => { - const changelog = ` -- fix(A): a bug fix -- hotfix(A): a bug fix -- bug(A): a bug fix -- feat(B): a feature -- feature(B): a feature -- enhancement(B): a feature -- break(C): a major update -- breaking(C): a major update -- feat(D): a feature -- docs(): a doc change -- chore: a chore -- break(g): a minor fix -- break(H H): a major update -` const result = changelog.matchAll(ChangelogReg) expect([...result]).toMatchSnapshot() }) From 4096074dad284d8e38e6cea6afd7f6e704017763 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=8E=E4=BC=9F=E6=9D=B0?= <674416404@qq.com> Date: Mon, 12 Aug 2024 21:41:26 +0800 Subject: [PATCH 06/22] test: add test case --- test/renderer.test.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/renderer.test.ts b/test/renderer.test.ts index d376c6a..b8d725e 100644 --- a/test/renderer.test.ts +++ b/test/renderer.test.ts @@ -5,6 +5,8 @@ import { changelog } from './fixtures/changelog' describe('renderer', () => { it('changelogReg', () => { const result = changelog.matchAll(ChangelogReg) - expect([...result]).toMatchSnapshot() + const arr = [...result] + expect(arr.length).toBe(13) + expect(arr).toMatchSnapshot() }) }) From 8d86c660bcfd424ec8fd0452b63a7446870f4374 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=8E=E4=BC=9F=E6=9D=B0?= <674416404@qq.com> Date: Tue, 13 Aug 2024 17:37:39 +0800 Subject: [PATCH 07/22] test: getPullNumbers --- src/index.ts | 4 ++-- src/renderer.ts | 7 +++---- test/__snapshots__/renderer.test.ts.snap | 21 ++++++++++++++++++++- test/fixtures/releaseNotes.ts | 24 ++++++++++++++++++++++++ test/renderer.test.ts | 10 ++++++++-- 5 files changed, 57 insertions(+), 9 deletions(-) create mode 100644 test/fixtures/releaseNotes.ts diff --git a/src/index.ts b/src/index.ts index 39f900f..2de1135 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,7 +3,7 @@ import process from 'node:process' import { getInput, info, setFailed, setOutput } from '@actions/core' import { context, getOctokit } from '@actions/github' import dayjs from 'dayjs' -import { getPReformatNotes, renderMarkdown } from './renderer' +import { getPullNumbers, renderMarkdown } from './renderer' import type { PullsData } from './types' const GITHUB_TOKEN = process.env.GITHUB_TOKEN @@ -36,7 +36,7 @@ async function generatorLogStart() { target_commitish: 'develop', // 也可以从上下文中拿 }) - const PRNumbers = getPReformatNotes(releases.data.body) + const PRNumbers = getPullNumbers(releases.data.body) const PRListRes = await Promise.all(PRNumbers.map(pull_number => octokit.rest.pulls.get({ owner, diff --git a/src/renderer.ts b/src/renderer.ts index 2fd42a9..95dcd27 100644 --- a/src/renderer.ts +++ b/src/renderer.ts @@ -6,10 +6,9 @@ const fixLabel = ['fix', 'bug', 'hotfix'] const breakingLabel = ['break', 'breaking', 'breaking changes'] const featureLabel = ['feature', 'feat', 'enhancement'] export const ChangelogReg = /-\s([A-Z]+)(?:\(([A-Z\s]*)\))?:\s(.+)/gi -export function getPReformatNotes(body: string) { - const reg = /in\shttps:\/\/github\.com\/.+\/pull\/(\d+)\s/g - - const arr = [...body.matchAll(reg)] +export const PullNumberReg = /in\shttps:\/\/github\.com\/.+\/pull\/(\d+)\s/g +export function getPullNumbers(body: string) { + const arr = [...body.matchAll(PullNumberReg)] return arr.map(n => Number(n[1])) // pr number list } diff --git a/test/__snapshots__/renderer.test.ts.snap b/test/__snapshots__/renderer.test.ts.snap index 70a3200..5dfd7fc 100644 --- a/test/__snapshots__/renderer.test.ts.snap +++ b/test/__snapshots__/renderer.test.ts.snap @@ -1,6 +1,6 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`renderer > changelogReg 1`] = ` +exports[`renderer > : changelogReg 1`] = ` [ [ "- fix(A): a bug fix", @@ -82,3 +82,22 @@ exports[`renderer > changelogReg 1`] = ` ], ] `; + +exports[`renderer > : getPullNumber 1`] = ` +[ + 7, + 14, + 15, + 16, + 17, + 18, + 19, + 20, + 21, + 23, + 25, + 26, + 27, + 28, +] +`; diff --git a/test/fixtures/releaseNotes.ts b/test/fixtures/releaseNotes.ts new file mode 100644 index 0000000..3a0d9d4 --- /dev/null +++ b/test/fixtures/releaseNotes.ts @@ -0,0 +1,24 @@ +const body = ` +## What's Changed +* feat: get latest tag by @liweijie0812 in https://github.com/TDesignOteam/tdesign-changelog-action/pull/7 +* ci: tdesign-tag-action by @liweijie0812 in https://github.com/TDesignOteam/tdesign-changelog-action/pull/14 +* chore: release/0.0.2 by @liweijie0812 in https://github.com/TDesignOteam/tdesign-changelog-action/pull/15 +* ci: auto merge develop to main by @liweijie0812 in https://github.com/TDesignOteam/tdesign-changelog-action/pull/16 +* chore: release 0.1.0 by @liweijie0812 in https://github.com/TDesignOteam/tdesign-changelog-action/pull/17 +* ci: fix tag_push by @liweijie0812 in https://github.com/TDesignOteam/tdesign-changelog-action/pull/18 +* chore: release 0.1.1 by @liweijie0812 in https://github.com/TDesignOteam/tdesign-changelog-action/pull/19 +* fix: merge_tag by @liweijie0812 in https://github.com/TDesignOteam/tdesign-changelog-action/pull/20 +* chore: release 0.1.2 by @liweijie0812 in https://github.com/TDesignOteam/tdesign-changelog-action/pull/21 +* ci: add bot-ci by @liweijie0812 in https://github.com/TDesignOteam/tdesign-changelog-action/pull/23 +* feat(ci): pr spell check by @liweijie0812 in https://github.com/TDesignOteam/tdesign-changelog-action/pull/25 +* feat: migrate ts by @liweijie0812 in https://github.com/TDesignOteam/tdesign-changelog-action/pull/26 +* feat: breakingLabel add break by @liweijie0812 in https://github.com/TDesignOteam/tdesign-changelog-action/pull/27 +* chore: release 0.2.0 by @liweijie0812 in https://github.com/TDesignOteam/tdesign-changelog-action/pull/28 + + +**Full Changelog**: https://github.com/TDesignOteam/tdesign-changelog-action/compare/0.0.1...0.2.0 +` +export const releaseNotes = { + name: '0.2.0', + body, +} diff --git a/test/renderer.test.ts b/test/renderer.test.ts index b8d725e..76bebd4 100644 --- a/test/renderer.test.ts +++ b/test/renderer.test.ts @@ -1,12 +1,18 @@ import { describe, expect, it } from 'vitest' -import { ChangelogReg } from '../src/renderer' +import { ChangelogReg, getPullNumbers } from '../src/renderer' import { changelog } from './fixtures/changelog' +import { releaseNotes } from './fixtures/releaseNotes' describe('renderer', () => { - it('changelogReg', () => { + it(': changelogReg', () => { const result = changelog.matchAll(ChangelogReg) const arr = [...result] expect(arr.length).toBe(13) expect(arr).toMatchSnapshot() }) + it(': getPullNumber', () => { + const result = getPullNumbers(releaseNotes.body) + expect(result.length).toBe(14) + expect(result).toMatchSnapshot() + }) }) From c6fd312cbadd26483eebdb6602654cc354d774a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=8E=E4=BC=9F=E6=9D=B0?= <674416404@qq.com> Date: Wed, 14 Aug 2024 10:20:21 +0800 Subject: [PATCH 08/22] test: wip --- src/renderer.ts | 8 +- test/__snapshots__/regexp.test.ts.snap | 159 +++++++++++++++++++++++ test/__snapshots__/renderer.test.ts.snap | 103 --------------- test/fixtures/changelog.ts | 3 +- test/fixtures/releaseNotes.ts | 7 +- test/regexp.test.ts | 19 +++ test/renderer.test.ts | 18 --- 7 files changed, 186 insertions(+), 131 deletions(-) create mode 100644 test/__snapshots__/regexp.test.ts.snap delete mode 100644 test/__snapshots__/renderer.test.ts.snap create mode 100644 test/regexp.test.ts delete mode 100644 test/renderer.test.ts diff --git a/src/renderer.ts b/src/renderer.ts index 95dcd27..4d7c839 100644 --- a/src/renderer.ts +++ b/src/renderer.ts @@ -5,10 +5,10 @@ const skipChangelogLabel = ['skip-changelog'] const fixLabel = ['fix', 'bug', 'hotfix'] const breakingLabel = ['break', 'breaking', 'breaking changes'] const featureLabel = ['feature', 'feat', 'enhancement'] -export const ChangelogReg = /-\s([A-Z]+)(?:\(([A-Z\s]*)\))?:\s(.+)/gi -export const PullNumberReg = /in\shttps:\/\/github\.com\/.+\/pull\/(\d+)\s/g +export const CHANGELOG_REG = /-\s([A-Z]+)(?:\(([A-Z\s]*)\))?:\s(.+)/gi +export const PULL_NUMBER_REG = /in\shttps:\/\/github\.com\/.+\/pull\/(\d+)\s/g export function getPullNumbers(body: string) { - const arr = [...body.matchAll(PullNumberReg)] + const arr = [...body.matchAll(PULL_NUMBER_REG)] return arr.map(n => Number(n[1])) // pr number list } @@ -52,7 +52,7 @@ export function renderMarkdown(pullRequestList: PullsData[]) { } if (pr.body.includes('### 📝 更新日志')) { - const arr = [...pr.body.matchAll(ChangelogReg)] + const arr = [...pr.body.matchAll(CHANGELOG_REG)] if (arr.length === 0) { info(`没有找到任何一条日志内容 number:${pr.number}, body:${pr.body}`) diff --git a/test/__snapshots__/regexp.test.ts.snap b/test/__snapshots__/regexp.test.ts.snap new file mode 100644 index 0000000..ce24d77 --- /dev/null +++ b/test/__snapshots__/regexp.test.ts.snap @@ -0,0 +1,159 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`regexp > : CHANGELOG_REG 1`] = ` +[ + [ + "- fix(A): a bug fix", + "fix", + "A", + "a bug fix", + ], + [ + "- hotfix(A): a bug fix", + "hotfix", + "A", + "a bug fix", + ], + [ + "- bug(A): a bug fix", + "bug", + "A", + "a bug fix", + ], + [ + "- feat(B): a feature", + "feat", + "B", + "a feature", + ], + [ + "- feature(B): a feature", + "feature", + "B", + "a feature", + ], + [ + "- enhancement(B): a feature", + "enhancement", + "B", + "a feature", + ], + [ + "- break(C): a major update", + "break", + "C", + "a major update", + ], + [ + "- breaking(C): a major update", + "breaking", + "C", + "a major update", + ], + [ + "- feat(D): a feature", + "feat", + "D", + "a feature", + ], + [ + "- docs(): a doc change", + "docs", + "", + "a doc change", + ], + [ + "- chore: a chore", + "chore", + undefined, + "a chore", + ], + [ + "- break(g): a minor fix", + "break", + "g", + "a minor fix", + ], + [ + "- break(H H): a major update", + "break", + "H H", + "a major update", + ], +] +`; + +exports[`regexp > : PULL_NUMBER_REG 1`] = ` +[ + [ + "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/7 +", + "7", + ], + [ + "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/14 +", + "14", + ], + [ + "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/15 +", + "15", + ], + [ + "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/16 +", + "16", + ], + [ + "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/17 +", + "17", + ], + [ + "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/18 +", + "18", + ], + [ + "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/19 +", + "19", + ], + [ + "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/20 +", + "20", + ], + [ + "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/21 +", + "21", + ], + [ + "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/23 +", + "23", + ], + [ + "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/25 +", + "25", + ], + [ + "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/26 +", + "26", + ], + [ + "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/27 +", + "27", + ], + [ + "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/28 +", + "28", + ], +] +`; diff --git a/test/__snapshots__/renderer.test.ts.snap b/test/__snapshots__/renderer.test.ts.snap deleted file mode 100644 index 5dfd7fc..0000000 --- a/test/__snapshots__/renderer.test.ts.snap +++ /dev/null @@ -1,103 +0,0 @@ -// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html - -exports[`renderer > : changelogReg 1`] = ` -[ - [ - "- fix(A): a bug fix", - "fix", - "A", - "a bug fix", - ], - [ - "- hotfix(A): a bug fix", - "hotfix", - "A", - "a bug fix", - ], - [ - "- bug(A): a bug fix", - "bug", - "A", - "a bug fix", - ], - [ - "- feat(B): a feature", - "feat", - "B", - "a feature", - ], - [ - "- feature(B): a feature", - "feature", - "B", - "a feature", - ], - [ - "- enhancement(B): a feature", - "enhancement", - "B", - "a feature", - ], - [ - "- break(C): a major update", - "break", - "C", - "a major update", - ], - [ - "- breaking(C): a major update", - "breaking", - "C", - "a major update", - ], - [ - "- feat(D): a feature", - "feat", - "D", - "a feature", - ], - [ - "- docs(): a doc change", - "docs", - "", - "a doc change", - ], - [ - "- chore: a chore", - "chore", - undefined, - "a chore", - ], - [ - "- break(g): a minor fix", - "break", - "g", - "a minor fix", - ], - [ - "- break(H H): a major update", - "break", - "H H", - "a major update", - ], -] -`; - -exports[`renderer > : getPullNumber 1`] = ` -[ - 7, - 14, - 15, - 16, - 17, - 18, - 19, - 20, - 21, - 23, - 25, - 26, - 27, - 28, -] -`; diff --git a/test/fixtures/changelog.ts b/test/fixtures/changelog.ts index 8162aef..a99bcb2 100644 --- a/test/fixtures/changelog.ts +++ b/test/fixtures/changelog.ts @@ -1,4 +1,4 @@ -export const changelog = ` +const changelog = ` - fix(A): a bug fix - hotfix(A): a bug fix - bug(A): a bug fix @@ -13,3 +13,4 @@ export const changelog = ` - break(g): a minor fix - break(H H): a major update ` +export default changelog diff --git a/test/fixtures/releaseNotes.ts b/test/fixtures/releaseNotes.ts index 3a0d9d4..a48ef0f 100644 --- a/test/fixtures/releaseNotes.ts +++ b/test/fixtures/releaseNotes.ts @@ -1,4 +1,4 @@ -const body = ` +const releaseNotes = ` ## What's Changed * feat: get latest tag by @liweijie0812 in https://github.com/TDesignOteam/tdesign-changelog-action/pull/7 * ci: tdesign-tag-action by @liweijie0812 in https://github.com/TDesignOteam/tdesign-changelog-action/pull/14 @@ -18,7 +18,4 @@ const body = ` **Full Changelog**: https://github.com/TDesignOteam/tdesign-changelog-action/compare/0.0.1...0.2.0 ` -export const releaseNotes = { - name: '0.2.0', - body, -} +export default releaseNotes diff --git a/test/regexp.test.ts b/test/regexp.test.ts new file mode 100644 index 0000000..38063ef --- /dev/null +++ b/test/regexp.test.ts @@ -0,0 +1,19 @@ +import { describe, expect, it } from 'vitest' +import { CHANGELOG_REG, PULL_NUMBER_REG } from '../src/renderer' +import changelog from './fixtures/changelog' +import releaseNotes from './fixtures/releaseNotes' + +describe('regexp', () => { + it(': CHANGELOG_REG', () => { + const result = changelog.matchAll(CHANGELOG_REG) + const arr = [...result] + expect(arr.length).toBe(13) + expect(arr).toMatchSnapshot() + }) + it(': PULL_NUMBER_REG', () => { + const result = releaseNotes.matchAll(PULL_NUMBER_REG) + const arr = [...result] + expect(arr.length).toBe(14) + expect(arr).toMatchSnapshot() + }) +}) diff --git a/test/renderer.test.ts b/test/renderer.test.ts deleted file mode 100644 index 76bebd4..0000000 --- a/test/renderer.test.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { describe, expect, it } from 'vitest' -import { ChangelogReg, getPullNumbers } from '../src/renderer' -import { changelog } from './fixtures/changelog' -import { releaseNotes } from './fixtures/releaseNotes' - -describe('renderer', () => { - it(': changelogReg', () => { - const result = changelog.matchAll(ChangelogReg) - const arr = [...result] - expect(arr.length).toBe(13) - expect(arr).toMatchSnapshot() - }) - it(': getPullNumber', () => { - const result = getPullNumbers(releaseNotes.body) - expect(result.length).toBe(14) - expect(result).toMatchSnapshot() - }) -}) From fb9407f815a1227cce2da1f87beba071fbf1a096 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=8E=E4=BC=9F=E6=9D=B0?= <674416404@qq.com> Date: Wed, 14 Aug 2024 11:40:25 +0800 Subject: [PATCH 09/22] test: SKIP_CHANGELOG_REG --- src/renderer.ts | 3 ++- test/regexp.test.ts | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/renderer.ts b/src/renderer.ts index 4d7c839..f93996c 100644 --- a/src/renderer.ts +++ b/src/renderer.ts @@ -7,6 +7,7 @@ const breakingLabel = ['break', 'breaking', 'breaking changes'] const featureLabel = ['feature', 'feat', 'enhancement'] export const CHANGELOG_REG = /-\s([A-Z]+)(?:\(([A-Z\s]*)\))?:\s(.+)/gi export const PULL_NUMBER_REG = /in\shttps:\/\/github\.com\/.+\/pull\/(\d+)\s/g +export const SKIP_CHANGELOG_REG = /\[x\] 本条 PR 不需要纳入 changelog/i export function getPullNumbers(body: string) { const arr = [...body.matchAll(PULL_NUMBER_REG)] @@ -46,7 +47,7 @@ export function renderMarkdown(pullRequestList: PullsData[]) { return } // 在 pr body 明确填了 跳过 label - if (/\[x\] 本条 PR 不需要纳入 changelog/i.test(pr.body)) { + if (SKIP_CHANGELOG_REG.test(pr.body)) { info(`pr ${pr.number} 显示不需要纳入 changelog`) return } diff --git a/test/regexp.test.ts b/test/regexp.test.ts index 38063ef..a886db8 100644 --- a/test/regexp.test.ts +++ b/test/regexp.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from 'vitest' -import { CHANGELOG_REG, PULL_NUMBER_REG } from '../src/renderer' +import { CHANGELOG_REG, PULL_NUMBER_REG, SKIP_CHANGELOG_REG } from '../src/renderer' import changelog from './fixtures/changelog' import releaseNotes from './fixtures/releaseNotes' @@ -10,10 +10,17 @@ describe('regexp', () => { expect(arr.length).toBe(13) expect(arr).toMatchSnapshot() }) + it(': PULL_NUMBER_REG', () => { const result = releaseNotes.matchAll(PULL_NUMBER_REG) const arr = [...result] expect(arr.length).toBe(14) expect(arr).toMatchSnapshot() }) + + it(': SKIP_CHANGELOG_REG', () => { + expect(SKIP_CHANGELOG_REG.test('[x] 本条 PR 不需要纳入 Changelog')).toBe(true) + expect(SKIP_CHANGELOG_REG.test('[x] 本条 PR 不需要纳入 changelog')).toBe(true) + expect(SKIP_CHANGELOG_REG.test('[X] 本条 PR 不需要纳入 changelog')).toBe(true) + }) }) From 80cb53c9f80241dbb94602e320f146ff79488efb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=8E=E4=BC=9F=E6=9D=B0?= <674416404@qq.com> Date: Sat, 7 Sep 2024 21:48:25 +0800 Subject: [PATCH 10/22] feat: update PULL_NUMBER_REG --- src/renderer.ts | 2 +- test/__snapshots__/regexp.test.ts.snap | 42 +++++++++----------------- 2 files changed, 15 insertions(+), 29 deletions(-) diff --git a/src/renderer.ts b/src/renderer.ts index f93996c..b2210e3 100644 --- a/src/renderer.ts +++ b/src/renderer.ts @@ -6,7 +6,7 @@ const fixLabel = ['fix', 'bug', 'hotfix'] const breakingLabel = ['break', 'breaking', 'breaking changes'] const featureLabel = ['feature', 'feat', 'enhancement'] export const CHANGELOG_REG = /-\s([A-Z]+)(?:\(([A-Z\s]*)\))?:\s(.+)/gi -export const PULL_NUMBER_REG = /in\shttps:\/\/github\.com\/.+\/pull\/(\d+)\s/g +export const PULL_NUMBER_REG = /in\shttps:\/\/github\.com\/.+\/pull\/(\d+)/g export const SKIP_CHANGELOG_REG = /\[x\] 本条 PR 不需要纳入 changelog/i export function getPullNumbers(body: string) { const arr = [...body.matchAll(PULL_NUMBER_REG)] diff --git a/test/__snapshots__/regexp.test.ts.snap b/test/__snapshots__/regexp.test.ts.snap index ce24d77..0480b36 100644 --- a/test/__snapshots__/regexp.test.ts.snap +++ b/test/__snapshots__/regexp.test.ts.snap @@ -86,73 +86,59 @@ exports[`regexp > : CHANGELOG_REG 1`] = ` exports[`regexp > : PULL_NUMBER_REG 1`] = ` [ [ - "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/7 -", + "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/7", "7", ], [ - "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/14 -", + "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/14", "14", ], [ - "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/15 -", + "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/15", "15", ], [ - "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/16 -", + "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/16", "16", ], [ - "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/17 -", + "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/17", "17", ], [ - "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/18 -", + "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/18", "18", ], [ - "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/19 -", + "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/19", "19", ], [ - "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/20 -", + "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/20", "20", ], [ - "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/21 -", + "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/21", "21", ], [ - "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/23 -", + "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/23", "23", ], [ - "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/25 -", + "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/25", "25", ], [ - "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/26 -", + "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/26", "26", ], [ - "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/27 -", + "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/27", "27", ], [ - "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/28 -", + "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/28", "28", ], ] From a60658dba6ffe132b783bbbd7f43aa52b1ffc57f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=8E=E4=BC=9F=E6=9D=B0?= <674416404@qq.com> Date: Mon, 9 Sep 2024 00:19:30 +0800 Subject: [PATCH 11/22] =?UTF-8?q?feat:=20getPullNumbers=20=E5=8E=BB?= =?UTF-8?q?=E9=87=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/renderer.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/renderer.ts b/src/renderer.ts index b2210e3..168b0d1 100644 --- a/src/renderer.ts +++ b/src/renderer.ts @@ -10,8 +10,9 @@ export const PULL_NUMBER_REG = /in\shttps:\/\/github\.com\/.+\/pull\/(\d+)/g export const SKIP_CHANGELOG_REG = /\[x\] 本条 PR 不需要纳入 changelog/i export function getPullNumbers(body: string) { const arr = [...body.matchAll(PULL_NUMBER_REG)] - - return arr.map(n => Number(n[1])) // pr number list + const pullNumbers = arr.map(n => Number(n[1])) // pr number list + const uniquePullNumbers = [...new Set(pullNumbers)] + return uniquePullNumbers } function regToPrObj(arr: string[]) { From 5b104f2a6c7351079fa40f531a2bbfb129a40802 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=8E=E4=BC=9F=E6=9D=B0?= <674416404@qq.com> Date: Mon, 9 Sep 2024 12:22:11 +0800 Subject: [PATCH 12/22] test: generatorLog test case --- src/generator.ts | 50 ++ src/index.ts | 53 +- src/renderer.ts | 2 +- src/use-octokit.ts | 34 ++ test/__snapshots__/generatorLog.test.ts.snap | 24 + test/__snapshots__/regexp.test.ts.snap | 108 ++-- test/fixtures/changelog.ts | 29 +- test/fixtures/release-notes.ts | 25 + test/fixtures/releaseNotes.ts | 21 - test/generatorLog.test.ts | 13 + test/index.test.ts | 2 +- test/regexp.test.ts | 4 +- test/setup-env.ts | 3 + test/setup-github.ts | 570 +++++++++++++++++++ test/setup-octokit.ts | 314 ++++++++++ vitest.config.mts | 1 + 16 files changed, 1094 insertions(+), 159 deletions(-) create mode 100644 src/generator.ts create mode 100644 src/use-octokit.ts create mode 100644 test/__snapshots__/generatorLog.test.ts.snap create mode 100644 test/fixtures/release-notes.ts delete mode 100644 test/fixtures/releaseNotes.ts create mode 100644 test/generatorLog.test.ts create mode 100644 test/setup-env.ts create mode 100644 test/setup-github.ts create mode 100644 test/setup-octokit.ts diff --git a/src/generator.ts b/src/generator.ts new file mode 100644 index 0000000..f9700a0 --- /dev/null +++ b/src/generator.ts @@ -0,0 +1,50 @@ +import fs from 'node:fs' +import process from 'node:process' +import { getInput, info, setOutput } from '@actions/core' +import dayjs from 'dayjs' +import { getPullNumbers, renderMarkdown } from './renderer' +import type { PullsData } from './types' +import { useOctokit } from './use-octokit' + +export async function generatorLogStart(context) { + const GITHUB_TOKEN = process.env.GITHUB_TOKEN || '' + const { generateReleaseNotes, getPullRequest } = useOctokit({ token: GITHUB_TOKEN }) + let tag = getInput('tag', { required: false }) + if (!tag) { + const pkg = JSON.parse(fs.readFileSync('./package.json', 'utf-8')) + tag = pkg.version + } + const { owner, repo } = context.repo + info(`owner:${owner}, repo:${repo}`) + + const releases = await generateReleaseNotes( + owner, + repo, + tag, + 'develop', + ) + + const PRNumbers = getPullNumbers(releases.data.body) + + const PRListRes = await Promise.all(PRNumbers.map(pull_number => getPullRequest( + owner, + repo, + pull_number, + ))) + + const PRList = PRListRes.map(res => res.data as PullsData) + + info(`PRList:${JSON.stringify(PRList)}`) + + const logRelease = `(删除此行代表确认该日志): 修改并确认日志后删除这一行,机器人会提交到 本 PR 的 CHANGELOG.md 文件中 + ## 🌈 ${tag} \`${dayjs().format('YYYY-MM-DD')}\` \n${renderMarkdown(PRList)}\n` + + info(logRelease) + + setActionOutput(logRelease) + return logRelease +} + +function setActionOutput(changelog: string) { + setOutput('changelog', changelog) +} diff --git a/src/index.ts b/src/index.ts index 2de1135..d0e682c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,13 +1,9 @@ -import fs from 'node:fs' import process from 'node:process' import { getInput, info, setFailed, setOutput } from '@actions/core' -import { context, getOctokit } from '@actions/github' -import dayjs from 'dayjs' -import { getPullNumbers, renderMarkdown } from './renderer' -import type { PullsData } from './types' +import { context } from '@actions/github' +import { generatorLogStart } from './generator' const GITHUB_TOKEN = process.env.GITHUB_TOKEN - info(`github.context:${JSON.stringify(context)}`) // console.log('payload', context.payload); @@ -18,50 +14,7 @@ if (!GITHUB_TOKEN) { ) } -const octokit = getOctokit(GITHUB_TOKEN) - -async function generatorLogStart() { - let tag = getInput('tag', { required: false }) - if (!tag) { - const pkg = JSON.parse(fs.readFileSync('./package.json', 'utf-8')) - tag = pkg.version - } - const { owner, repo } = context.repo - info(`owner:${owner}, repo:${repo}`) - - const releases = await octokit.rest.repos.generateReleaseNotes({ - owner, - repo, - tag_name: tag, // 'package.version' - target_commitish: 'develop', // 也可以从上下文中拿 - }) - - const PRNumbers = getPullNumbers(releases.data.body) - - const PRListRes = await Promise.all(PRNumbers.map(pull_number => octokit.rest.pulls.get({ - owner, - repo, - pull_number, - }))) - - const PRList = PRListRes.map(res => res.data as PullsData) - - info(`PRList:${JSON.stringify(PRList)}`) - - const logRelease = `(删除此行代表确认该日志): 修改并确认日志后删除这一行,机器人会提交到 本 PR 的 CHANGELOG.md 文件中 -## 🌈 ${tag} \`${dayjs().format('YYYY-MM-DD')}\` \n${renderMarkdown(PRList)}\n` - - info(logRelease) - - setActionOutput(logRelease) - return logRelease -} - -generatorLogStart().catch((error) => { +generatorLogStart(context).catch((error) => { console.error(error) setFailed(`💥 Auto Release failed with error: ${error.message}`) }) - -function setActionOutput(changelog: string) { - setOutput('changelog', changelog) -} diff --git a/src/renderer.ts b/src/renderer.ts index 168b0d1..3d6d661 100644 --- a/src/renderer.ts +++ b/src/renderer.ts @@ -18,7 +18,7 @@ export function getPullNumbers(body: string) { function regToPrObj(arr: string[]) { return { cate: arr[1], - component: arr[2], + component: arr[2] || '', desc: arr[3], } } diff --git a/src/use-octokit.ts b/src/use-octokit.ts new file mode 100644 index 0000000..5696a6b --- /dev/null +++ b/src/use-octokit.ts @@ -0,0 +1,34 @@ +import { getOctokit } from '@actions/github' + +export interface OctokitContext { + token: string + owner?: string + repo?: string +} +export function useOctokit(context: OctokitContext) { + const octokit = getOctokit(context.token) + + const generateReleaseNotes = async (owner: string, repo: string, tag_name: string, target_commitish: string) => { + const res = octokit.rest.repos.generateReleaseNotes({ + owner, + repo, + tag_name, + target_commitish, + }) + return res + } + + const getPullRequest = (owner: string, repo: string, pull_number: number) => { + const res = octokit.rest.pulls.get({ + owner, + repo, + pull_number, + }) + return res + } + + return { + generateReleaseNotes, + getPullRequest, + } +} diff --git a/test/__snapshots__/generatorLog.test.ts.snap b/test/__snapshots__/generatorLog.test.ts.snap new file mode 100644 index 0000000..3c981bd --- /dev/null +++ b/test/__snapshots__/generatorLog.test.ts.snap @@ -0,0 +1,24 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`generatorLog > : generatorLogStart 1`] = ` +"(删除此行代表确认该日志): 修改并确认日志后删除这一行,机器人会提交到 本 PR 的 CHANGELOG.md 文件中 + ## 🌈 0.2.0 \`2024-02-24\` +### ❗ Breaking Changes +- \`C\`: a major update label in break @liweijie0812 ([#29](https://github.com/TDesignOteam/tdesign-changelog-action/pull/29)) +- \`C\`: a major update label in breaking @liweijie0812 ([#29](https://github.com/TDesignOteam/tdesign-changelog-action/pull/29)) +- \`g\`: a minor fix label in break @liweijie0812 ([#29](https://github.com/TDesignOteam/tdesign-changelog-action/pull/29)) +- \`H H\`: a major update label in break @liweijie0812 ([#29](https://github.com/TDesignOteam/tdesign-changelog-action/pull/29)) +### 🚀 Features +- \`B\`: a feature label in feat @liweijie0812 ([#29](https://github.com/TDesignOteam/tdesign-changelog-action/pull/29)) +- \`B\`: a feature label in feature @liweijie0812 ([#29](https://github.com/TDesignOteam/tdesign-changelog-action/pull/29)) +- \`B\`: a feature label in enhancement @liweijie0812 ([#29](https://github.com/TDesignOteam/tdesign-changelog-action/pull/29)) +- \`D\`: a feature label in feat @liweijie0812 ([#29](https://github.com/TDesignOteam/tdesign-changelog-action/pull/29)) +### 🐞 Bug Fixes +- \`A\`: a bug fix label in fix @liweijie0812 ([#29](https://github.com/TDesignOteam/tdesign-changelog-action/pull/29)) +- \`A\`: a bug fix label in hotfix @liweijie0812 ([#29](https://github.com/TDesignOteam/tdesign-changelog-action/pull/29)) +- \`A\`: a bug fix label in bug @liweijie0812 ([#29](https://github.com/TDesignOteam/tdesign-changelog-action/pull/29)) +### 🚧 Others +- \`\`: a doc change label in docs @liweijie0812 ([#29](https://github.com/TDesignOteam/tdesign-changelog-action/pull/29)) +- \`\`: a chore label in chore @liweijie0812 ([#29](https://github.com/TDesignOteam/tdesign-changelog-action/pull/29)) +" +`; diff --git a/test/__snapshots__/regexp.test.ts.snap b/test/__snapshots__/regexp.test.ts.snap index 0480b36..5a4e896 100644 --- a/test/__snapshots__/regexp.test.ts.snap +++ b/test/__snapshots__/regexp.test.ts.snap @@ -3,82 +3,82 @@ exports[`regexp > : CHANGELOG_REG 1`] = ` [ [ - "- fix(A): a bug fix", + "- fix(A): a bug fix label in fix", "fix", "A", - "a bug fix", + "a bug fix label in fix", ], [ - "- hotfix(A): a bug fix", + "- hotfix(A): a bug fix label in hotfix", "hotfix", "A", - "a bug fix", + "a bug fix label in hotfix", ], [ - "- bug(A): a bug fix", + "- bug(A): a bug fix label in bug", "bug", "A", - "a bug fix", + "a bug fix label in bug", ], [ - "- feat(B): a feature", + "- feat(B): a feature label in feat", "feat", "B", - "a feature", + "a feature label in feat", ], [ - "- feature(B): a feature", + "- feature(B): a feature label in feature", "feature", "B", - "a feature", + "a feature label in feature", ], [ - "- enhancement(B): a feature", + "- enhancement(B): a feature label in enhancement", "enhancement", "B", - "a feature", + "a feature label in enhancement", ], [ - "- break(C): a major update", + "- break(C): a major update label in break", "break", "C", - "a major update", + "a major update label in break", ], [ - "- breaking(C): a major update", + "- breaking(C): a major update label in breaking", "breaking", "C", - "a major update", + "a major update label in breaking", ], [ - "- feat(D): a feature", + "- feat(D): a feature label in feat", "feat", "D", - "a feature", + "a feature label in feat", ], [ - "- docs(): a doc change", + "- docs(): a doc change label in docs", "docs", "", - "a doc change", + "a doc change label in docs", ], [ - "- chore: a chore", + "- chore: a chore label in chore", "chore", undefined, - "a chore", + "a chore label in chore", ], [ - "- break(g): a minor fix", + "- break(g): a minor fix label in break", "break", "g", - "a minor fix", + "a minor fix label in break", ], [ - "- break(H H): a major update", + "- break(H H): a major update label in break", "break", "H H", - "a major update", + "a major update label in break", ], ] `; @@ -86,60 +86,28 @@ exports[`regexp > : CHANGELOG_REG 1`] = ` exports[`regexp > : PULL_NUMBER_REG 1`] = ` [ [ - "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/7", - "7", + "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/1", + "1", ], [ - "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/14", - "14", + "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/2", + "2", ], [ - "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/15", - "15", + "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/3", + "3", ], [ - "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/16", - "16", + "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/4", + "4", ], [ - "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/17", - "17", + "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/5", + "5", ], [ - "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/18", - "18", - ], - [ - "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/19", - "19", - ], - [ - "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/20", - "20", - ], - [ - "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/21", - "21", - ], - [ - "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/23", - "23", - ], - [ - "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/25", - "25", - ], - [ - "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/26", - "26", - ], - [ - "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/27", - "27", - ], - [ - "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/28", - "28", + "in https://github.com/TDesignOteam/tdesign-changelog-action/pull/1", + "1", ], ] `; diff --git a/test/fixtures/changelog.ts b/test/fixtures/changelog.ts index a99bcb2..2b6261e 100644 --- a/test/fixtures/changelog.ts +++ b/test/fixtures/changelog.ts @@ -1,16 +1,17 @@ -const changelog = ` -- fix(A): a bug fix -- hotfix(A): a bug fix -- bug(A): a bug fix -- feat(B): a feature -- feature(B): a feature -- enhancement(B): a feature -- break(C): a major update -- breaking(C): a major update -- feat(D): a feature -- docs(): a doc change -- chore: a chore -- break(g): a minor fix -- break(H H): a major update +export const changelog = ` +- fix(A): a bug fix label in fix +- hotfix(A): a bug fix label in hotfix +- bug(A): a bug fix label in bug +- feat(B): a feature label in feat +- feature(B): a feature label in feature +- enhancement(B): a feature label in enhancement +- break(C): a major update label in break +- breaking(C): a major update label in breaking +- feat(D): a feature label in feat +- docs(): a doc change label in docs +- chore: a chore label in chore +- break(g): a minor fix label in break +- break(H H): a major update label in break ` + export default changelog diff --git a/test/fixtures/release-notes.ts b/test/fixtures/release-notes.ts new file mode 100644 index 0000000..85e1fc0 --- /dev/null +++ b/test/fixtures/release-notes.ts @@ -0,0 +1,25 @@ +export const releaseNote = ` +## What's Changed +* feat: a feature by @liweijie0812 in https://github.com/TDesignOteam/tdesign-changelog-action/pull/1 + +## New Contributors +* @liweijie0812 made their first contribution in https://github.com/TDesignOteam/tdesign-changelog-action/pull/1 + +**Full Changelog**: https://github.com/TDesignOteam/tdesign-changelog-action/compare/0.0.1...0.2.0 +` + +export const releaseNotes = ` +## What's Changed +* feat: a feature by @liweijie0812 in https://github.com/TDesignOteam/tdesign-changelog-action/pull/1 +* docs: a doc change by @liweijie0812 in https://github.com/TDesignOteam/tdesign-changelog-action/pull/2 +* fix: a bug fix by @liweijie0812 in https://github.com/TDesignOteam/tdesign-changelog-action/pull/3 +* chore: a chore by @liweijie0812 in https://github.com/TDesignOteam/tdesign-changelog-action/pull/4 +* breaking: a major update by @liweijie0812 in https://github.com/TDesignOteam/tdesign-changelog-action/pull/5 + +## New Contributors +* @liweijie0812 made their first contribution in https://github.com/TDesignOteam/tdesign-changelog-action/pull/1 + +**Full Changelog**: https://github.com/TDesignOteam/tdesign-changelog-action/compare/0.0.1...0.2.0 +` + +export default releaseNotes diff --git a/test/fixtures/releaseNotes.ts b/test/fixtures/releaseNotes.ts deleted file mode 100644 index a48ef0f..0000000 --- a/test/fixtures/releaseNotes.ts +++ /dev/null @@ -1,21 +0,0 @@ -const releaseNotes = ` -## What's Changed -* feat: get latest tag by @liweijie0812 in https://github.com/TDesignOteam/tdesign-changelog-action/pull/7 -* ci: tdesign-tag-action by @liweijie0812 in https://github.com/TDesignOteam/tdesign-changelog-action/pull/14 -* chore: release/0.0.2 by @liweijie0812 in https://github.com/TDesignOteam/tdesign-changelog-action/pull/15 -* ci: auto merge develop to main by @liweijie0812 in https://github.com/TDesignOteam/tdesign-changelog-action/pull/16 -* chore: release 0.1.0 by @liweijie0812 in https://github.com/TDesignOteam/tdesign-changelog-action/pull/17 -* ci: fix tag_push by @liweijie0812 in https://github.com/TDesignOteam/tdesign-changelog-action/pull/18 -* chore: release 0.1.1 by @liweijie0812 in https://github.com/TDesignOteam/tdesign-changelog-action/pull/19 -* fix: merge_tag by @liweijie0812 in https://github.com/TDesignOteam/tdesign-changelog-action/pull/20 -* chore: release 0.1.2 by @liweijie0812 in https://github.com/TDesignOteam/tdesign-changelog-action/pull/21 -* ci: add bot-ci by @liweijie0812 in https://github.com/TDesignOteam/tdesign-changelog-action/pull/23 -* feat(ci): pr spell check by @liweijie0812 in https://github.com/TDesignOteam/tdesign-changelog-action/pull/25 -* feat: migrate ts by @liweijie0812 in https://github.com/TDesignOteam/tdesign-changelog-action/pull/26 -* feat: breakingLabel add break by @liweijie0812 in https://github.com/TDesignOteam/tdesign-changelog-action/pull/27 -* chore: release 0.2.0 by @liweijie0812 in https://github.com/TDesignOteam/tdesign-changelog-action/pull/28 - - -**Full Changelog**: https://github.com/TDesignOteam/tdesign-changelog-action/compare/0.0.1...0.2.0 -` -export default releaseNotes diff --git a/test/generatorLog.test.ts b/test/generatorLog.test.ts new file mode 100644 index 0000000..9bad8e5 --- /dev/null +++ b/test/generatorLog.test.ts @@ -0,0 +1,13 @@ +import { describe, expect, it, vi } from 'vitest' +import { context } from '@actions/github' +import { generatorLogStart } from '../src/generator' + +describe('generatorLog', () => { + it(': generatorLogStart', async () => { + const mockDate = new Date(2024, 1, 24) + vi.setSystemTime(mockDate) + const log = await generatorLogStart(context) + expect(log).toMatchSnapshot() + vi.useRealTimers() + }) +}) diff --git a/test/index.test.ts b/test/index.test.ts index d29dbea..9839ecf 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -1,4 +1,4 @@ -import { assert, describe, expect, it } from 'vitest' +import { assert, describe, expect, it, vi } from 'vitest' describe('index', () => { it('index', () => { diff --git a/test/regexp.test.ts b/test/regexp.test.ts index a886db8..58deba1 100644 --- a/test/regexp.test.ts +++ b/test/regexp.test.ts @@ -1,7 +1,7 @@ import { describe, expect, it } from 'vitest' import { CHANGELOG_REG, PULL_NUMBER_REG, SKIP_CHANGELOG_REG } from '../src/renderer' import changelog from './fixtures/changelog' -import releaseNotes from './fixtures/releaseNotes' +import releaseNotes from './fixtures/release-notes' describe('regexp', () => { it(': CHANGELOG_REG', () => { @@ -14,7 +14,7 @@ describe('regexp', () => { it(': PULL_NUMBER_REG', () => { const result = releaseNotes.matchAll(PULL_NUMBER_REG) const arr = [...result] - expect(arr.length).toBe(14) + expect(arr.length).toBe(6) expect(arr).toMatchSnapshot() }) diff --git a/test/setup-env.ts b/test/setup-env.ts new file mode 100644 index 0000000..dc52053 --- /dev/null +++ b/test/setup-env.ts @@ -0,0 +1,3 @@ +import process from 'node:process' + +process.env.GITHUB_TOKEN = 'test-token' diff --git a/test/setup-github.ts b/test/setup-github.ts new file mode 100644 index 0000000..a2d2e43 --- /dev/null +++ b/test/setup-github.ts @@ -0,0 +1,570 @@ +import { vi } from 'vitest' + +const context = { + payload: { + action: 'synchronize', + after: '16306438a5022551238ef9f8e09619a09f927439', + before: '24a3de6e95a4ff9f859d31443848fd7ce31fbdd1', + number: 33, + organization: { + avatar_url: 'https://avatars.githubusercontent.com/u/39033385?v=4', + description: '', + events_url: 'https://api.github.com/orgs/TDesignOteam/events', + hooks_url: 'https://api.github.com/orgs/TDesignOteam/hooks', + id: 39033385, + issues_url: 'https://api.github.com/orgs/TDesignOteam/issues', + login: 'TDesignOteam', + members_url: 'https://api.github.com/orgs/TDesignOteam/members{/member}', + node_id: 'MDEyOk9yZ2FuaXphdGlvbjM5MDMzMzg1', + public_members_url: 'https://api.github.com/orgs/TDesignOteam/public_members{/member}', + repos_url: 'https://api.github.com/orgs/TDesignOteam/repos', + url: 'https://api.github.com/orgs/TDesignOteam', + }, + pull_request: { + _links: { + comments: { + href: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/issues/33/comments', + }, + commits: { + href: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/pulls/33/commits', + }, + html: { + href: 'https://github.com/TDesignOteam/tdesign-changelog-action/pull/33', + }, + issue: { + href: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/issues/33', + }, + review_comment: { + href: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/pulls/comments{/number}', + }, + review_comments: { + href: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/pulls/33/comments', + }, + self: { + href: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/pulls/33', + }, + statuses: { + href: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/statuses/16306438a5022551238ef9f8e09619a09f927439', + }, + }, + active_lock_reason: null, + additions: 25, + assignee: null, + assignees: [], + author_association: 'MEMBER', + auto_merge: null, + base: { + label: 'TDesignOteam:develop', + ref: 'develop', + repo: { + allow_auto_merge: false, + allow_forking: true, + allow_merge_commit: false, + allow_rebase_merge: false, + allow_squash_merge: true, + allow_update_branch: false, + archive_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/{archive_format}{/ref}', + archived: false, + assignees_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/assignees{/user}', + blobs_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/git/blobs{/sha}', + branches_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/branches{/branch}', + clone_url: 'https://github.com/TDesignOteam/tdesign-changelog-action.git', + collaborators_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/collaborators{/collaborator}', + comments_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/comments{/number}', + commits_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/commits{/sha}', + compare_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/compare/{base}...{head}', + contents_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/contents/{+path}', + contributors_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/contributors', + created_at: '2024-05-31T03:18:52Z', + default_branch: 'develop', + delete_branch_on_merge: true, + deployments_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/deployments', + description: null, + disabled: false, + downloads_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/downloads', + events_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/events', + fork: false, + forks: 1, + forks_count: 1, + forks_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/forks', + full_name: 'TDesignOteam/tdesign-changelog-action', + git_commits_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/git/commits{/sha}', + git_refs_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/git/refs{/sha}', + git_tags_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/git/tags{/sha}', + git_url: 'git://github.com/TDesignOteam/tdesign-changelog-action.git', + has_discussions: false, + has_downloads: true, + has_issues: true, + has_pages: false, + has_projects: true, + has_wiki: true, + homepage: null, + hooks_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/hooks', + html_url: 'https://github.com/TDesignOteam/tdesign-changelog-action', + id: 808419936, + is_template: false, + issue_comment_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/issues/comments{/number}', + issue_events_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/issues/events{/number}', + issues_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/issues{/number}', + keys_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/keys{/key_id}', + labels_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/labels{/name}', + language: 'TypeScript', + languages_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/languages', + license: { + key: 'mit', + name: 'MIT License', + node_id: 'MDc6TGljZW5zZTEz', + spdx_id: 'MIT', + url: 'https://api.github.com/licenses/mit', + }, + merge_commit_message: 'PR_TITLE', + merge_commit_title: 'MERGE_MESSAGE', + merges_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/merges', + milestones_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/milestones{/number}', + mirror_url: null, + name: 'tdesign-changelog-action', + node_id: 'R_kgDOMC-CYA', + notifications_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/notifications{?since,all,participating}', + open_issues: 5, + open_issues_count: 5, + owner: { + avatar_url: 'https://avatars.githubusercontent.com/u/39033385?v=4', + events_url: 'https://api.github.com/users/TDesignOteam/events{/privacy}', + followers_url: 'https://api.github.com/users/TDesignOteam/followers', + following_url: 'https://api.github.com/users/TDesignOteam/following{/other_user}', + gists_url: 'https://api.github.com/users/TDesignOteam/gists{/gist_id}', + gravatar_id: '', + html_url: 'https://github.com/TDesignOteam', + id: 39033385, + login: 'TDesignOteam', + node_id: 'MDEyOk9yZ2FuaXphdGlvbjM5MDMzMzg1', + organizations_url: 'https://api.github.com/users/TDesignOteam/orgs', + received_events_url: 'https://api.github.com/users/TDesignOteam/received_events', + repos_url: 'https://api.github.com/users/TDesignOteam/repos', + site_admin: false, + starred_url: 'https://api.github.com/users/TDesignOteam/starred{/owner}{/repo}', + subscriptions_url: 'https://api.github.com/users/TDesignOteam/subscriptions', + type: 'Organization', + url: 'https://api.github.com/users/TDesignOteam', + }, + private: false, + pulls_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/pulls{/number}', + pushed_at: '2024-08-13T08:28:58Z', + releases_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/releases{/id}', + size: 584, + squash_merge_commit_message: 'COMMIT_MESSAGES', + squash_merge_commit_title: 'COMMIT_OR_PR_TITLE', + ssh_url: 'git@github.com:TDesignOteam/tdesign-changelog-action.git', + stargazers_count: 0, + stargazers_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/stargazers', + statuses_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/statuses/{sha}', + subscribers_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/subscribers', + subscription_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/subscription', + svn_url: 'https://github.com/TDesignOteam/tdesign-changelog-action', + tags_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/tags', + teams_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/teams', + topics: [], + trees_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/git/trees{/sha}', + updated_at: '2024-08-13T01:15:57Z', + url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action', + use_squash_pr_title_as_default: false, + visibility: 'public', + watchers: 0, + watchers_count: 0, + web_commit_signoff_required: false, + }, + sha: '2252a494738f568b04a8d66efe2085e7cb32768a', + user: { + avatar_url: 'https://avatars.githubusercontent.com/u/39033385?v=4', + events_url: 'https://api.github.com/users/TDesignOteam/events{/privacy}', + followers_url: 'https://api.github.com/users/TDesignOteam/followers', + following_url: 'https://api.github.com/users/TDesignOteam/following{/other_user}', + gists_url: 'https://api.github.com/users/TDesignOteam/gists{/gist_id}', + gravatar_id: '', + html_url: 'https://github.com/TDesignOteam', + id: 39033385, + login: 'TDesignOteam', + node_id: 'MDEyOk9yZ2FuaXphdGlvbjM5MDMzMzg1', + organizations_url: 'https://api.github.com/users/TDesignOteam/orgs', + received_events_url: 'https://api.github.com/users/TDesignOteam/received_events', + repos_url: 'https://api.github.com/users/TDesignOteam/repos', + site_admin: false, + starred_url: 'https://api.github.com/users/TDesignOteam/starred{/owner}{/repo}', + subscriptions_url: 'https://api.github.com/users/TDesignOteam/subscriptions', + type: 'Organization', + url: 'https://api.github.com/users/TDesignOteam', + }, + }, + body: '\r\n\r\n### 🤔 这个 PR 的性质是?\r\n\r\n- [ ] 日常 bug 修复\r\n- [ ] 新特性提交\r\n- [ ] 文档改进\r\n- [ ] 演示代码改进\r\n- [ ] 组件样式/交互改进\r\n- [ ] CI/CD 改进\r\n- [ ] 重构\r\n- [ ] 代码风格优化\r\n- [ ] 测试用例\r\n- [ ] 分支合并\r\n- [ ] 其他\r\n\r\n### 🔗 相关 Issue\r\n\r\n\r\n\r\n### 💡 需求背景和解决方案\r\n\r\n\r\n\r\n### 📝 更新日志\r\n\r\n\r\n\r\n- fix(组件名称): 处理问题或特性描述 ...\r\n\r\n- [ ] 本条 PR 不需要纳入 Changelog\r\n\r\n### ☑️ 请求合并前的自查清单\r\n\r\n⚠️ 请自检并全部**勾选全部选项**。⚠️\r\n\r\n- [ ] 文档已补充或无须补充\r\n- [ ] 代码演示已提供或无须提供\r\n- [ ] TypeScript 定义已补充或无须补充\r\n- [ ] Changelog 已提供或无须提供\r\n', + changed_files: 2, + closed_at: null, + comments: 3, + comments_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/issues/33/comments', + commits: 3, + commits_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/pulls/33/commits', + created_at: '2024-08-13T08:20:48Z', + deletions: 13, + diff_url: 'https://github.com/TDesignOteam/tdesign-changelog-action/pull/33.diff', + draft: false, + head: { + label: 'TDesignOteam:chore/log', + ref: 'chore/log', + repo: { + allow_auto_merge: false, + allow_forking: true, + allow_merge_commit: false, + allow_rebase_merge: false, + allow_squash_merge: true, + allow_update_branch: false, + archive_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/{archive_format}{/ref}', + archived: false, + assignees_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/assignees{/user}', + blobs_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/git/blobs{/sha}', + branches_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/branches{/branch}', + clone_url: 'https://github.com/TDesignOteam/tdesign-changelog-action.git', + collaborators_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/collaborators{/collaborator}', + comments_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/comments{/number}', + commits_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/commits{/sha}', + compare_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/compare/{base}...{head}', + contents_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/contents/{+path}', + contributors_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/contributors', + created_at: '2024-05-31T03:18:52Z', + default_branch: 'develop', + delete_branch_on_merge: true, + deployments_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/deployments', + description: null, + disabled: false, + downloads_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/downloads', + events_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/events', + fork: false, + forks: 1, + forks_count: 1, + forks_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/forks', + full_name: 'TDesignOteam/tdesign-changelog-action', + git_commits_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/git/commits{/sha}', + git_refs_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/git/refs{/sha}', + git_tags_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/git/tags{/sha}', + git_url: 'git://github.com/TDesignOteam/tdesign-changelog-action.git', + has_discussions: false, + has_downloads: true, + has_issues: true, + has_pages: false, + has_projects: true, + has_wiki: true, + homepage: null, + hooks_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/hooks', + html_url: 'https://github.com/TDesignOteam/tdesign-changelog-action', + id: 808419936, + is_template: false, + issue_comment_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/issues/comments{/number}', + issue_events_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/issues/events{/number}', + issues_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/issues{/number}', + keys_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/keys{/key_id}', + labels_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/labels{/name}', + language: 'TypeScript', + languages_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/languages', + license: { + key: 'mit', + name: 'MIT License', + node_id: 'MDc6TGljZW5zZTEz', + spdx_id: 'MIT', + url: 'https://api.github.com/licenses/mit', + }, + merge_commit_message: 'PR_TITLE', + merge_commit_title: 'MERGE_MESSAGE', + merges_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/merges', + milestones_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/milestones{/number}', + mirror_url: null, + name: 'tdesign-changelog-action', + node_id: 'R_kgDOMC-CYA', + notifications_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/notifications{?since,all,participating}', + open_issues: 5, + open_issues_count: 5, + owner: { + avatar_url: 'https://avatars.githubusercontent.com/u/39033385?v=4', + events_url: 'https://api.github.com/users/TDesignOteam/events{/privacy}', + followers_url: 'https://api.github.com/users/TDesignOteam/followers', + following_url: 'https://api.github.com/users/TDesignOteam/following{/other_user}', + gists_url: 'https://api.github.com/users/TDesignOteam/gists{/gist_id}', + gravatar_id: '', + html_url: 'https://github.com/TDesignOteam', + id: 39033385, + login: 'TDesignOteam', + node_id: 'MDEyOk9yZ2FuaXphdGlvbjM5MDMzMzg1', + organizations_url: 'https://api.github.com/users/TDesignOteam/orgs', + received_events_url: 'https://api.github.com/users/TDesignOteam/received_events', + repos_url: 'https://api.github.com/users/TDesignOteam/repos', + site_admin: false, + starred_url: 'https://api.github.com/users/TDesignOteam/starred{/owner}{/repo}', + subscriptions_url: 'https://api.github.com/users/TDesignOteam/subscriptions', + type: 'Organization', + url: 'https://api.github.com/users/TDesignOteam', + }, + private: false, + pulls_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/pulls{/number}', + pushed_at: '2024-08-13T08:28:58Z', + releases_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/releases{/id}', + size: 584, + squash_merge_commit_message: 'COMMIT_MESSAGES', + squash_merge_commit_title: 'COMMIT_OR_PR_TITLE', + ssh_url: 'git@github.com:TDesignOteam/tdesign-changelog-action.git', + stargazers_count: 0, + stargazers_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/stargazers', + statuses_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/statuses/{sha}', + subscribers_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/subscribers', + subscription_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/subscription', + svn_url: 'https://github.com/TDesignOteam/tdesign-changelog-action', + tags_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/tags', + teams_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/teams', + topics: [], + trees_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/git/trees{/sha}', + updated_at: '2024-08-13T01:15:57Z', + url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action', + use_squash_pr_title_as_default: false, + visibility: 'public', + watchers: 0, + watchers_count: 0, + web_commit_signoff_required: false, + }, + sha: '16306438a5022551238ef9f8e09619a09f927439', + user: { + avatar_url: 'https://avatars.githubusercontent.com/u/39033385?v=4', + events_url: 'https://api.github.com/users/TDesignOteam/events{/privacy}', + followers_url: 'https://api.github.com/users/TDesignOteam/followers', + following_url: 'https://api.github.com/users/TDesignOteam/following{/other_user}', + gists_url: 'https://api.github.com/users/TDesignOteam/gists{/gist_id}', + gravatar_id: '', + html_url: 'https://github.com/TDesignOteam', + id: 39033385, + login: 'TDesignOteam', + node_id: 'MDEyOk9yZ2FuaXphdGlvbjM5MDMzMzg1', + organizations_url: 'https://api.github.com/users/TDesignOteam/orgs', + received_events_url: 'https://api.github.com/users/TDesignOteam/received_events', + repos_url: 'https://api.github.com/users/TDesignOteam/repos', + site_admin: false, + starred_url: 'https://api.github.com/users/TDesignOteam/starred{/owner}{/repo}', + subscriptions_url: 'https://api.github.com/users/TDesignOteam/subscriptions', + type: 'Organization', + url: 'https://api.github.com/users/TDesignOteam', + }, + }, + html_url: 'https://github.com/TDesignOteam/tdesign-changelog-action/pull/33', + id: 2016606180, + issue_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/issues/33', + labels: [], + locked: false, + maintainer_can_modify: false, + merge_commit_sha: 'd9e3b14f86ae7190b5d70c4b4d5980e22497d16e', + mergeable: null, + mergeable_state: 'unknown', + merged: false, + merged_at: null, + merged_by: null, + milestone: null, + node_id: 'PR_kwDOMC-CYM54Mvfk', + number: 33, + patch_url: 'https://github.com/TDesignOteam/tdesign-changelog-action/pull/33.patch', + rebaseable: null, + requested_reviewers: [ + { + avatar_url: 'https://avatars.githubusercontent.com/u/26377630?v=4', + events_url: 'https://api.github.com/users/uyarn/events{/privacy}', + followers_url: 'https://api.github.com/users/uyarn/followers', + following_url: 'https://api.github.com/users/uyarn/following{/other_user}', + gists_url: 'https://api.github.com/users/uyarn/gists{/gist_id}', + gravatar_id: '', + html_url: 'https://github.com/uyarn', + id: 26377630, + login: 'uyarn', + node_id: 'MDQ6VXNlcjI2Mzc3NjMw', + organizations_url: 'https://api.github.com/users/uyarn/orgs', + received_events_url: 'https://api.github.com/users/uyarn/received_events', + repos_url: 'https://api.github.com/users/uyarn/repos', + site_admin: false, + starred_url: 'https://api.github.com/users/uyarn/starred{/owner}{/repo}', + subscriptions_url: 'https://api.github.com/users/uyarn/subscriptions', + type: 'User', + url: 'https://api.github.com/users/uyarn', + }, + ], + requested_teams: [], + review_comment_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/pulls/comments{/number}', + review_comments: 0, + review_comments_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/pulls/33/comments', + state: 'open', + statuses_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/statuses/16306438a5022551238ef9f8e09619a09f927439', + title: 'chore: print log', + updated_at: '2024-08-13T08:28:59Z', + url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/pulls/33', + user: { + avatar_url: 'https://avatars.githubusercontent.com/u/10710889?v=4', + events_url: 'https://api.github.com/users/liweijie0812/events{/privacy}', + followers_url: 'https://api.github.com/users/liweijie0812/followers', + following_url: 'https://api.github.com/users/liweijie0812/following{/other_user}', + gists_url: 'https://api.github.com/users/liweijie0812/gists{/gist_id}', + gravatar_id: '', + html_url: 'https://github.com/liweijie0812', + id: 10710889, + login: 'liweijie0812', + node_id: 'MDQ6VXNlcjEwNzEwODg5', + organizations_url: 'https://api.github.com/users/liweijie0812/orgs', + received_events_url: 'https://api.github.com/users/liweijie0812/received_events', + repos_url: 'https://api.github.com/users/liweijie0812/repos', + site_admin: false, + starred_url: 'https://api.github.com/users/liweijie0812/starred{/owner}{/repo}', + subscriptions_url: 'https://api.github.com/users/liweijie0812/subscriptions', + type: 'User', + url: 'https://api.github.com/users/liweijie0812', + }, + }, + repository: { + allow_forking: true, + archive_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/{archive_format}{/ref}', + archived: false, + assignees_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/assignees{/user}', + blobs_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/git/blobs{/sha}', + branches_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/branches{/branch}', + clone_url: 'https://github.com/TDesignOteam/tdesign-changelog-action.git', + collaborators_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/collaborators{/collaborator}', + comments_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/comments{/number}', + commits_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/commits{/sha}', + compare_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/compare/{base}...{head}', + contents_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/contents/{+path}', + contributors_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/contributors', + created_at: '2024-05-31T03:18:52Z', + custom_properties: {}, + default_branch: 'develop', + deployments_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/deployments', + description: null, + disabled: false, + downloads_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/downloads', + events_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/events', + fork: false, + forks: 1, + forks_count: 1, + forks_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/forks', + full_name: 'TDesignOteam/tdesign-changelog-action', + git_commits_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/git/commits{/sha}', + git_refs_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/git/refs{/sha}', + git_tags_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/git/tags{/sha}', + git_url: 'git://github.com/TDesignOteam/tdesign-changelog-action.git', + has_discussions: false, + has_downloads: true, + has_issues: true, + has_pages: false, + has_projects: true, + has_wiki: true, + homepage: null, + hooks_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/hooks', + html_url: 'https://github.com/TDesignOteam/tdesign-changelog-action', + id: 808419936, + is_template: false, + issue_comment_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/issues/comments{/number}', + issue_events_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/issues/events{/number}', + issues_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/issues{/number}', + keys_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/keys{/key_id}', + labels_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/labels{/name}', + language: 'TypeScript', + languages_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/languages', + license: { + key: 'mit', + name: 'MIT License', + node_id: 'MDc6TGljZW5zZTEz', + spdx_id: 'MIT', + url: 'https://api.github.com/licenses/mit', + }, + merges_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/merges', + milestones_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/milestones{/number}', + mirror_url: null, + name: 'tdesign-changelog-action', + node_id: 'R_kgDOMC-CYA', + notifications_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/notifications{?since,all,participating}', + open_issues: 5, + open_issues_count: 5, + owner: { + avatar_url: 'https://avatars.githubusercontent.com/u/39033385?v=4', + events_url: 'https://api.github.com/users/TDesignOteam/events{/privacy}', + followers_url: 'https://api.github.com/users/TDesignOteam/followers', + following_url: 'https://api.github.com/users/TDesignOteam/following{/other_user}', + gists_url: 'https://api.github.com/users/TDesignOteam/gists{/gist_id}', + gravatar_id: '', + html_url: 'https://github.com/TDesignOteam', + id: 39033385, + login: 'TDesignOteam', + node_id: 'MDEyOk9yZ2FuaXphdGlvbjM5MDMzMzg1', + organizations_url: 'https://api.github.com/users/TDesignOteam/orgs', + received_events_url: 'https://api.github.com/users/TDesignOteam/received_events', + repos_url: 'https://api.github.com/users/TDesignOteam/repos', + site_admin: false, + starred_url: 'https://api.github.com/users/TDesignOteam/starred{/owner}{/repo}', + subscriptions_url: 'https://api.github.com/users/TDesignOteam/subscriptions', + type: 'Organization', + url: 'https://api.github.com/users/TDesignOteam', + }, + private: false, + pulls_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/pulls{/number}', + pushed_at: '2024-08-13T08:28:58Z', + releases_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/releases{/id}', + size: 584, + ssh_url: 'git@github.com:TDesignOteam/tdesign-changelog-action.git', + stargazers_count: 0, + stargazers_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/stargazers', + statuses_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/statuses/{sha}', + subscribers_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/subscribers', + subscription_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/subscription', + svn_url: 'https://github.com/TDesignOteam/tdesign-changelog-action', + tags_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/tags', + teams_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/teams', + topics: [], + trees_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/git/trees{/sha}', + updated_at: '2024-08-13T01:15:57Z', + url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action', + visibility: 'public', + watchers: 0, + watchers_count: 0, + web_commit_signoff_required: false, + }, + sender: { + avatar_url: 'https://avatars.githubusercontent.com/u/10710889?v=4', + events_url: 'https://api.github.com/users/liweijie0812/events{/privacy}', + followers_url: 'https://api.github.com/users/liweijie0812/followers', + following_url: 'https://api.github.com/users/liweijie0812/following{/other_user}', + gists_url: 'https://api.github.com/users/liweijie0812/gists{/gist_id}', + gravatar_id: '', + html_url: 'https://github.com/liweijie0812', + id: 10710889, + login: 'liweijie0812', + node_id: 'MDQ6VXNlcjEwNzEwODg5', + organizations_url: 'https://api.github.com/users/liweijie0812/orgs', + received_events_url: 'https://api.github.com/users/liweijie0812/received_events', + repos_url: 'https://api.github.com/users/liweijie0812/repos', + site_admin: false, + starred_url: 'https://api.github.com/users/liweijie0812/starred{/owner}{/repo}', + subscriptions_url: 'https://api.github.com/users/liweijie0812/subscriptions', + type: 'User', + url: 'https://api.github.com/users/liweijie0812', + }, + }, + eventName: 'pull_request', + sha: '0876c48037b11a7b6c7ed01e16dc3ada0ae44cbd', + ref: 'refs/pull/33/merge', + workflow: 'test dist', + action: 'changelog', + actor: 'liweijie0812', + job: 'generator', + runNumber: 20, + runId: 10366307007, + apiUrl: 'https://api.github.com', + serverUrl: 'https://github.com', + graphqlUrl: 'https://api.github.com/graphql', + repo: { + owner: 'TDesignOteam', + repo: 'tdesign-changelog-action', + }, +} + +vi.mock('@actions/github', () => { + return { + context, + } +}) diff --git a/test/setup-octokit.ts b/test/setup-octokit.ts new file mode 100644 index 0000000..b491e6c --- /dev/null +++ b/test/setup-octokit.ts @@ -0,0 +1,314 @@ +import { vi } from 'vitest' +import changelog from './fixtures/changelog' +import { releaseNote } from './fixtures/release-notes' + +const releaseNotesData = { + status: 200, + url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/releases/generate-notes', + data: { name: 'mock-tag-name', body: releaseNote }, +} +const pullRequestData = { + data: { + url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/pulls/29', + id: 2006134041, + node_id: 'PR_kwDOMC-CYM53ky0Z', + html_url: 'https://github.com/TDesignOteam/tdesign-changelog-action/pull/29', + diff_url: 'https://github.com/TDesignOteam/tdesign-changelog-action/pull/29.diff', + patch_url: 'https://github.com/TDesignOteam/tdesign-changelog-action/pull/29.patch', + issue_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/issues/29', + number: 29, + state: 'closed', + locked: false, + title: 'chore: ci enhance', + user: { + login: 'liweijie0812', + id: 10710889, + node_id: 'MDQ6VXNlcjEwNzEwODg5', + avatar_url: 'https://avatars.githubusercontent.com/u/10710889?v=4', + gravatar_id: '', + url: 'https://api.github.com/users/liweijie0812', + html_url: 'https://github.com/liweijie0812', + followers_url: 'https://api.github.com/users/liweijie0812/followers', + following_url: 'https://api.github.com/users/liweijie0812/following{/other_user}', + gists_url: 'https://api.github.com/users/liweijie0812/gists{/gist_id}', + starred_url: 'https://api.github.com/users/liweijie0812/starred{/owner}{/repo}', + subscriptions_url: 'https://api.github.com/users/liweijie0812/subscriptions', + organizations_url: 'https://api.github.com/users/liweijie0812/orgs', + repos_url: 'https://api.github.com/users/liweijie0812/repos', + events_url: 'https://api.github.com/users/liweijie0812/events{/privacy}', + received_events_url: 'https://api.github.com/users/liweijie0812/received_events', + type: 'User', + site_admin: false, + }, + body: `### 📝 更新日志\n\n ${changelog}`, + created_at: '2024-08-06T13:48:12Z', + updated_at: '2024-08-07T01:14:21Z', + closed_at: '2024-08-07T01:14:20Z', + merged_at: '2024-08-07T01:14:19Z', + merge_commit_sha: '5028ec67c707af0a2f99377fe444af3a9598edd4', + assignee: null, + assignees: [], + requested_reviewers: [ + { + login: 'uyarn', + id: 26377630, + node_id: 'MDQ6VXNlcjI2Mzc3NjMw', + avatar_url: 'https://avatars.githubusercontent.com/u/26377630?v=4', + gravatar_id: '', + url: 'https://api.github.com/users/uyarn', + html_url: 'https://github.com/uyarn', + followers_url: 'https://api.github.com/users/uyarn/followers', + following_url: 'https://api.github.com/users/uyarn/following{/other_user}', + gists_url: 'https://api.github.com/users/uyarn/gists{/gist_id}', + starred_url: 'https://api.github.com/users/uyarn/starred{/owner}{/repo}', + subscriptions_url: 'https://api.github.com/users/uyarn/subscriptions', + organizations_url: 'https://api.github.com/users/uyarn/orgs', + repos_url: 'https://api.github.com/users/uyarn/repos', + events_url: 'https://api.github.com/users/uyarn/events{/privacy}', + received_events_url: 'https://api.github.com/users/uyarn/received_events', + type: 'User', + site_admin: false, + }, + ], + requested_teams: [], + labels: [], + milestone: null, + draft: false, + commits_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/pulls/29/commits', + review_comments_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/pulls/29/comments', + review_comment_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/pulls/comments{/number}', + comments_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/issues/29/comments', + statuses_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/statuses/38a9e5522ab653e01758837bfc12b26e2a8f5a0e', + head: { + label: 'TDesignOteam:chore/vitest', + ref: 'chore/vitest', + sha: '38a9e5522ab653e01758837bfc12b26e2a8f5a0e', + user: { + login: 'TDesignOteam', + id: 39033385, + node_id: 'MDEyOk9yZ2FuaXphdGlvbjM5MDMzMzg1', + avatar_url: 'https://avatars.githubusercontent.com/u/39033385?v=4', + gravatar_id: '', + url: 'https://api.github.com/users/TDesignOteam', + html_url: 'https://github.com/TDesignOteam', + followers_url: 'https://api.github.com/users/TDesignOteam/followers', + following_url: 'https://api.github.com/users/TDesignOteam/following{/other_user}', + gists_url: 'https://api.github.com/users/TDesignOteam/gists{/gist_id}', + starred_url: 'https://api.github.com/users/TDesignOteam/starred{/owner}{/repo}', + subscriptions_url: 'https://api.github.com/users/TDesignOteam/subscriptions', + organizations_url: 'https://api.github.com/users/TDesignOteam/orgs', + repos_url: 'https://api.github.com/users/TDesignOteam/repos', + events_url: 'https://api.github.com/users/TDesignOteam/events{/privacy}', + received_events_url: 'https://api.github.com/users/TDesignOteam/received_events', + type: 'Organization', + site_admin: false, + }, + repo: { + id: 808419936, + node_id: 'R_kgDOMC-CYA', + name: 'tdesign-changelog-action', + full_name: 'TDesignOteam/tdesign-changelog-action', + private: false, + owner: { + login: 'TDesignOteam', + id: 39033385, + node_id: 'MDEyOk9yZ2FuaXphdGlvbjM5MDMzMzg1', + avatar_url: 'https://avatars.githubusercontent.com/u/39033385?v=4', + gravatar_id: '', + url: 'https://api.github.com/users/TDesignOteam', + html_url: 'https://github.com/TDesignOteam', + followers_url: 'https://api.github.com/users/TDesignOteam/followers', + following_url: 'https://api.github.com/users/TDesignOteam/following{/other_user}', + gists_url: 'https://api.github.com/users/TDesignOteam/gists{/gist_id}', + starred_url: 'https://api.github.com/users/TDesignOteam/starred{/owner}{/repo}', + subscriptions_url: 'https://api.github.com/users/TDesignOteam/subscriptions', + organizations_url: 'https://api.github.com/users/TDesignOteam/orgs', + repos_url: 'https://api.github.com/users/TDesignOteam/repos', + events_url: 'https://api.github.com/users/TDesignOteam/events{/privacy}', + received_events_url: 'https://api.github.com/users/TDesignOteam/received_events', + type: 'Organization', + site_admin: false, + }, + html_url: 'https://github.com/TDesignOteam/tdesign-changelog-action', + description: null, + fork: false, + url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action', + forks_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/forks', + keys_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/keys{/key_id}', + collaborators_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/collaborators{/collaborator}', + teams_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/teams', + hooks_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/hooks', + issue_events_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/issues/events{/number}', + events_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/events', + assignees_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/assignees{/user}', + branches_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/branches{/branch}', + tags_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/tags', + blobs_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/git/blobs{/sha}', + git_tags_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/git/tags{/sha}', + git_refs_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/git/refs{/sha}', + trees_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/git/trees{/sha}', + statuses_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/statuses/{sha}', + languages_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/languages', + stargazers_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/stargazers', + contributors_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/contributors', + subscribers_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/subscribers', + subscription_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/subscription', + commits_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/commits{/sha}', + git_commits_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/git/commits{/sha}', + comments_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/comments{/number}', + issue_comment_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/issues/comments{/number}', + contents_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/contents/{+path}', + compare_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/compare/{base}...{head}', + merges_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/merges', + archive_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/{archive_format}{/ref}', + downloads_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/downloads', + issues_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/issues{/number}', + pulls_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/pulls{/number}', + milestones_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/milestones{/number}', + notifications_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/notifications{?since,all,participating}', + labels_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/labels{/name}', + releases_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/releases{/id}', + deployments_url: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/deployments', + created_at: '2024-05-31T03:18:52Z', + updated_at: '2024-08-13T01:15:57Z', + pushed_at: '2024-08-13T08:29:00Z', + git_url: 'git://github.com/TDesignOteam/tdesign-changelog-action.git', + ssh_url: 'git@github.com:TDesignOteam/tdesign-changelog-action.git', + clone_url: 'https://github.com/TDesignOteam/tdesign-changelog-action.git', + svn_url: 'https://github.com/TDesignOteam/tdesign-changelog-action', + homepage: null, + size: 584, + stargazers_count: 0, + watchers_count: 0, + language: 'TypeScript', + has_issues: true, + has_projects: true, + has_downloads: true, + has_wiki: true, + has_pages: false, + has_discussions: false, + forks_count: 1, + mirror_url: null, + archived: false, + disabled: false, + open_issues_count: 5, + license: { + key: 'mit', + name: 'MIT License', + spdx_id: 'MIT', + url: 'https://api.github.com/licenses/mit', + node_id: 'MDc6TGljZW5zZTEz', + }, + allow_forking: true, + is_template: false, + web_commit_signoff_required: false, + topics: [], + visibility: 'public', + forks: 1, + open_issues: 5, + watchers: 0, + default_branch: 'develop', + }, + }, + base: { + label: 'TDesignOteam:develop', + ref: 'develop', + sha: '60cf90e0ae1224eb1b6bb3ae2eca2ca4997c7bc1', + user: { + login: 'TDesignOteam', + id: 39033385, + node_id: 'MDEyOk9yZ2FuaXphdGlvbjM5MDMzMzg1', + avatar_url: 'https://avatars.githubusercontent.com/u/39033385?v=4', + gravatar_id: '', + url: 'https://api.github.com/users/TDesignOteam', + html_url: 'https://github.com/TDesignOteam', + followers_url: 'https://api.github.com/users/TDesignOteam/followers', + following_url: 'https://api.github.com/users/TDesignOteam/following{/other_user}', + gists_url: 'https://api.github.com/users/TDesignOteam/gists{/gist_id}', + starred_url: 'https://api.github.com/users/TDesignOteam/starred{/owner}{/repo}', + subscriptions_url: 'https://api.github.com/users/TDesignOteam/subscriptions', + organizations_url: 'https://api.github.com/users/TDesignOteam/orgs', + repos_url: 'https://api.github.com/users/TDesignOteam/repos', + events_url: 'https://api.github.com/users/TDesignOteam/events{/privacy}', + received_events_url: 'https://api.github.com/users/TDesignOteam/received_events', + type: 'Organization', + site_admin: false, + }, + repo: { + id: 808419936, + node_id: 'R_kgDOMC-CYA', + name: 'tdesign-changelog-action', + full_name: 'TDesignOteam/tdesign-changelog-action', + private: false, + owner: { + login: 'TDesignOteam', + id: 39033385, + node_id: 'MDEyOk9yZ2FuaXphdGlvbjM5MDMzMzg1', + avatar_url: 'https://avatars.githubusercontent.com/u/39033385?v=4', + gravatar_id: '', + url: 'https://api.github.com/users/TDesignOteam', + html_url: 'https://github.com/TDesignOteam', + followers_url: 'https://api.github.com/users/TDesignOteam/followers', + following_url: 'https://api.github.com/users/TDesignOteam/following{/other_user}', + gists_url: 'https://api.github.com/users/TDesignOteam/gists{/gist_id}', + starred_url: 'https://api.github.com/users/TDesignOteam/starred{/owner}{/repo}', + href: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/issues/29/comments', + }, + review_comments: { + href: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/pulls/29/comments', + }, + review_comment: { + href: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/pulls/comments{/number}', + }, + commits: { + href: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/pulls/29/commits', + }, + statuses: { + href: 'https://api.github.com/repos/TDesignOteam/tdesign-changelog-action/statuses/38a9e5522ab653e01758837bfc12b26e2a8f5a0e', + }, + }, + author_association: 'MEMBER', + auto_merge: null, + active_lock_reason: null, + merged: true, + mergeable: null, + rebaseable: null, + mergeable_state: 'unknown', + merged_by: { + login: 'liweijie0812', + id: 10710889, + node_id: 'MDQ6VXNlcjEwNzEwODg5', + avatar_url: 'https://avatars.githubusercontent.com/u/10710889?v=4', + gravatar_id: '', + url: 'https://api.github.com/users/liweijie0812', + html_url: 'https://github.com/liweijie0812', + followers_url: 'https://api.github.com/users/liweijie0812/followers', + following_url: 'https://api.github.com/users/liweijie0812/following{/other_user}', + gists_url: 'https://api.github.com/users/liweijie0812/gists{/gist_id}', + starred_url: 'https://api.github.com/users/liweijie0812/starred{/owner}{/repo}', + subscriptions_url: 'https://api.github.com/users/liweijie0812/subscriptions', + organizations_url: 'https://api.github.com/users/liweijie0812/orgs', + repos_url: 'https://api.github.com/users/liweijie0812/repos', + events_url: 'https://api.github.com/users/liweijie0812/events{/privacy}', + received_events_url: 'https://api.github.com/users/liweijie0812/received_events', + type: 'User', + site_admin: false, + }, + comments: 1, + review_comments: 0, + maintainer_can_modify: false, + commits: 15, + additions: 1152, + deletions: 340, + changed_files: 15, + }, + }, +} +vi.mock('../src/use-octokit', () => { + return { + useOctokit: () => ({ + generateReleaseNotes: () => Promise.resolve(releaseNotesData), + getPullRequest: () => Promise.resolve(pullRequestData), + }), + } +}) diff --git a/vitest.config.mts b/vitest.config.mts index 53e9ef0..5cf1ae5 100644 --- a/vitest.config.mts +++ b/vitest.config.mts @@ -3,5 +3,6 @@ import { defineConfig } from 'vitest/config' export default defineConfig({ test: { // ... + setupFiles: ['./test/setup-env.ts', './test/setup-github.ts', './test/setup-octokit.ts'], }, }) From bf95bfdb8d1e30358cb17eb24a1e8ebe42b74b4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=8E=E4=BC=9F=E6=9D=B0?= <674416404@qq.com> Date: Mon, 9 Sep 2024 12:23:35 +0800 Subject: [PATCH 13/22] chore: fix lint --- src/index.ts | 2 +- test/index.test.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index d0e682c..c649d67 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,5 @@ import process from 'node:process' -import { getInput, info, setFailed, setOutput } from '@actions/core' +import { info, setFailed } from '@actions/core' import { context } from '@actions/github' import { generatorLogStart } from './generator' diff --git a/test/index.test.ts b/test/index.test.ts index 9839ecf..d29dbea 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -1,4 +1,4 @@ -import { assert, describe, expect, it, vi } from 'vitest' +import { assert, describe, expect, it } from 'vitest' describe('index', () => { it('index', () => { From 44e5ef316606ac4fedf2233fb1f2ae18ee001ef9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=8E=E4=BC=9F=E6=9D=B0?= <674416404@qq.com> Date: Mon, 9 Sep 2024 12:31:47 +0800 Subject: [PATCH 14/22] fix: log title is empty --- src/renderer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderer.ts b/src/renderer.ts index 3d6d661..e7d3142 100644 --- a/src/renderer.ts +++ b/src/renderer.ts @@ -24,7 +24,7 @@ function regToPrObj(arr: string[]) { } function renderCate(cate: PRChangelog[]) { return `${cate.sort().map((pr) => { - const title = pr.changelog ? `\`${pr.changelog.component}\`: ${pr.changelog.desc}` : pr.title + const title = pr.changelog ? `\`${pr.changelog.component || pr.changelog.cate}\`: ${pr.changelog.desc}` : pr.title return `- ${title} @${pr.user.login} ([#${pr.number}](${pr.html_url}))` }).join('\n')}` } From 5c7586304a2e900007c9b5fd6d5b3d287afcb313 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=8E=E4=BC=9F=E6=9D=B0?= <674416404@qq.com> Date: Mon, 9 Sep 2024 16:37:55 +0800 Subject: [PATCH 15/22] chore: update snapshot --- test/__snapshots__/generatorLog.test.ts.snap | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/__snapshots__/generatorLog.test.ts.snap b/test/__snapshots__/generatorLog.test.ts.snap index 3c981bd..82700be 100644 --- a/test/__snapshots__/generatorLog.test.ts.snap +++ b/test/__snapshots__/generatorLog.test.ts.snap @@ -18,7 +18,7 @@ exports[`generatorLog > : generatorLogStart 1`] = ` - \`A\`: a bug fix label in hotfix @liweijie0812 ([#29](https://github.com/TDesignOteam/tdesign-changelog-action/pull/29)) - \`A\`: a bug fix label in bug @liweijie0812 ([#29](https://github.com/TDesignOteam/tdesign-changelog-action/pull/29)) ### 🚧 Others -- \`\`: a doc change label in docs @liweijie0812 ([#29](https://github.com/TDesignOteam/tdesign-changelog-action/pull/29)) -- \`\`: a chore label in chore @liweijie0812 ([#29](https://github.com/TDesignOteam/tdesign-changelog-action/pull/29)) +- \`docs\`: a doc change label in docs @liweijie0812 ([#29](https://github.com/TDesignOteam/tdesign-changelog-action/pull/29)) +- \`chore\`: a chore label in chore @liweijie0812 ([#29](https://github.com/TDesignOteam/tdesign-changelog-action/pull/29)) " `; From 6c21c4fb9e0a6e7976196e73e0c9e39c5a5d1692 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=8E=E4=BC=9F=E6=9D=B0?= <674416404@qq.com> Date: Mon, 9 Sep 2024 18:01:04 +0800 Subject: [PATCH 16/22] feat: log label refactor --- test/__snapshots__/generatorLog.test.ts.snap | 1 + test/__snapshots__/regexp.test.ts.snap | 6 ++++++ test/fixtures/changelog.ts | 1 + test/regexp.test.ts | 2 +- 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/test/__snapshots__/generatorLog.test.ts.snap b/test/__snapshots__/generatorLog.test.ts.snap index 82700be..0b7be34 100644 --- a/test/__snapshots__/generatorLog.test.ts.snap +++ b/test/__snapshots__/generatorLog.test.ts.snap @@ -20,5 +20,6 @@ exports[`generatorLog > : generatorLogStart 1`] = ` ### 🚧 Others - \`docs\`: a doc change label in docs @liweijie0812 ([#29](https://github.com/TDesignOteam/tdesign-changelog-action/pull/29)) - \`chore\`: a chore label in chore @liweijie0812 ([#29](https://github.com/TDesignOteam/tdesign-changelog-action/pull/29)) +- \`I\`: a refactor label in refactor @liweijie0812 ([#29](https://github.com/TDesignOteam/tdesign-changelog-action/pull/29)) " `; diff --git a/test/__snapshots__/regexp.test.ts.snap b/test/__snapshots__/regexp.test.ts.snap index 5a4e896..a7a4bbb 100644 --- a/test/__snapshots__/regexp.test.ts.snap +++ b/test/__snapshots__/regexp.test.ts.snap @@ -80,6 +80,12 @@ exports[`regexp > : CHANGELOG_REG 1`] = ` "H H", "a major update label in break", ], + [ + "- refactor(I): a refactor label in refactor", + "refactor", + "I", + "a refactor label in refactor", + ], ] `; diff --git a/test/fixtures/changelog.ts b/test/fixtures/changelog.ts index 2b6261e..5dfcce5 100644 --- a/test/fixtures/changelog.ts +++ b/test/fixtures/changelog.ts @@ -12,6 +12,7 @@ export const changelog = ` - chore: a chore label in chore - break(g): a minor fix label in break - break(H H): a major update label in break +- refactor(I): a refactor label in refactor ` export default changelog diff --git a/test/regexp.test.ts b/test/regexp.test.ts index 58deba1..5823aa2 100644 --- a/test/regexp.test.ts +++ b/test/regexp.test.ts @@ -7,7 +7,7 @@ describe('regexp', () => { it(': CHANGELOG_REG', () => { const result = changelog.matchAll(CHANGELOG_REG) const arr = [...result] - expect(arr.length).toBe(13) + expect(arr.length).toBe(14) expect(arr).toMatchSnapshot() }) From 4b9d25950357c1064ed0ad0d373d4c3cb682ab5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=8E=E4=BC=9F=E6=9D=B0?= <674416404@qq.com> Date: Thu, 26 Sep 2024 23:00:41 +0800 Subject: [PATCH 17/22] chore: file rename --- src/generator.ts | 2 +- src/{use-octokit.ts => useOctokit.ts} | 0 test/{setup-env.ts => setupEnv.ts} | 0 test/{setup-github.ts => setupGithub.ts} | 0 test/{setup-octokit.ts => setupOctokit.ts} | 2 +- vitest.config.mts | 2 +- 6 files changed, 3 insertions(+), 3 deletions(-) rename src/{use-octokit.ts => useOctokit.ts} (100%) rename test/{setup-env.ts => setupEnv.ts} (100%) rename test/{setup-github.ts => setupGithub.ts} (100%) rename test/{setup-octokit.ts => setupOctokit.ts} (99%) diff --git a/src/generator.ts b/src/generator.ts index f9700a0..a849d3d 100644 --- a/src/generator.ts +++ b/src/generator.ts @@ -4,7 +4,7 @@ import { getInput, info, setOutput } from '@actions/core' import dayjs from 'dayjs' import { getPullNumbers, renderMarkdown } from './renderer' import type { PullsData } from './types' -import { useOctokit } from './use-octokit' +import { useOctokit } from './useOctokit' export async function generatorLogStart(context) { const GITHUB_TOKEN = process.env.GITHUB_TOKEN || '' diff --git a/src/use-octokit.ts b/src/useOctokit.ts similarity index 100% rename from src/use-octokit.ts rename to src/useOctokit.ts diff --git a/test/setup-env.ts b/test/setupEnv.ts similarity index 100% rename from test/setup-env.ts rename to test/setupEnv.ts diff --git a/test/setup-github.ts b/test/setupGithub.ts similarity index 100% rename from test/setup-github.ts rename to test/setupGithub.ts diff --git a/test/setup-octokit.ts b/test/setupOctokit.ts similarity index 99% rename from test/setup-octokit.ts rename to test/setupOctokit.ts index b491e6c..df0e853 100644 --- a/test/setup-octokit.ts +++ b/test/setupOctokit.ts @@ -304,7 +304,7 @@ const pullRequestData = { }, }, } -vi.mock('../src/use-octokit', () => { +vi.mock('../src/useOctokit', () => { return { useOctokit: () => ({ generateReleaseNotes: () => Promise.resolve(releaseNotesData), diff --git a/vitest.config.mts b/vitest.config.mts index 5cf1ae5..71b74f2 100644 --- a/vitest.config.mts +++ b/vitest.config.mts @@ -3,6 +3,6 @@ import { defineConfig } from 'vitest/config' export default defineConfig({ test: { // ... - setupFiles: ['./test/setup-env.ts', './test/setup-github.ts', './test/setup-octokit.ts'], + setupFiles: ['./test/setupEnv.ts', './test/setupGithub.ts', './test/setupOctokit.ts'], }, }) From 64d3b6c3a8307afcd36776bfd4c897a65fdc1841 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=8E=E4=BC=9F=E6=9D=B0?= <674416404@qq.com> Date: Thu, 26 Sep 2024 23:13:19 +0800 Subject: [PATCH 18/22] feat(log): Documentation label --- src/renderer.ts | 29 +++++++------------- test/__snapshots__/generatorLog.test.ts.snap | 3 +- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/renderer.ts b/src/renderer.ts index e7d3142..0e8ccb6 100644 --- a/src/renderer.ts +++ b/src/renderer.ts @@ -5,6 +5,7 @@ const skipChangelogLabel = ['skip-changelog'] const fixLabel = ['fix', 'bug', 'hotfix'] const breakingLabel = ['break', 'breaking', 'breaking changes'] const featureLabel = ['feature', 'feat', 'enhancement'] +const docsLabel = ['docs', 'doc', 'documentation'] export const CHANGELOG_REG = /-\s([A-Z]+)(?:\(([A-Z\s]*)\))?:\s(.+)/gi export const PULL_NUMBER_REG = /in\shttps:\/\/github\.com\/.+\/pull\/(\d+)/g export const SKIP_CHANGELOG_REG = /\[x\] 本条 PR 不需要纳入 changelog/i @@ -36,6 +37,7 @@ export function renderMarkdown(pullRequestList: PullsData[]) { breaking: [] as PRChangelog[], features: [] as PRChangelog[], bugfix: [] as PRChangelog[], + docs: [] as PRChangelog[], extra: [] as PRChangelog[], } @@ -81,6 +83,9 @@ export function renderMarkdown(pullRequestList: PullsData[]) { else if (isInLabel(fixLabel)) { categories.bugfix.push(logItem) } + else if (isInLabel(docsLabel)) { + categories.docs.push(logItem) + } else { categories.extra.push(logItem) } @@ -94,24 +99,10 @@ export function renderMarkdown(pullRequestList: PullsData[]) { }) return [ - categories.breaking.length - ? `### ❗ Breaking Changes -${renderCate(categories.breaking)}` - : '', - - categories.features.length - ? `### 🚀 Features -${renderCate(categories.features)}` - : '', - - categories.bugfix.length - ? `### 🐞 Bug Fixes -${renderCate(categories.bugfix)}` - : '', - - categories.extra.length - ? `### 🚧 Others -${renderCate(categories.extra)}` - : '', + categories.breaking.length ? `### ❗ Breaking Changes\n${renderCate(categories.breaking)}` : '', + categories.features.length ? `### 🚀 Features\n${renderCate(categories.features)}` : '', + categories.bugfix.length ? `### 🐞 Bug Fixes\n${renderCate(categories.bugfix)}` : '', + categories.docs.length ? `### 📝 Documentation\n${renderCate(categories.docs)}` : '', + categories.extra.length ? `### 🚧 Others\n${renderCate(categories.extra)}` : '', ].filter(n => n).join('\n') } diff --git a/test/__snapshots__/generatorLog.test.ts.snap b/test/__snapshots__/generatorLog.test.ts.snap index 0b7be34..ea185f9 100644 --- a/test/__snapshots__/generatorLog.test.ts.snap +++ b/test/__snapshots__/generatorLog.test.ts.snap @@ -17,8 +17,9 @@ exports[`generatorLog > : generatorLogStart 1`] = ` - \`A\`: a bug fix label in fix @liweijie0812 ([#29](https://github.com/TDesignOteam/tdesign-changelog-action/pull/29)) - \`A\`: a bug fix label in hotfix @liweijie0812 ([#29](https://github.com/TDesignOteam/tdesign-changelog-action/pull/29)) - \`A\`: a bug fix label in bug @liweijie0812 ([#29](https://github.com/TDesignOteam/tdesign-changelog-action/pull/29)) -### 🚧 Others +### 📝 Documentation - \`docs\`: a doc change label in docs @liweijie0812 ([#29](https://github.com/TDesignOteam/tdesign-changelog-action/pull/29)) +### 🚧 Others - \`chore\`: a chore label in chore @liweijie0812 ([#29](https://github.com/TDesignOteam/tdesign-changelog-action/pull/29)) - \`I\`: a refactor label in refactor @liweijie0812 ([#29](https://github.com/TDesignOteam/tdesign-changelog-action/pull/29)) " From 810ee40628d61684424b8d9d79b301bd27f1ebfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=8E=E4=BC=9F=E6=9D=B0?= <674416404@qq.com> Date: Thu, 26 Sep 2024 23:17:27 +0800 Subject: [PATCH 19/22] feat(log): Performance label --- src/renderer.ts | 7 +++++++ test/__snapshots__/generatorLog.test.ts.snap | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/renderer.ts b/src/renderer.ts index 0e8ccb6..d4fe490 100644 --- a/src/renderer.ts +++ b/src/renderer.ts @@ -6,6 +6,8 @@ const fixLabel = ['fix', 'bug', 'hotfix'] const breakingLabel = ['break', 'breaking', 'breaking changes'] const featureLabel = ['feature', 'feat', 'enhancement'] const docsLabel = ['docs', 'doc', 'documentation'] +const refactorLabel = ['pref', 'refactor'] + export const CHANGELOG_REG = /-\s([A-Z]+)(?:\(([A-Z\s]*)\))?:\s(.+)/gi export const PULL_NUMBER_REG = /in\shttps:\/\/github\.com\/.+\/pull\/(\d+)/g export const SKIP_CHANGELOG_REG = /\[x\] 本条 PR 不需要纳入 changelog/i @@ -37,6 +39,7 @@ export function renderMarkdown(pullRequestList: PullsData[]) { breaking: [] as PRChangelog[], features: [] as PRChangelog[], bugfix: [] as PRChangelog[], + refactor: [] as PRChangelog[], docs: [] as PRChangelog[], extra: [] as PRChangelog[], } @@ -83,6 +86,9 @@ export function renderMarkdown(pullRequestList: PullsData[]) { else if (isInLabel(fixLabel)) { categories.bugfix.push(logItem) } + else if (isInLabel(refactorLabel)) { + categories.refactor.push(logItem) + } else if (isInLabel(docsLabel)) { categories.docs.push(logItem) } @@ -102,6 +108,7 @@ export function renderMarkdown(pullRequestList: PullsData[]) { categories.breaking.length ? `### ❗ Breaking Changes\n${renderCate(categories.breaking)}` : '', categories.features.length ? `### 🚀 Features\n${renderCate(categories.features)}` : '', categories.bugfix.length ? `### 🐞 Bug Fixes\n${renderCate(categories.bugfix)}` : '', + categories.refactor.length ? `### 📈 Performance\n${renderCate(categories.refactor)}` : '', categories.docs.length ? `### 📝 Documentation\n${renderCate(categories.docs)}` : '', categories.extra.length ? `### 🚧 Others\n${renderCate(categories.extra)}` : '', ].filter(n => n).join('\n') diff --git a/test/__snapshots__/generatorLog.test.ts.snap b/test/__snapshots__/generatorLog.test.ts.snap index ea185f9..76e37db 100644 --- a/test/__snapshots__/generatorLog.test.ts.snap +++ b/test/__snapshots__/generatorLog.test.ts.snap @@ -17,10 +17,11 @@ exports[`generatorLog > : generatorLogStart 1`] = ` - \`A\`: a bug fix label in fix @liweijie0812 ([#29](https://github.com/TDesignOteam/tdesign-changelog-action/pull/29)) - \`A\`: a bug fix label in hotfix @liweijie0812 ([#29](https://github.com/TDesignOteam/tdesign-changelog-action/pull/29)) - \`A\`: a bug fix label in bug @liweijie0812 ([#29](https://github.com/TDesignOteam/tdesign-changelog-action/pull/29)) +### 📈 Performance +- \`I\`: a refactor label in refactor @liweijie0812 ([#29](https://github.com/TDesignOteam/tdesign-changelog-action/pull/29)) ### 📝 Documentation - \`docs\`: a doc change label in docs @liweijie0812 ([#29](https://github.com/TDesignOteam/tdesign-changelog-action/pull/29)) ### 🚧 Others - \`chore\`: a chore label in chore @liweijie0812 ([#29](https://github.com/TDesignOteam/tdesign-changelog-action/pull/29)) -- \`I\`: a refactor label in refactor @liweijie0812 ([#29](https://github.com/TDesignOteam/tdesign-changelog-action/pull/29)) " `; From ea1d95de13f93edd2c0b987d92cc0db7b6a545c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=8E=E4=BC=9F=E6=9D=B0?= <674416404@qq.com> Date: Thu, 26 Sep 2024 23:24:29 +0800 Subject: [PATCH 20/22] fix: indent --- src/generator.ts | 2 +- test/__snapshots__/generatorLog.test.ts.snap | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/generator.ts b/src/generator.ts index a849d3d..0043f1f 100644 --- a/src/generator.ts +++ b/src/generator.ts @@ -37,7 +37,7 @@ export async function generatorLogStart(context) { info(`PRList:${JSON.stringify(PRList)}`) const logRelease = `(删除此行代表确认该日志): 修改并确认日志后删除这一行,机器人会提交到 本 PR 的 CHANGELOG.md 文件中 - ## 🌈 ${tag} \`${dayjs().format('YYYY-MM-DD')}\` \n${renderMarkdown(PRList)}\n` +## 🌈 ${tag} \`${dayjs().format('YYYY-MM-DD')}\` \n${renderMarkdown(PRList)}\n` info(logRelease) diff --git a/test/__snapshots__/generatorLog.test.ts.snap b/test/__snapshots__/generatorLog.test.ts.snap index 76e37db..57a94f2 100644 --- a/test/__snapshots__/generatorLog.test.ts.snap +++ b/test/__snapshots__/generatorLog.test.ts.snap @@ -2,7 +2,7 @@ exports[`generatorLog > : generatorLogStart 1`] = ` "(删除此行代表确认该日志): 修改并确认日志后删除这一行,机器人会提交到 本 PR 的 CHANGELOG.md 文件中 - ## 🌈 0.2.0 \`2024-02-24\` +## 🌈 0.2.0 \`2024-02-24\` ### ❗ Breaking Changes - \`C\`: a major update label in break @liweijie0812 ([#29](https://github.com/TDesignOteam/tdesign-changelog-action/pull/29)) - \`C\`: a major update label in breaking @liweijie0812 ([#29](https://github.com/TDesignOteam/tdesign-changelog-action/pull/29)) From 3f321ade233bfb45a48397152b5f8a92d7e7dc56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=8E=E4=BC=9F=E6=9D=B0?= <674416404@qq.com> Date: Fri, 27 Sep 2024 23:51:16 +0800 Subject: [PATCH 21/22] feat: mock package version --- src/generator.ts | 4 ++-- test/generatorLog.test.ts | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/generator.ts b/src/generator.ts index 0043f1f..57fc298 100644 --- a/src/generator.ts +++ b/src/generator.ts @@ -1,4 +1,4 @@ -import fs from 'node:fs' +import { readFileSync } from 'node:fs' import process from 'node:process' import { getInput, info, setOutput } from '@actions/core' import dayjs from 'dayjs' @@ -11,7 +11,7 @@ export async function generatorLogStart(context) { const { generateReleaseNotes, getPullRequest } = useOctokit({ token: GITHUB_TOKEN }) let tag = getInput('tag', { required: false }) if (!tag) { - const pkg = JSON.parse(fs.readFileSync('./package.json', 'utf-8')) + const pkg = JSON.parse(readFileSync('./package.json', 'utf-8')) tag = pkg.version } const { owner, repo } = context.repo diff --git a/test/generatorLog.test.ts b/test/generatorLog.test.ts index 9bad8e5..95f81ca 100644 --- a/test/generatorLog.test.ts +++ b/test/generatorLog.test.ts @@ -2,6 +2,13 @@ import { describe, expect, it, vi } from 'vitest' import { context } from '@actions/github' import { generatorLogStart } from '../src/generator' +vi.mock('node:fs', async () => { + return { + ...(await vi.importActual('node:fs')), + readFileSync: vi.fn().mockReturnValue(`{ "version": "x.x.x" }`), + } +}) + describe('generatorLog', () => { it(': generatorLogStart', async () => { const mockDate = new Date(2024, 1, 24) From 7a0c3100597bd60c571cbfbffdede0d222962cbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=8E=E4=BC=9F=E6=9D=B0?= <674416404@qq.com> Date: Fri, 27 Sep 2024 23:52:06 +0800 Subject: [PATCH 22/22] chore: update snapshot --- test/__snapshots__/generatorLog.test.ts.snap | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/__snapshots__/generatorLog.test.ts.snap b/test/__snapshots__/generatorLog.test.ts.snap index 57a94f2..b9a9c40 100644 --- a/test/__snapshots__/generatorLog.test.ts.snap +++ b/test/__snapshots__/generatorLog.test.ts.snap @@ -2,7 +2,7 @@ exports[`generatorLog > : generatorLogStart 1`] = ` "(删除此行代表确认该日志): 修改并确认日志后删除这一行,机器人会提交到 本 PR 的 CHANGELOG.md 文件中 -## 🌈 0.2.0 \`2024-02-24\` +## 🌈 x.x.x \`2024-02-24\` ### ❗ Breaking Changes - \`C\`: a major update label in break @liweijie0812 ([#29](https://github.com/TDesignOteam/tdesign-changelog-action/pull/29)) - \`C\`: a major update label in breaking @liweijie0812 ([#29](https://github.com/TDesignOteam/tdesign-changelog-action/pull/29))