From 5e5cad2f50b5c0860b7c644a0f71290fe30c302b Mon Sep 17 00:00:00 2001 From: Andrew Lisowski Date: Sat, 4 Apr 2020 11:22:21 -0700 Subject: [PATCH] include first commit in changelogs --- .../__tests__/__snapshots__/git.test.ts.snap | 84 +++++++++++++++---- packages/core/src/__tests__/git.test.ts | 2 +- packages/core/src/git.ts | 13 ++- 3 files changed, 82 insertions(+), 17 deletions(-) diff --git a/packages/core/src/__tests__/__snapshots__/git.test.ts.snap b/packages/core/src/__tests__/__snapshots__/git.test.ts.snap index e3026fd8a..3a1d49e36 100644 --- a/packages/core/src/__tests__/__snapshots__/git.test.ts.snap +++ b/packages/core/src/__tests__/__snapshots__/git.test.ts.snap @@ -1,20 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`github getGitLog 1`] = ` -Array [ - Object { - "authorEmail": "lisowski54@gmail.com", - "authorName": "Andrew Lisowski", - "files": Array [ - "/src/__tests__/git.test.ts", - ], - "hash": "a7f6634429731055a5a44bae24ac88c5f9822e58", - "subject": "update tests -", - }, -] -`; - exports[`github getGitLog - merge commits 1`] = ` Object { "authorEmail": "lisowski54@gmail.com", @@ -32,3 +17,72 @@ Object { determine if branch behind remote and exit before trying to publish", } `; + +exports[`github getGitLog 1`] = ` +Array [ + Object { + "authorEmail": "lisowski54@gmail.com", + "authorName": "Andrew Lisowski", + "files": Array [ + "/src/__tests__/git.test.ts", + ], + "hash": "a7f6634429731055a5a44bae24ac88c5f9822e58", + "subject": "update tests +", + }, + Object { + "authorEmail": "lisowski54@gmail.com", + "authorName": "Andrew Lisowski", + "files": Array [ + "/.circleci/config.yml", + "/.gitignore", + "/.vscode/settings.json", + "/CHANGELOG.md", + "/LICENSE", + "/README.md", + "/package.json", + "/scripts/post-install.sh", + "/scripts/release.sh", + "/src/__tests__/__snapshots__/git.test.ts.snap", + "/src/__tests__/__snapshots__/log-parse.test.ts.snap", + "/src/__tests__/__snapshots__/main.test.ts.snap", + "/src/__tests__/git-changed-packages.test.ts", + "/src/__tests__/git.test.ts", + "/src/__tests__/github-responses/bad-credentials.json", + "/src/__tests__/github-responses/pr-labels.json", + "/src/__tests__/log-parse.test.ts", + "/src/__tests__/main.test.ts", + "/src/__tests__/make-commit-from-msg.ts", + "/src/__tests__/semver.test.ts", + "/src/auto-rc.json", + "/src/bin/__tests__/bin.test.ts", + "/src/bin/auto.ts", + "/src/cli/__tests__/args.test.ts", + "/src/cli/args.ts", + "/src/git.ts", + "/src/log-parse.ts", + "/src/main.ts", + "/src/semver.ts", + "/src/types/parse-git.d.ts", + "/src/types/registry-url.d.ts", + "/src/utils/__tests__/__snapshots__/slack.test.ts.snap", + "/src/utils/__tests__/exec-promise.test.ts", + "/src/utils/__tests__/github-token.test.ts", + "/src/utils/__tests__/package-config.test.ts", + "/src/utils/__tests__/slack.test.ts", + "/src/utils/exec-promise.ts", + "/src/utils/github-token.ts", + "/src/utils/logger.ts", + "/src/utils/package-config.ts", + "/src/utils/slack.ts", + "/tsconfig.build.json", + "/tsconfig.json", + "/tslint.json", + "/yarn.lock", + ], + "hash": "0b2af75d8b55c8869cda93d0e5589ad9f2677e18", + "subject": "init +", + }, +] +`; diff --git a/packages/core/src/__tests__/git.test.ts b/packages/core/src/__tests__/git.test.ts index 24547941c..c6e22d5f3 100644 --- a/packages/core/src/__tests__/git.test.ts +++ b/packages/core/src/__tests__/git.test.ts @@ -210,7 +210,7 @@ describe("github", () => { expect(await gh.getLastTagNotInBaseBranch("alpha")).toBe("0.4.0-alpha.1"); }); - test("getGitLog ", async () => { + test("getGitLog", async () => { const gh = new Git(options); expect( diff --git a/packages/core/src/git.ts b/packages/core/src/git.ts index f18a4a016..0d04c85c3 100644 --- a/packages/core/src/git.ts +++ b/packages/core/src/git.ts @@ -318,11 +318,21 @@ export default class Git { @memoize() async getGitLog(start: string, end = "HEAD"): Promise { try { + const first = await this.getFirstCommit(); + // This "shaExists" is just so we don't have to refactor all the tests + // in auto.test.ts. If the SHA doesn't really exist then the call to + // gitlog will fail too. + const startSha = (await this.shaExists(start)) + ? await execPromise("git", ["rev-parse", start]) + : ""; + const log = await gitlog({ repo: process.cwd(), number: Number.MAX_SAFE_INTEGER, fields: ["hash", "authorName", "authorEmail", "rawBody"], - branch: `${start.trim()}..${end.trim()}`, + // If start === firstCommit then we want to include that commit in the changelog + // Otherwise it was that last release and should not be included in the release. + branch: first === startSha ? end : `${start.trim()}..${end.trim()}`, execOptions: { maxBuffer: 1000 * 1024 }, }); @@ -334,6 +344,7 @@ export default class Git { files: (commit.files || []).map((file) => path.resolve(file)), })); } catch (error) { + console.log(error); const tag = error.match(/ambiguous argument '(\S+)\.\.\S+'/); if (tag) {