Skip to content

Commit fc00a48

Browse files
authored
Merge pull request #449 from gfscott/changeset-compact
Replace deprecated changelog formatter dependency with minimal local utility
2 parents 4a7fcf0 + ed78e83 commit fc00a48

4 files changed

Lines changed: 54 additions & 69 deletions

File tree

.changeset/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "https://unpkg.com/@changesets/config@2.3.0/schema.json",
3-
"changelog": ["@svitejs/changesets-changelog-github-compact", { "repo": "gfscott/eleventy-plugin-embed-everything" }],
3+
"changelog": ["../utils/changelog/format.cjs", { "repo": "gfscott/eleventy-plugin-embed-everything" }],
44
"commit": false,
55
"fixed": [],
66
"linked": [],

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
},
2525
"bugs": "https://github.com/gfscott/eleventy-plugin-embed-everything/issues",
2626
"devDependencies": {
27-
"@svitejs/changesets-changelog-github-compact": "^1.2.0",
2827
"msw": "^2.15.0",
2928
"permute-arrays": "workspace:^"
3029
},

pnpm-lock.yaml

Lines changed: 0 additions & 67 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

utils/changelog/format.cjs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Minimal replacement for @svitejs/changesets-changelog-github-compact (deprecated).
2+
// Formats changelog lines as "- summary (#pr)" / "- summary (commit-link)".
3+
4+
function repoOf(options) {
5+
if (!options || !options.repo) {
6+
throw new Error(
7+
'Please provide a repo to this changelog generator like this:\n"changelog": ["./utils/changesets-changelog.cjs", { "repo": "org/repo" }]'
8+
);
9+
}
10+
return options.repo;
11+
}
12+
13+
// ponytail: unauthenticated GitHub API calls are rate-limited to 60/hr; set GITHUB_TOKEN
14+
// in CI if changesets ever needs more commits' worth of PR lookups per release.
15+
async function commitPullLink(repo, commit) {
16+
const res = await fetch(`https://api.github.com/repos/${repo}/commits/${commit}/pulls`, {
17+
headers: {
18+
Accept: "application/vnd.github+json",
19+
...(process.env.GITHUB_TOKEN ? { Authorization: `Bearer ${process.env.GITHUB_TOKEN}` } : {})
20+
}
21+
});
22+
if (!res.ok) return null;
23+
const [pr] = await res.json();
24+
return pr ? `[#${pr.number}](${pr.html_url})` : null;
25+
}
26+
27+
async function getReleaseLine(changeset, _type, options) {
28+
const repo = repoOf(options);
29+
const summary = changeset.summary.trim();
30+
31+
const pullLink = changeset.commit ? await commitPullLink(repo, changeset.commit) : null;
32+
const commitLink = changeset.commit
33+
? `[\`${changeset.commit.slice(0, 7)}\`](https://github.com/${repo}/commit/${changeset.commit})`
34+
: null;
35+
const suffix = pullLink ? ` (${pullLink})` : commitLink ? ` (${commitLink})` : "";
36+
37+
return `\n- ${summary}${suffix}`;
38+
}
39+
40+
async function getDependencyReleaseLine(changesets, dependenciesUpdated, options) {
41+
const repo = repoOf(options);
42+
if (dependenciesUpdated.length === 0) return "";
43+
44+
const commitLinks = changesets
45+
.filter((cs) => cs.commit)
46+
.map((cs) => `[\`${cs.commit.slice(0, 7)}\`](https://github.com/${repo}/commit/${cs.commit})`);
47+
48+
const heading = `- Updated dependencies [${commitLinks.join(", ")}]:`;
49+
const deps = dependenciesUpdated.map((dep) => ` - ${dep.name}@${dep.newVersion}`);
50+
return [heading, ...deps].join("\n");
51+
}
52+
53+
module.exports = { getReleaseLine, getDependencyReleaseLine };

0 commit comments

Comments
 (0)