From e86b0ad68b340c6c285a623c8aa5a873de1faa45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20B=C3=B6hm?= Date: Thu, 13 Apr 2023 16:55:33 +0200 Subject: [PATCH 1/4] refactor: remove explicit return statements --- .commitlintrc.cjs | 1 + src/getDependencyReleaseLine.ts | 5 +---- src/getReleaseLine.ts | 6 +++--- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/.commitlintrc.cjs b/.commitlintrc.cjs index 848b43c..e054271 100644 --- a/.commitlintrc.cjs +++ b/.commitlintrc.cjs @@ -5,5 +5,6 @@ module.exports = { ...defaultConfig, prompt: { ...defaultConfig.prompt, + allowEmptyScopes: true, }, }; diff --git a/src/getDependencyReleaseLine.ts b/src/getDependencyReleaseLine.ts index 430eefa..f3d7c3c 100644 --- a/src/getDependencyReleaseLine.ts +++ b/src/getDependencyReleaseLine.ts @@ -3,10 +3,7 @@ import type { GetDependencyReleaseLine, NewChangesetWithCommit } from '@changese import { errorMessage } from './utils'; -async function getDependencyReleaseLinks( - changesets: NewChangesetWithCommit[], - repository: string, -): Promise { +async function getDependencyReleaseLinks(changesets: NewChangesetWithCommit[], repository: string) { const changesetLinks = await Promise.all( changesets.map(async (cs) => { // istanbul ignore next: because of our mocked get-github-info -- @preserve diff --git a/src/getReleaseLine.ts b/src/getReleaseLine.ts index 1bf2325..0a7af27 100644 --- a/src/getReleaseLine.ts +++ b/src/getReleaseLine.ts @@ -44,7 +44,7 @@ async function getGitHubLinks( commit?: string, commitFromSummary?: string, prFromSummary?: number, -): Promise { +) { let githubLinks: GithubLinks = { commit: undefined, pull: undefined, user: undefined }; if (prFromSummary) { @@ -82,7 +82,7 @@ async function getGitHubLinks( return githubLinks; } -function getUserLink(usersFromSummary: string[], user?: string): string | undefined { +function getUserLink(usersFromSummary: string[], user?: string) { const userLink = usersFromSummary.length > 0 ? usersFromSummary @@ -96,7 +96,7 @@ function getUserLink(usersFromSummary: string[], user?: string): string | undefi // add links to issue hints (fix #123) => (fix [#123](https://....)) // thanks to https://github.com/svitejs/changesets-changelog-github-compact -function linkifyIssue(line: string, repository: string): string { +function linkifyIssue(line: string, repository: string) { return line.replace(/(?<=\( ?(?:fix|fixes|resolves|see) )(#\d+)(?= ?\))/g, (issue) => { return `[${issue}](https://github.com/${repository}/issues/${issue.slice(1)})`; }); From 7fcecaf4f34f1d02191317dd68b8646fa42327c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20B=C3=B6hm?= Date: Thu, 13 Apr 2023 17:01:05 +0200 Subject: [PATCH 2/4] feat!: reformat changelog output The new output looks like: "#PR (USER): MESSAGE" closes #19 --- .changeset/cuddly-carrots-train.md | 5 +++++ src/getReleaseLine.ts | 9 ++++----- 2 files changed, 9 insertions(+), 5 deletions(-) create mode 100644 .changeset/cuddly-carrots-train.md diff --git a/.changeset/cuddly-carrots-train.md b/.changeset/cuddly-carrots-train.md new file mode 100644 index 0000000..630d0c0 --- /dev/null +++ b/.changeset/cuddly-carrots-train.md @@ -0,0 +1,5 @@ +--- +'@mheob/changeset-changelog': major +--- + +reformat the changelog output to displzy first the PR and user diff --git a/src/getReleaseLine.ts b/src/getReleaseLine.ts index 0a7af27..4b14505 100644 --- a/src/getReleaseLine.ts +++ b/src/getReleaseLine.ts @@ -91,7 +91,7 @@ function getUserLink(usersFromSummary: string[], user?: string) { .trim() : user; - return userLink ? `by ${userLink}` : undefined; + return userLink ? `(${userLink})` : ''; } // add links to issue hints (fix #123) => (fix [#123](https://....)) @@ -120,12 +120,11 @@ export const getReleaseLine: GetReleaseLine = async (changeset, _type, options) const prMessage = pull ? `(${pull})` : ''; const commitMessage = commit ? `(${commit})` : ''; - const userLinkMessage = userLink ?? ''; // istanbul ignore next: because of our mocked get-github-info -- @preserve - const printPrOrCommit = pull !== '' ? prMessage : commitMessage; - const suffix = printPrOrCommit.trim() ? ` --> ${printPrOrCommit.trim()} ${userLinkMessage}` : ''; + const printPrOrCommit = (pull !== '' ? prMessage : commitMessage).trim(); + const prefix = printPrOrCommit ? `${printPrOrCommit} ${userLink}: ` : ''; const futureLinesMessage = futureLines.map((line) => ` ${line}`).join('\n'); - return `\n\n- ${firstLine}${suffix}\n${futureLinesMessage}`; + return `\n\n- ${prefix}${firstLine}\n${futureLinesMessage}`; }; From c1b3ec61c3c6bbd08256c267bb6a3c76d8f55ae2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20B=C3=B6hm?= Date: Thu, 13 Apr 2023 17:09:07 +0200 Subject: [PATCH 3/4] test: fix new strings in the unit tests --- src/getReleaseLine.ts | 4 ++-- src/index.test.ts | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/getReleaseLine.ts b/src/getReleaseLine.ts index 4b14505..ea6e349 100644 --- a/src/getReleaseLine.ts +++ b/src/getReleaseLine.ts @@ -118,8 +118,8 @@ export const getReleaseLine: GetReleaseLine = async (changeset, _type, options) .split('\n') .map((line) => linkifyIssue(line.trimEnd(), options['repo'])); - const prMessage = pull ? `(${pull})` : ''; - const commitMessage = commit ? `(${commit})` : ''; + const prMessage = pull ? `${pull}` : ''; + const commitMessage = commit ? `${commit}` : ''; // istanbul ignore next: because of our mocked get-github-info -- @preserve const printPrOrCommit = (pull !== '' ? prMessage : commitMessage).trim(); const prefix = printPrOrCommit ? `${printPrOrCommit} ${userLink}: ` : ''; diff --git a/src/index.test.ts b/src/index.test.ts index acc93fc..d85f289 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -112,7 +112,7 @@ describe('getReplacedChangelog', () => { ); const result = await getReleaseLine(changeset, 'minor', { repo: data.repo }); expect(result).toBe( - '\n\n- An awesome feature. --> ([#2](https://github.com/mheob/changeset-changelog/pull/2)) by [@mheob](https://github.com/mheob)\n', + '\n\n- [#2](https://github.com/mheob/changeset-changelog/pull/2) ([@mheob](https://github.com/mheob)): An awesome feature.\n', ); }); @@ -120,7 +120,7 @@ describe('getReplacedChangelog', () => { const changeset = getChangeset('An awesome feature.', data.commit); const result = await getReleaseLine(changeset, 'minor', { repo: data.repo }); expect(result).toBe( - '\n\n- An awesome feature. --> ([#2](https://github.com/mheob/changeset-changelog/pull/2)) by [@mheob](https://github.com/mheob)\n', + '\n\n- [#2](https://github.com/mheob/changeset-changelog/pull/2) ([@mheob](https://github.com/mheob)): An awesome feature.\n', ); }); @@ -128,7 +128,7 @@ describe('getReplacedChangelog', () => { const changeset = getChangeset('An awesome feature, (resolves #9)', data.commit); const result = await getReleaseLine(changeset, 'minor', { repo: data.repo }); expect(result).toBe( - '\n\n- An awesome feature, (resolves [#9](https://github.com/mheob/changeset-changelog/issues/9)) --> ([#2](https://github.com/mheob/changeset-changelog/pull/2)) by [@mheob](https://github.com/mheob)\n', + '\n\n- [#2](https://github.com/mheob/changeset-changelog/pull/2) ([@mheob](https://github.com/mheob)): An awesome feature, (resolves [#9](https://github.com/mheob/changeset-changelog/issues/9))\n', ); }); From 33b24b8cb56c04a704d35b33b5879081ef79e513 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20B=C3=B6hm?= Date: Thu, 13 Apr 2023 17:16:07 +0200 Subject: [PATCH 4/4] docs: add changes to the README --- README.md | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9a12c69..d687974 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,13 @@ # `@mheob/changeset-changelog` -[![Release](https://github.com/mheob/changeset-changelog/actions/workflows/release.yml/badge.svg)](https://github.com/mheob/changeset-changelog/actions/workflows/release.yml) [![Check](https://github.com/mheob/changeset-changelog/actions/workflows/check.yml/badge.svg)](https://github.com/mheob/changeset-changelog/actions/workflows/check.yml) [![codecov](https://codecov.io/gh/mheob/changeset-changelog/branch/main/graph/badge.svg?token=E7RZLWHMEX)](https://codecov.io/gh/mheob/changeset-changelog) +[![Release](https://github.com/mheob/changeset-changelog/actions/workflows/release.yml/badge.svg)](https://github.com/mheob/changeset-changelog/actions/workflows/release.yml) +[![Check](https://github.com/mheob/changeset-changelog/actions/workflows/check.yml/badge.svg)](https://github.com/mheob/changeset-changelog/actions/workflows/check.yml) +[![codecov](https://codecov.io/gh/mheob/changeset-changelog/branch/main/graph/badge.svg?token=E7RZLWHMEX)](https://codecov.io/gh/mheob/changeset-changelog) -Add my own style for the changelogs generated by the awesome [changesets](https://github.com/changesets/changesets) library. The style was inspired by the original [@changesets/changelog-github](https://github.com/changesets/changesets/tree/main/packages/changelog-github) and the [@svitejs/changesets-changelog-github-compact](https://github.com/svitejs/changesets-changelog-github-compact) packages. +Add my own style for the changelogs generated by the awesome [changesets](https://github.com/changesets/changesets) library. The +style was inspired by the original +[@changesets/changelog-github](https://github.com/changesets/changesets/tree/main/packages/changelog-github) and the +[@svitejs/changesets-changelog-github-compact](https://github.com/svitejs/changesets-changelog-github-compact) packages. ## Installation @@ -54,8 +59,8 @@ There are differences between this changelog output and the others: -- Add nice feature to the project with a PR and commit --> ([#PR](#)) by [@user](#) -- Add nice feature to the project without a PR --> ([commit](#)) by [@user](#) +- [PR](#) ([@user](#)): Add nice feature to the project with a PR and commit +- [commit](#) ([@user](#)): Add nice feature to the project without a PR ## Additional feature: linking issues