Skip to content

Commit

Permalink
Add support for specifying multiple authors of a change by using mult…
Browse files Browse the repository at this point in the history
…iple `author: @someuser` lines (#564)

Co-authored-by: Mitchell Hamilton <mitchell@hamil.town>
  • Loading branch information
Andarist and emmatown committed Apr 8, 2021
1 parent 190c751 commit 707002d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/tender-cheetahs-begin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@changesets/changelog-github": minor
---

It's now possible to specify multiple authors of a change by using multiple `author: @someuser` lines.
18 changes: 17 additions & 1 deletion packages/changelog-github/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const getChangeset = (content: string, commit: string | undefined) => {
`---
pkg: "minor"
---
something
${content}
`
Expand Down Expand Up @@ -117,3 +117,19 @@ describe.each(["author", "user"])(
});
}
);

it("with multiple authors", async () => {
expect(
await getReleaseLine(
...getChangeset(
["author: @Andarist", "author: @mitchellhamilton"].join("\n"),
data.commit
)
)
).toMatchInlineSnapshot(`
"
- [#1613](https://github.com/emotion-js/emotion/pull/1613) [\`a085003\`](https://github.com/emotion-js/emotion/commit/a085003) Thanks [@Andarist](https://github.com/Andarist), [@mitchellhamilton](https://github.com/mitchellhamilton)! - something
"
`);
});
17 changes: 11 additions & 6 deletions packages/changelog-github/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const changelogFunctions: ChangelogFunctions = {

let prFromSummary: number | undefined;
let commitFromSummary: string | undefined;
let userFromSummary: string | undefined;
let usersFromSummary: string[] = [];

const replacedChangelog = changeset.summary
.replace(/^\s*(?:pr|pull|pull\s+request):\s*#?(\d+)/im, (_, pr) => {
Expand All @@ -61,8 +61,8 @@ const changelogFunctions: ChangelogFunctions = {
commitFromSummary = commit;
return "";
})
.replace(/^\s*(?:author|user):\s*@?([^\s]+)/im, (_, user) => {
userFromSummary = user;
.replace(/^\s*(?:author|user):\s*@?([^\s]+)/gim, (_, user) => {
usersFromSummary.push(user);
return "";
})
.trim();
Expand Down Expand Up @@ -100,14 +100,19 @@ const changelogFunctions: ChangelogFunctions = {
};
})();

const user = userFromSummary
? `[@${userFromSummary}](https://github.com/${userFromSummary})`
const users = usersFromSummary.length
? usersFromSummary
.map(
userFromSummary =>
`[@${userFromSummary}](https://github.com/${userFromSummary})`
)
.join(", ")
: links.user;

const prefix = [
links.pull === null ? "" : ` ${links.pull}`,
links.commit === null ? "" : ` ${links.commit}`,
user === null ? "" : ` Thanks ${user}!`
users === null ? "" : ` Thanks ${users}!`
].join("");

return `\n\n-${prefix ? `${prefix} -` : ""} ${firstLine}\n${futureLines
Expand Down

0 comments on commit 707002d

Please sign in to comment.