Skip to content

Commit 7b3f6a4

Browse files
committed
chore: xth time is the charm
1 parent 6375daa commit 7b3f6a4

File tree

4 files changed

+54
-109
lines changed

4 files changed

+54
-109
lines changed

.changeset/evil-suits-serve.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@stacc/changeset-formatter": major
3+
---
4+
5+
and a major!

.changeset/few-kids-start.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@stacc/changeset-formatter": minor
3+
---
4+
5+
lets get a minor in here

src/index.test.ts

Lines changed: 40 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,50 @@ vi.mock("@changesets/get-github-info", () => {
1818
pull: `[#${data.pull}](https://github.com/${data.repo}/pull/${data.pull})`,
1919
commit: `[\`${data.commit}\`](https://github.com/${data.repo}/commit/${data.commit})`,
2020
};
21-
return {
22-
getInfo: vi.fn(async ({ commit, repo }) => {
23-
expect(commit).toBe(data.commit);
24-
expect(repo).toBe(data.repo);
21+
22+
const getInfoFn = vi.fn(async ({ commit, repo }) => {
23+
expect(repo).toBe(data.repo);
24+
if (commit === data.commit) {
2525
return {
2626
pull: data.pull,
2727
user: data.user,
28-
links,
28+
links: {
29+
user: links.user,
30+
commit: links.commit,
31+
pull: links.pull,
32+
},
2933
};
30-
}),
31-
getInfoFromPullRequest: vi.fn(async ({ pull, repo }) => {
32-
expect(pull).toBe(data.pull);
33-
expect(repo).toBe(data.repo);
34+
}
35+
return {
36+
pull: data.pull,
37+
user: data.user,
38+
links: {
39+
user: links.user,
40+
commit: `[\`${commit}\`](https://github.com/${repo}/commit/${commit})`,
41+
pull: links.pull,
42+
},
43+
};
44+
});
45+
46+
const getInfoFromPullRequestFn = vi.fn(async ({ pull, repo }) => {
47+
expect(repo).toBe(data.repo);
48+
if (pull === data.pull) {
3449
return {
3550
commit: data.commit,
3651
user: data.user,
37-
links,
52+
links: {
53+
user: links.user,
54+
commit: links.commit,
55+
pull: links.pull,
56+
},
3857
};
39-
}),
58+
}
59+
throw new Error(`Unexpected pull request: ${pull}`);
60+
});
61+
62+
return {
63+
getInfo: getInfoFn,
64+
getInfoFromPullRequest: getInfoFromPullRequestFn,
4065
};
4166
});
4267

@@ -113,92 +138,30 @@ describe("Changeset formatter", () => {
113138
}
114139
);
115140

116-
describe.each(["author", "user"])(
117-
"override author with %s keyword",
118-
(keyword) => {
119-
it.each([
120-
["with @", `${keyword}: @other`],
121-
["without @", `${keyword}: other`],
122-
])("%s", async (name, content) => {
123-
const result = await getReleaseLine(
124-
...getChangeset(content, data.commit, true)
125-
);
126-
expect(result).toEqual(
127-
`- something ([#${data.pull}](https://github.com/${data.repo}/pull/${data.pull}))\n\n**Credits**\nHuge thanks to @other for helping!`
128-
);
129-
});
130-
}
131-
);
132-
133-
it("with multiple authors", async () => {
134-
const result = await getReleaseLine(
135-
...getChangeset(
136-
["author: @Gawdfrey", "author: @thymas1"].join("\n"),
137-
data.commit,
138-
true
139-
)
140-
);
141-
142-
expect(result).toEqual(
143-
`- something ([#${data.pull}](https://github.com/${data.repo}/pull/${data.pull}))\n\n**Credits**\nHuge thanks to @Gawdfrey and @thymas1 for helping!`
144-
);
145-
});
146-
147141
describe("multiple changes", () => {
148142
it("should only show credits after last change", async () => {
149143
// First change
150144
const firstResult = await getReleaseLine(
151-
...getChangeset("author: @Gawdfrey", data.commit, false, "first change")
145+
...getChangeset("", data.commit, false, "first change")
152146
);
153147
expect(firstResult).toEqual(
154148
`- first change ([#${data.pull}](https://github.com/${data.repo}/pull/${data.pull}))`
155149
);
156150

157151
// Second change
158152
const secondResult = await getReleaseLine(
159-
...getChangeset("author: @thymas1", data.commit, false, "second change")
153+
...getChangeset("", data.commit, false, "second change")
160154
);
161155
expect(secondResult).toEqual(
162156
`- second change ([#${data.pull}](https://github.com/${data.repo}/pull/${data.pull}))`
163157
);
164158

165159
// Last change
166160
const lastResult = await getReleaseLine(
167-
...getChangeset("author: @huozhi", data.commit, true, "third change")
168-
);
169-
expect(lastResult).toEqual(
170-
`- third change ([#${data.pull}](https://github.com/${data.repo}/pull/${data.pull}))\n\n**Credits**\nHuge thanks to @Gawdfrey, @huozhi, and @thymas1 for helping!`
171-
);
172-
});
173-
174-
it("should combine authors from all changes", async () => {
175-
// First change with GitHub author
176-
const firstResult = await getReleaseLine(
177-
...getChangeset("", data.commit, false, "first change")
178-
);
179-
expect(firstResult).toEqual(
180-
`- first change ([#${data.pull}](https://github.com/${data.repo}/pull/${data.pull}))`
181-
);
182-
183-
// Second change with explicit author
184-
const secondResult = await getReleaseLine(
185-
...getChangeset("author: @thymas1", data.commit, false, "second change")
186-
);
187-
expect(secondResult).toEqual(
188-
`- second change ([#${data.pull}](https://github.com/${data.repo}/pull/${data.pull}))`
189-
);
190-
191-
// Last change with multiple authors
192-
const lastResult = await getReleaseLine(
193-
...getChangeset(
194-
["author: @huozhi", "author: @ijjk"].join("\n"),
195-
data.commit,
196-
true,
197-
"third change"
198-
)
161+
...getChangeset("", data.commit, true, "third change")
199162
);
200163
expect(lastResult).toEqual(
201-
`- third change ([#${data.pull}](https://github.com/${data.repo}/pull/${data.pull}))\n\n**Credits**\nHuge thanks to @Gawdfrey, @huozhi, @ijjk, and @thymas1 for helping!`
164+
`- third change ([#${data.pull}](https://github.com/${data.repo}/pull/${data.pull}))\n\n**Credits**\nHuge thanks to @Gawdfrey for helping!`
202165
);
203166
});
204167
});

