Skip to content

Commit 5c6eb4d

Browse files
authored
feat!: reformat changelog output (#27)
Resolves #19 ## Changes - reformat changelog output - the new output looks like: "#PR (USER): MESSAGE" - remove explicit return statements on every typescript functions
1 parent 00adc68 commit 5c6eb4d

6 files changed

+28
-21
lines changed

.changeset/cuddly-carrots-train.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@mheob/changeset-changelog': major
3+
---
4+
5+
reformat the changelog output to displzy first the PR and user

.commitlintrc.cjs

+1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ module.exports = {
55
...defaultConfig,
66
prompt: {
77
...defaultConfig.prompt,
8+
allowEmptyScopes: true,
89
},
910
};

README.md

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
# `@mheob/changeset-changelog`
22

3-
[![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)
3+
[![Release](https://github.com/mheob/changeset-changelog/actions/workflows/release.yml/badge.svg)](https://github.com/mheob/changeset-changelog/actions/workflows/release.yml)
4+
[![Check](https://github.com/mheob/changeset-changelog/actions/workflows/check.yml/badge.svg)](https://github.com/mheob/changeset-changelog/actions/workflows/check.yml)
5+
[![codecov](https://codecov.io/gh/mheob/changeset-changelog/branch/main/graph/badge.svg?token=E7RZLWHMEX)](https://codecov.io/gh/mheob/changeset-changelog)
46

5-
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.
7+
Add my own style for the changelogs generated by the awesome [changesets](https://github.com/changesets/changesets) library. The
8+
style was inspired by the original
9+
[@changesets/changelog-github](https://github.com/changesets/changesets/tree/main/packages/changelog-github) and the
10+
[@svitejs/changesets-changelog-github-compact](https://github.com/svitejs/changesets-changelog-github-compact) packages.
611

712
## Installation
813

@@ -54,8 +59,8 @@ There are differences between this changelog output and the others:
5459

5560
<!-- markdownlint-enable MD024 -->
5661

57-
- Add nice feature to the project with a PR and commit --> ([#PR](#)) by [@user](#)
58-
- Add nice feature to the project without a PR --> ([commit](#)) by [@user](#)
62+
- [PR](#) ([@user](#)): Add nice feature to the project with a PR and commit
63+
- [commit](#) ([@user](#)): Add nice feature to the project without a PR
5964

6065
## Additional feature: linking issues
6166

src/getDependencyReleaseLine.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ import type { GetDependencyReleaseLine, NewChangesetWithCommit } from '@changese
33

44
import { errorMessage } from './utils';
55

6-
async function getDependencyReleaseLinks(
7-
changesets: NewChangesetWithCommit[],
8-
repository: string,
9-
): Promise<string> {
6+
async function getDependencyReleaseLinks(changesets: NewChangesetWithCommit[], repository: string) {
107
const changesetLinks = await Promise.all(
118
changesets.map(async (cs) => {
129
// istanbul ignore next: because of our mocked get-github-info -- @preserve

src/getReleaseLine.ts

+9-10
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ async function getGitHubLinks(
4444
commit?: string,
4545
commitFromSummary?: string,
4646
prFromSummary?: number,
47-
): Promise<GithubLinks> {
47+
) {
4848
let githubLinks: GithubLinks = { commit: undefined, pull: undefined, user: undefined };
4949

5050
if (prFromSummary) {
@@ -82,7 +82,7 @@ async function getGitHubLinks(
8282
return githubLinks;
8383
}
8484

85-
function getUserLink(usersFromSummary: string[], user?: string): string | undefined {
85+
function getUserLink(usersFromSummary: string[], user?: string) {
8686
const userLink =
8787
usersFromSummary.length > 0
8888
? usersFromSummary
@@ -91,12 +91,12 @@ function getUserLink(usersFromSummary: string[], user?: string): string | undefi
9191
.trim()
9292
: user;
9393

94-
return userLink ? `by ${userLink}` : undefined;
94+
return userLink ? `(${userLink})` : '';
9595
}
9696

9797
// add links to issue hints (fix #123) => (fix [#123](https://....))
9898
// thanks to https://github.com/svitejs/changesets-changelog-github-compact
99-
function linkifyIssue(line: string, repository: string): string {
99+
function linkifyIssue(line: string, repository: string) {
100100
return line.replace(/(?<=\( ?(?:fix|fixes|resolves|see) )(#\d+)(?= ?\))/g, (issue) => {
101101
return `[${issue}](https://github.com/${repository}/issues/${issue.slice(1)})`;
102102
});
@@ -118,14 +118,13 @@ export const getReleaseLine: GetReleaseLine = async (changeset, _type, options)
118118
.split('\n')
119119
.map((line) => linkifyIssue(line.trimEnd(), options['repo']));
120120

121-
const prMessage = pull ? `(${pull})` : '';
122-
const commitMessage = commit ? `(${commit})` : '';
123-
const userLinkMessage = userLink ?? '';
121+
const prMessage = pull ? `${pull}` : '';
122+
const commitMessage = commit ? `${commit}` : '';
124123
// istanbul ignore next: because of our mocked get-github-info -- @preserve
125-
const printPrOrCommit = pull !== '' ? prMessage : commitMessage;
126-
const suffix = printPrOrCommit.trim() ? ` --> ${printPrOrCommit.trim()} ${userLinkMessage}` : '';
124+
const printPrOrCommit = (pull !== '' ? prMessage : commitMessage).trim();
125+
const prefix = printPrOrCommit ? `${printPrOrCommit} ${userLink}: ` : '';
127126

128127
const futureLinesMessage = futureLines.map((line) => ` ${line}`).join('\n');
129128

130-
return `\n\n- ${firstLine}${suffix}\n${futureLinesMessage}`;
129+
return `\n\n- ${prefix}${firstLine}\n${futureLinesMessage}`;
131130
};

src/index.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -112,23 +112,23 @@ describe('getReplacedChangelog', () => {
112112
);
113113
const result = await getReleaseLine(changeset, 'minor', { repo: data.repo });
114114
expect(result).toBe(
115-
'\n\n- An awesome feature. --> ([#2](https://github.com/mheob/changeset-changelog/pull/2)) by [@mheob](https://github.com/mheob)\n',
115+
'\n\n- [#2](https://github.com/mheob/changeset-changelog/pull/2) ([@mheob](https://github.com/mheob)): An awesome feature.\n',
116116
);
117117
});
118118

119119
it('should return the changelog in a string format with data from commit', async () => {
120120
const changeset = getChangeset('An awesome feature.', data.commit);
121121
const result = await getReleaseLine(changeset, 'minor', { repo: data.repo });
122122
expect(result).toBe(
123-
'\n\n- An awesome feature. --> ([#2](https://github.com/mheob/changeset-changelog/pull/2)) by [@mheob](https://github.com/mheob)\n',
123+
'\n\n- [#2](https://github.com/mheob/changeset-changelog/pull/2) ([@mheob](https://github.com/mheob)): An awesome feature.\n',
124124
);
125125
});
126126

127127
it('should return the changelog in a string format with data from commit', async () => {
128128
const changeset = getChangeset('An awesome feature, (resolves #9)', data.commit);
129129
const result = await getReleaseLine(changeset, 'minor', { repo: data.repo });
130130
expect(result).toBe(
131-
'\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',
131+
'\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',
132132
);
133133
});
134134

0 commit comments

Comments
 (0)