Repository: intuit/auto
Pull request #661 (2019-11-07 18:51:18)

Fix wrong author in changelog
# What Changed

check for falsy values before matching an author.

# Why

If two users didn't have a attr set (ex: name) the `null` names would match, attributing the commit to the wrong person.

Todo:

- [x] Add tests

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



Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a0af46c9..577a77a0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,34 +1,3 @@
-# v7.12.7 (Thu Nov 07 2019)
-
-#### 🐛  Bug Fix
-
-- `@auto-it/released`
-  - Fix creating old changelogs [#659](https://github.com/intuit/auto/pull/659) ([@hipstersmoothie](https://github.com/hipstersmoothie))
-
-#### 🔩 Dependency Updates
-
-- Bump @types/node from 12.11.1 to 12.12.5 [#643](https://github.com/intuit/auto/pull/643) ([@dependabot-preview[bot]](https://github.com/dependabot-preview[bot]))
-- Bump twitter-text from 3.0.0 to 3.0.1 [#651](https://github.com/intuit/auto/pull/651) ([@dependabot-preview[bot]](https://github.com/dependabot-preview[bot]))
-- Bump eslint from 6.5.1 to 6.6.0 [#649](https://github.com/intuit/auto/pull/649) ([@dependabot-preview[bot]](https://github.com/dependabot-preview[bot]))
-- Bump eslint-config-prettier from 6.4.0 to 6.5.0 [#652](https://github.com/intuit/auto/pull/652) ([@dependabot-preview[bot]](https://github.com/dependabot-preview[bot]))
-- Bump @types/jest from 24.0.19 to 24.0.21 [#647](https://github.com/intuit/auto/pull/647) ([@dependabot-preview[bot]](https://github.com/dependabot-preview[bot]))
-- Bump deepmerge from 4.1.1 to 4.2.2 [#646](https://github.com/intuit/auto/pull/646) ([@dependabot-preview[bot]](https://github.com/dependabot-preview[bot]))
-- Bump @typescript-eslint/eslint-plugin from 2.5.0 to 2.6.0 [#645](https://github.com/intuit/auto/pull/645) ([@dependabot-preview[bot]](https://github.com/dependabot-preview[bot]))
-- Bump env-ci from 4.5.0 to 4.5.1 [#644](https://github.com/intuit/auto/pull/644) ([@dependabot-preview[bot]](https://github.com/dependabot-preview[bot]))
-- `@auto-it/core`
-  - Bump cosmiconfig from 5.2.1 to 6.0.0 [#650](https://github.com/intuit/auto/pull/650) ([@dependabot-preview[bot]](https://github.com/dependabot-preview[bot]) [@hipstersmoothie](https://github.com/hipstersmoothie))
-- `@auto-it/core`
-  - Bump @octokit/rest from 16.34.0 to 16.34.1 [#653](https://github.com/intuit/auto/pull/653) ([@dependabot-preview[bot]](https://github.com/dependabot-preview[bot]))
-- `@auto-it/core`
-  - Bump @types/dotenv from 6.1.1 to 8.2.0 [#648](https://github.com/intuit/auto/pull/648) ([@dependabot-preview[bot]](https://github.com/dependabot-preview[bot]))
-
-#### Authors: 2
-
-- [@dependabot-preview[bot]](https://github.com/dependabot-preview[bot])
-- Andrew Lisowski ([@hipstersmoothie](https://github.com/hipstersmoothie))
-
----
-
 # v7.12.5 (Tue Nov 05 2019)
 
 #### 🐛  Bug Fix
diff --git a/lerna.json b/lerna.json
index 134f0d78..485ca30e 100644
--- a/lerna.json
+++ b/lerna.json
@@ -1,5 +1,5 @@
 {
-  "version": "7.12.7",
+  "version": "7.12.6",
   "npmClient": "yarn",
   "useWorkspaces": true,
   "packages": [
diff --git a/packages/cli/package.json b/packages/cli/package.json
index 2fe72aa0..329526e4 100644
--- a/packages/cli/package.json
+++ b/packages/cli/package.json
@@ -2,7 +2,7 @@
   "name": "auto",
   "bin": "dist/bin/auto.js",
   "description": "CLI tools to help facilitate semantic versioning based on GitHub PR labels",
-  "version": "7.12.7",
+  "version": "7.12.6",
   "author": {
     "name": "Andrew Lisowski",
     "email": "lisowski54@gmail.com"
diff --git a/packages/core/package.json b/packages/core/package.json
index e477025a..9a6453c1 100644
--- a/packages/core/package.json
+++ b/packages/core/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@auto-it/core",
-  "version": "7.12.7",
+  "version": "7.12.6",
   "description": "Node API for using auto.",
   "main": "dist/auto.js",
   "author": {
diff --git a/packages/core/src/changelog.ts b/packages/core/src/changelog.ts
index d2082736..d58f924b 100644
--- a/packages/core/src/changelog.ts
+++ b/packages/core/src/changelog.ts
@@ -207,8 +207,15 @@ export default class Changelog {
       commit.authors.map(async rawAuthor => {
         const data = (this.authors!.find(
           ([, commitAuthor]) =>
-            commitAuthor.name === rawAuthor.name ||
-            commitAuthor.email === rawAuthor.email
+            (commitAuthor.name &&
+              rawAuthor.name &&
+              commitAuthor.name === rawAuthor.name) ||
+            (commitAuthor.email &&
+              rawAuthor.email &&
+              commitAuthor.email === rawAuthor.email) ||
+            (commitAuthor.username &&
+              rawAuthor.username &&
+              commitAuthor.username === rawAuthor.username)
         ) as [IExtendedCommit, ICommitAuthor]) || [{}, rawAuthor];
 
         const link = await this.hooks.renderChangelogAuthor.promise(
@@ -216,6 +223,7 @@ export default class Changelog {
           commit,
           this.options
         );
+
         if (link) {
           result.add(link);
         }
diff --git a/plugins/all-contributors/package.json b/plugins/all-contributors/package.json
index 6bb51999..5337d5ef 100644
--- a/plugins/all-contributors/package.json
+++ b/plugins/all-contributors/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@auto-it/all-contributors",
-  "version": "7.12.7",
+  "version": "7.12.6",
   "main": "dist/index.js",
   "description": "Automatically add contributors as changelogs are produced.",
   "author": {
diff --git a/plugins/chrome/package.json b/plugins/chrome/package.json
index 25ad7485..83f4698c 100644
--- a/plugins/chrome/package.json
+++ b/plugins/chrome/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@auto-it/chrome",
-  "version": "7.12.7",
+  "version": "7.12.6",
   "main": "dist/index.js",
   "description": "Chrome publishing plugin for auto",
   "author": {
diff --git a/plugins/conventional-commits/package.json b/plugins/conventional-commits/package.json
index 03ddb03b..a39d7d24 100644
--- a/plugins/conventional-commits/package.json
+++ b/plugins/conventional-commits/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@auto-it/conventional-commits",
-  "version": "7.12.7",
+  "version": "7.12.6",
   "main": "dist/index.js",
   "description": "Conventional commit plugin for auto",
   "author": {
diff --git a/plugins/crates/package.json b/plugins/crates/package.json
index 3b0027e5..f951c535 100644
--- a/plugins/crates/package.json
+++ b/plugins/crates/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@auto-it/crates",
-  "version": "7.12.7",
+  "version": "7.12.6",
   "main": "dist/index.js",
   "description": "Deploy Rust crates to crates.io",
   "author": {
diff --git a/plugins/first-time-contributor/package.json b/plugins/first-time-contributor/package.json
index 4ecdf77f..7932dd4f 100644
--- a/plugins/first-time-contributor/package.json
+++ b/plugins/first-time-contributor/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@auto-it/first-time-contributor",
-  "version": "7.12.7",
+  "version": "7.12.6",
   "main": "dist/index.js",
   "description": "Thank first time contributors for their work right in your release notes.",
   "author": {
diff --git a/plugins/first-time-contributor/src/index.ts b/plugins/first-time-contributor/src/index.ts
index eb5dcc3b..7b4dad03 100644
--- a/plugins/first-time-contributor/src/index.ts
+++ b/plugins/first-time-contributor/src/index.ts
@@ -37,15 +37,7 @@ export default class FirstTimeContributorPlugin implements IPlugin {
 
           const contributors = await Promise.all([
             getContributors(JUST_NAME),
-            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')
-              )
+            getContributors(JUST_EMAIL)
           ]).then(lists => lists.join('\n').split('\n'));
 
           const newContributors = authors.filter(
diff --git a/plugins/git-tag/package.json b/plugins/git-tag/package.json
index 27549bf0..d117561d 100644
--- a/plugins/git-tag/package.json
+++ b/plugins/git-tag/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@auto-it/git-tag",
-  "version": "7.12.7",
+  "version": "7.12.6",
   "main": "dist/index.js",
   "description": "Manage your projects version through just a git tag",
   "author": {
diff --git a/plugins/jira/package.json b/plugins/jira/package.json
index dd35bba3..9d3b82c2 100644
--- a/plugins/jira/package.json
+++ b/plugins/jira/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@auto-it/jira",
-  "version": "7.12.7",
+  "version": "7.12.6",
   "main": "dist/index.js",
   "description": "Jira plugin for auto",
   "author": {
diff --git a/plugins/maven/package.json b/plugins/maven/package.json
index fb8f5284..3bc12238 100644
--- a/plugins/maven/package.json
+++ b/plugins/maven/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@auto-it/maven",
-  "version": "7.12.7",
+  "version": "7.12.6",
   "main": "dist/index.js",
   "description": "Maven publishing plugin for auto",
   "author": {
diff --git a/plugins/npm/package.json b/plugins/npm/package.json
index 7aee8ee3..17e6310b 100644
--- a/plugins/npm/package.json
+++ b/plugins/npm/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@auto-it/npm",
-  "version": "7.12.7",
+  "version": "7.12.6",
   "main": "dist/index.js",
   "description": "NPM publishing plugin for auto",
   "author": {
diff --git a/plugins/omit-commits/package.json b/plugins/omit-commits/package.json
index 19bbf004..6bf611a5 100644
--- a/plugins/omit-commits/package.json
+++ b/plugins/omit-commits/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@auto-it/omit-commits",
-  "version": "7.12.7",
+  "version": "7.12.6",
   "main": "dist/index.js",
   "description": "Omit commits plugin for auto",
   "author": {
diff --git a/plugins/omit-release-notes/package.json b/plugins/omit-release-notes/package.json
index 2e0fd379..75830e47 100644
--- a/plugins/omit-release-notes/package.json
+++ b/plugins/omit-release-notes/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@auto-it/omit-release-notes",
-  "version": "7.12.7",
+  "version": "7.12.6",
   "main": "dist/index.js",
   "description": "Omit release notes plugin for auto",
   "author": {
diff --git a/plugins/released/package.json b/plugins/released/package.json
index e855231f..a04a37b0 100644
--- a/plugins/released/package.json
+++ b/plugins/released/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@auto-it/released",
-  "version": "7.12.7",
+  "version": "7.12.6",
   "main": "dist/index.js",
   "description": "Released plugin for auto. Comments with version + extra",
   "author": {
diff --git a/plugins/released/src/index.ts b/plugins/released/src/index.ts
index 10f42453..20ed228c 100644
--- a/plugins/released/src/index.ts
+++ b/plugins/released/src/index.ts
@@ -38,6 +38,14 @@ export default class ReleasedLabelPlugin implements IPlugin {
       return config;
     });
 
+    auto.hooks.onCreateLogParse.tap(this.name, logParse => {
+      logParse.hooks.omitCommit.tapPromise(this.name, async commit => {
+        if (commit.labels.includes(this.options.label)) {
+          return true;
+        }
+      });
+    });
+
     auto.hooks.afterRelease.tapPromise(
       this.name,
       async ({ newVersion, commits }) => {
diff --git a/plugins/s3/package.json b/plugins/s3/package.json
index e80b623e..4a27058f 100644
--- a/plugins/s3/package.json
+++ b/plugins/s3/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@auto-it/s3",
-  "version": "7.12.7",
+  "version": "7.12.6",
   "main": "dist/index.js",
   "description": "Post your built artifacts to s3",
   "author": {
diff --git a/plugins/slack/package.json b/plugins/slack/package.json
index 0d02d864..79c92fe9 100644
--- a/plugins/slack/package.json
+++ b/plugins/slack/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@auto-it/slack",
-  "version": "7.12.7",
+  "version": "7.12.6",
   "main": "dist/index.js",
   "description": "Slack plugin for auto",
   "author": {
diff --git a/plugins/twitter/package.json b/plugins/twitter/package.json
index f562d88f..984f7e89 100644
--- a/plugins/twitter/package.json
+++ b/plugins/twitter/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@auto-it/twitter",
-  "version": "7.12.7",
+  "version": "7.12.6",
   "main": "dist/index.js",
   "description": "Twitter plugin for auto",
   "author": {
diff --git a/plugins/upload-assets/package.json b/plugins/upload-assets/package.json
index 3180f471..40400699 100644
--- a/plugins/upload-assets/package.json
+++ b/plugins/upload-assets/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@auto-it/upload-assets",
-  "version": "7.12.7",
+  "version": "7.12.6",
   "main": "dist/index.js",
   "description": "Upload assets plugin for auto",
   "author": {


Test patch:
diff --git a/packages/core/src/__tests__/__snapshots__/changelog.test.ts.snap b/packages/core/src/__tests__/__snapshots__/changelog.test.ts.snap
index eac64647..914fa2dc 100644
--- a/packages/core/src/__tests__/__snapshots__/changelog.test.ts.snap
+++ b/packages/core/src/__tests__/__snapshots__/changelog.test.ts.snap
@@ -189,6 +189,23 @@ exports[`generateReleaseNotes should include prs with released label 1`] = `
 - Adam Dierkens (adam@dierkens.com)"
 `;
 
+exports[`generateReleaseNotes should match authors correctly 1`] = `
+"#### 🏠  Internal
+
+- something  (andrew@email.com)
+
+#### 📝  Documentation
+
+- docs  (kendall@email.com)
+- another  ([@rdubzz](https://github.custom.com/rdubzz))
+
+#### Authors: 3
+
+- [@rdubzz](https://github.custom.com/rdubzz)
+- kendall@email.com
+- andrew@email.com"
+`;
+
 exports[`generateReleaseNotes should merge sections with same changelog title 1`] = `
 "#### Enhancement
 
@@ -236,7 +253,7 @@ exports[`generateReleaseNotes should use only email if author name doesn't exist
 "#### 🐛  Bug Fix
 
 - Another Feature [#1234](https://github.custom.com/foobar/auto/pull/1234) (adam@dierkens.com)
-- One Feature [#1235](https://github.custom.com/foobar/auto/pull/1235) (adam@dierkens.com)
+- One Feature [#1235](https://github.custom.com/foobar/auto/pull/1235)
 
 #### Authors: 1
 
diff --git a/packages/core/src/__tests__/changelog.test.ts b/packages/core/src/__tests__/changelog.test.ts
index 7641b01d..201eec63 100644
--- a/packages/core/src/__tests__/changelog.test.ts
+++ b/packages/core/src/__tests__/changelog.test.ts
@@ -342,6 +342,50 @@ describe('generateReleaseNotes', () => {
     expect(await changelog.generateReleaseNotes(commits)).toMatchSnapshot();
   });
 
+  test('should match authors correctly', async () => {
+    const options = testOptions();
+    const changelog = new Changelog(dummyLog(), options);
+    changelog.loadDefaultHooks();
+
+    const commits = await logParse.normalizeCommits([
+      {
+        hash: '0a',
+        files: [],
+        subject: 'something\n\n',
+        labels: ['internal']
+      },
+      {
+        hash: '0',
+        files: [],
+        subject: 'docs\n\n',
+        labels: ['documentation']
+      },
+      {
+        hash: '0',
+        files: [],
+        subject: 'another\n\n',
+        labels: ['documentation']
+      }
+    ]);
+
+    commits.forEach((commit, index) => {
+      switch (index) {
+        case 0:
+          commit.authors = [{ email: 'andrew@email.com' }];
+          break;
+        case 1:
+          commit.authors = [{ email: 'kendall@email.com' }];
+          break;
+        case 2:
+          commit.authors = [{ username: 'rdubzz' }];
+          break;
+        default:
+      }
+    });
+
+    expect(await changelog.generateReleaseNotes(commits)).toMatchSnapshot();
+  });
+
   test('should be able to customize pushToBaseBranch title', async () => {
     const options = testOptions();
     options.labels = {
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 02f80f97..774486bf 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,14 +8,6 @@ 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 3ef9c913..5629cd3e 100644
--- a/plugins/first-time-contributor/__tests__/first-time-contributor.test.ts
+++ b/plugins/first-time-contributor/__tests__/first-time-contributor.test.ts
@@ -7,31 +7,18 @@ 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 = (
-  contributors: Partial<Octokit.ReposListContributorsResponseItem>[] = []
-) => {
+const setup = () => {
   const plugin = new FirstTimeContributor();
   const hooks = makeHooks();
   const changelogHooks = makeChangelogHooks();
 
-  plugin.apply({
-    hooks,
-    git: {
-      options: { repo: 'repo', owner: 'test' },
-      github: {
-        repos: {
-          listContributors: () => Promise.resolve({ data: contributors })
-        }
-      }
-    } as any
-  } as Auto.Auto);
+  plugin.apply({ hooks } as Auto.Auto);
   hooks.onCreateChangelog.call(
     {
       hooks: changelogHooks,
@@ -69,16 +56,6 @@ 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 = [
diff --git a/plugins/released/__tests__/released-label.test.ts b/plugins/released/__tests__/released-label.test.ts
index 31c34fdc..b406c24e 100644
--- a/plugins/released/__tests__/released-label.test.ts
+++ b/plugins/released/__tests__/released-label.test.ts
@@ -59,7 +59,7 @@ describe('release label plugin', () => {
     });
   });
 
-  test('should not omit released PRs', async () => {
+  test('should omit released PRs', async () => {
     const releasedLabel = new ReleasedLabelPlugin();
     const autoHooks = makeHooks();
     const logParseHooks = makeLogParseHooks();
@@ -75,12 +75,12 @@ describe('release label plugin', () => {
     autoHooks.onCreateLogParse.call({ hooks: logParseHooks } as LogParse);
 
     const included = makeCommitFromMsg('normal commit with no bump');
-    expect(await logParseHooks.omitCommit.promise(included)).not.toBe(true);
+    expect(await logParseHooks.omitCommit.promise(included)).toBeUndefined();
 
     const omitted = makeCommitFromMsg('normal commit with no bump', {
       labels: ['released']
     });
-    expect(await logParseHooks.omitCommit.promise(omitted)).not.toBe(true);
+    expect(await logParseHooks.omitCommit.promise(omitted)).toBe(true);
   });
 
   test('should do nothing without PRs', async () => {