Skip to content

Commit 1d07eab

Browse files
authored
chore: improve changelog (fixes #93) (#94)
1 parent e0a41b3 commit 1d07eab

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

.changeset/happy-mails-kneel.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/vite-plugin-svelte': patch
3+
---
4+
5+
further improvements to changelog (see #93)

scripts/changelog-github-custom.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// modifications to improve readability:
33
// - removed thanks notes. We're thanking contributors in the PRs or acknowledge their work in different ways
44
// - moved issue links to end of first line
5+
// - omit link to merge commit if PR link is found
6+
// - linkify issue hints like (see #123) or (fixes #567)
57

68
const { config } = require('dotenv');
79
const { getInfo, getInfoFromPullRequest } = require('@changesets/get-github-info');
@@ -66,7 +68,14 @@ const changelogFunctions = {
6668
})
6769
.trim();
6870

69-
const [firstLine, ...futureLines] = replacedChangelog.split('\n').map((l) => l.trimRight());
71+
// add links to issue hints (fix #123) => (fix [#123](https://....))
72+
const linkifyIssueHints = (line) =>
73+
line.replace(/(?<=\( ?(?:fix|fixes|see) )(#\d+)(?= ?\))/g, (issueHash) => {
74+
return `[${issueHash}](https://github.com/${options.repo}/issue/${issueHash.substring(1)})`;
75+
});
76+
const [firstLine, ...futureLines] = replacedChangelog
77+
.split('\n')
78+
.map((l) => linkifyIssueHints(l.trimRight()));
7079

7180
const links = await (async () => {
7281
if (prFromSummary !== undefined) {
@@ -97,10 +106,8 @@ const changelogFunctions = {
97106
};
98107
})();
99108

100-
const suffix = [
101-
links.pull === null ? '' : ` (${links.pull})`,
102-
links.commit === null ? '' : ` (${links.commit})`
103-
].join('');
109+
// only link PR or merge commit not both
110+
const suffix = links.pull ? ` (${links.pull})` : links.commit ? ` (${links.commit})` : '';
104111

105112
return `\n\n- ${firstLine}${suffix}\n${futureLines.map((l) => ` ${l}`).join('\n')}`;
106113
}

0 commit comments

Comments
 (0)