src/index.ts

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ async function getReleaseLine(
2929
// Extract PR, commit, and users from the summary
3030
let prFromSummary: number | undefined;
3131
let commitFromSummary: string | undefined;
32-
let usersFromSummary: string[] = [];
33-
let hasAuthorOverride = false;
3432

3533
// Process the changeset summary to extract metadata
3634
const replacedChangelog = changeset.summary
@@ -43,29 +41,6 @@ async function getReleaseLine(
4341
commitFromSummary = commit;
4442
return "";
4543
})
46-
.replace(
47-
/^\s*(?:author|user):\s*@?([^\s,]+)(?:\s*,\s*@?([^\s,]+))*/gim,
48-
(_, user, rest) => {
49-
hasAuthorOverride = true;
50-
if (user && !usersFromSummary.includes(user)) {
51-
usersFromSummary.push(user);
52-
allAuthors.add(user);
53-
}
54-
if (rest && !usersFromSummary.includes(rest)) {
55-
usersFromSummary.push(rest);
56-
allAuthors.add(rest);
57-
}
58-
return "";
59-
}
60-
)
61-
.replace(/^\s*(?:author|user):\s*@?([^\s,]+)/gim, (_, user) => {
62-
hasAuthorOverride = true;
63-
if (user && !usersFromSummary.includes(user)) {
64-
usersFromSummary.push(user);
65-
allAuthors.add(user);
66-
}
67-
return "";
68-
})
6944
.trim();
7045

7146
// Format the cleaned summary
@@ -81,7 +56,7 @@ async function getReleaseLine(
8156
repo,
8257
pull: prFromSummary,
8358
});
84-
if (user && !hasAuthorOverride) {
59+
if (user) {
8560
allAuthors.add(user);
8661
}
8762
return { links, user };
@@ -94,7 +69,7 @@ async function getReleaseLine(
9469
repo,
9570
commit: commitToFetchFrom,
9671
});
97-
if (info.user && !hasAuthorOverride) {
72+
if (info.user) {
9873
allAuthors.add(info.user);
9974
}
10075
return info;
@@ -116,16 +91,13 @@ async function getReleaseLine(
11691
? githubInfo.links.pull.match(/#(\d+)/)?.[1]
11792
: undefined);
11893

119-
// Get commit hash for the change
120-
const commitHash = commitFromSummary || changeset.commit;
121-
12294
// Build the release line in the requested format
12395
let result = `- ${firstLine}`;
12496

12597
if (prNumber) {
12698
result += ` ([#${prNumber}](https://github.com/${repo}/pull/${prNumber}))`;
127-
} else if (commitHash) {
128-
result += ` ([\`${commitHash}\`](https://github.com/${repo}/commit/${commitHash}))`;
99+
} else if (githubInfo.links?.commit) {
100+
result += ` (${githubInfo.links.commit})`;
129101
}
130102

131103
if (futureLines.length > 0) {

0 commit comments

Comments
 (0)