Repository: intuit/auto
Pull request #660 (2019-11-07 18:37:06)

Fix multiple first-time-contributor thank you
# What Changed

Use the `listContributors` endpoint to determine who has contributed to the repo.

# Why

Fix a bug where a contributor was thanked multiple times in the changelog.

Todo:

- [x] Add tests

<!-- GITHUB_RELEASE PR BODY: canary-version -->
Published PR with canary version: `7.12.7-canary.660.8528.0`
<!-- GITHUB_RELEASE PR BODY: canary-version -->



Patch:
diff --git a/plugins/first-time-contributor/src/index.ts b/plugins/first-time-contributor/src/index.ts
index 7b4dad03..eb5dcc3b 100644
--- a/plugins/first-time-contributor/src/index.ts
+++ b/plugins/first-time-contributor/src/index.ts
@@ -37,7 +37,15 @@ export default class FirstTimeContributorPlugin implements IPlugin {
 
           const contributors = await Promise.all([
             getContributors(JUST_NAME),
-            getContributors(JUST_EMAIL)
+            getContributors(JUST_EMAIL),
+            auto
+              .git!.github.repos.listContributors({
+                repo: auto.git!.options.repo,
+                owner: auto.git!.options.owner
+              })
+              .then(response =>
+                response.data.map(collaborator => collaborator.login).join('\n')
+              )
           ]).then(lists => lists.join('\n').split('\n'));
 
           const newContributors = authors.filter(


Test patch:
diff --git a/plugins/first-time-contributor/__tests__/__snapshots__/first-time-contributor.test.ts.snap b/plugins/first-time-contributor/__tests__/__snapshots__/first-time-contributor.test.ts.snap
index 774486bf..02f80f97 100644
--- a/plugins/first-time-contributor/__tests__/__snapshots__/first-time-contributor.test.ts.snap
+++ b/plugins/first-time-contributor/__tests__/__snapshots__/first-time-contributor.test.ts.snap
@@ -8,6 +8,14 @@ Thank you, Jeff, for all your work!",
 ]
 `;
 
+exports[`First Time Contributor Plugin should exclude a past contributor by username 1`] = `
+Array [
+  ":tada: This release contains work from a new contributor! :tada:
+
+Thank you, Jeff123, for all your work!",
+]
+`;
+
 exports[`First Time Contributor Plugin should include a username if it exists 1`] = `
 Array [
   ":tada: This release contains work from new contributors! :tada:
diff --git a/plugins/first-time-contributor/__tests__/first-time-contributor.test.ts b/plugins/first-time-contributor/__tests__/first-time-contributor.test.ts
index 5629cd3e..3ef9c913 100644
--- a/plugins/first-time-contributor/__tests__/first-time-contributor.test.ts
+++ b/plugins/first-time-contributor/__tests__/first-time-contributor.test.ts
@@ -7,18 +7,31 @@ import {
 } from '@auto-it/core/dist/utils/make-hooks';
 
 import FirstTimeContributor from '../src';
+import Octokit = require('@octokit/rest');
 
 const exec = jest.fn();
 exec.mockReturnValue('');
 // @ts-ignore
 jest.spyOn(Auto, 'execPromise').mockImplementation(exec);
 
-const setup = () => {
+const setup = (
+  contributors: Partial<Octokit.ReposListContributorsResponseItem>[] = []
+) => {
   const plugin = new FirstTimeContributor();
   const hooks = makeHooks();
   const changelogHooks = makeChangelogHooks();
 
-  plugin.apply({ hooks } as Auto.Auto);
+  plugin.apply({
+    hooks,
+    git: {
+      options: { repo: 'repo', owner: 'test' },
+      github: {
+        repos: {
+          listContributors: () => Promise.resolve({ data: contributors })
+        }
+      }
+    } as any
+  } as Auto.Auto);
   hooks.onCreateChangelog.call(
     {
       hooks: changelogHooks,
@@ -56,6 +69,16 @@ describe('First Time Contributor Plugin', () => {
     expect(await hooks.addToBody.promise([], commits)).toMatchSnapshot();
   });
 
+  test('should exclude a past contributor by username', async () => {
+    const hooks = setup([{ login: 'Andrew420' }]);
+    const commits = [
+      makeCommitFromMsg('foo', { name: 'Jeff123' }),
+      makeCommitFromMsg('foo', { name: 'Andrew420' })
+    ];
+
+    expect(await hooks.addToBody.promise([], commits)).toMatchSnapshot();
+  });
+
   test('should not include past contributors', async () => {
     const hooks = setup();
     const commits = [