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/.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/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 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..ea6e349 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 @@ -91,12 +91,12 @@ function getUserLink(usersFromSummary: string[], user?: string): string | undefi .trim() : user; - return userLink ? `by ${userLink}` : undefined; + return userLink ? `(${userLink})` : ''; } // 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)})`; }); @@ -118,14 +118,13 @@ 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 userLinkMessage = userLink ?? ''; + const prMessage = pull ? `${pull}` : ''; + const commitMessage = commit ? `${commit}` : ''; // 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}`; }; 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', ); });