Repository: atlassian/changesets
Pull request #564 (2021-04-08 07:32:56)

Add support for specifying multiple authors of a change by using multiple `author: @someuser` lines

changeset-bot[bot]: ###  🦋  Changeset detected

Latest commit: 5d96a01dfe5d0d70c1054ecefe2951c5c02cc85d

**The changes in this PR will be included in the next version bump.**

<details><summary>This PR includes changesets to release 1 package</summary>

  | Name                         | Type  |
| ---------------------------- | ----- |
| @changesets/changelog-github | Minor |

</details>

Not sure what this means? [Click here  to learn what changesets are](https://github.com/changesets/changesets/blob/master/docs/adding-a-changeset.md).

[Click here if you're a maintainer who wants to add another changeset to this PR](https://github.com/atlassian/changesets/new/multiple-authors-of-a-change?filename=.changeset/lemon-ravens-confess.md&value=---%0A%22%40changesets%2Fchangelog-git%22%3A%20patch%0A%22%40changesets%2Fchangelog-github%22%3A%20patch%0A---%0A%0AAdd%20support%20for%20specifying%20multiple%20authors%20of%20a%20change%20by%20using%20multiple%20%60author%3A%20%40someuser%60%20lines%0A)



Patch:
diff --git a/.changeset/tender-cheetahs-begin.md b/.changeset/tender-cheetahs-begin.md
new file mode 100644
index 0000000..e8b866a
--- /dev/null
+++ b/.changeset/tender-cheetahs-begin.md
@@ -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.
diff --git a/packages/changelog-github/src/index.ts b/packages/changelog-github/src/index.ts
index 806c990..c973c69 100644
--- a/packages/changelog-github/src/index.ts
+++ b/packages/changelog-github/src/index.ts
@@ -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) => {
@@ -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();
@@ -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


Test patch:
diff --git a/packages/changelog-github/src/index.test.ts b/packages/changelog-github/src/index.test.ts
index f934b0f..fe5b3a4 100644
--- a/packages/changelog-github/src/index.test.ts
+++ b/packages/changelog-github/src/index.test.ts
@@ -48,7 +48,7 @@ const getChangeset = (content: string, commit: string | undefined) => {
         `---
   pkg: "minor"
   ---
-  
+
   something
   ${content}
   `
@@ -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
+    "
+  `);
+});