From 2a0f2704a6701cffaac9e8a3e923cd5d42b1a7e4 Mon Sep 17 00:00:00 2001 From: Andrew Lisowski Date: Fri, 31 Jul 2020 10:00:12 -0700 Subject: [PATCH] memoize getCommits --- packages/core/src/__tests__/release.test.ts | 25 ++++++++++++++++++++- packages/core/src/git.ts | 4 +--- packages/core/src/release.ts | 1 + 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/packages/core/src/__tests__/release.test.ts b/packages/core/src/__tests__/release.test.ts index 5df1b7ff2..16ccfec0f 100644 --- a/packages/core/src/__tests__/release.test.ts +++ b/packages/core/src/__tests__/release.test.ts @@ -1049,7 +1049,7 @@ describe("Release", () => { expect(await gh.getSemverBump("1234", "123")).toBe(SEMVER.minor); }); - test("should be able to configure labels", async () => { + test("should be able to configure labels - no release", async () => { const customLabels = [ ...defaultLabels, { name: "Version: Major", releaseType: SEMVER.major }, @@ -1083,7 +1083,30 @@ describe("Release", () => { ); expect(await gh.getSemverBump("1234", "123")).toBe(""); + }); + + test("should be able to configure labels", async () => { + const customLabels = [ + ...defaultLabels, + { name: "Version: Major", releaseType: SEMVER.major }, + { name: "Version: Minor", releaseType: SEMVER.minor }, + { name: "Version: Patch", releaseType: SEMVER.patch }, + { name: "Deploy", releaseType: "release" }, + ] as ILabelDefinition[]; + + const gh = new Release(git, { + onlyPublishWithReleaseLabel: true, + prereleaseBranches: ["next"], + labels: customLabels, + baseBranch: "master", + }); + const commits = [ + makeCommitFromMsg("First (#1234)"), + makeCommitFromMsg("Second (#1235)"), + makeCommitFromMsg("Third (#1236)"), + ]; + // Test deploy label creates release getGitLog.mockReturnValueOnce(commits); getPr.mockReturnValueOnce( Promise.resolve(mockLabels(["Version: Minor", "Deploy"])) diff --git a/packages/core/src/git.ts b/packages/core/src/git.ts index 50f67ece8..003c9971b 100644 --- a/packages/core/src/git.ts +++ b/packages/core/src/git.ts @@ -128,9 +128,7 @@ export default class Git { ? this.options.graphqlBaseUrl || join(new URL(this.baseUrl).origin, "api") : this.baseUrl; this.logger.veryVerbose.info(`Initializing GitHub with: ${this.baseUrl}`); - const GitHub = Octokit.plugin(enterpriseCompatibility) - .plugin(retry) - .plugin(throttling); + const GitHub = Octokit.plugin(enterpriseCompatibility, retry, throttling); this.github = new GitHub({ baseUrl: this.baseUrl, auth: this.options.token, diff --git a/packages/core/src/release.ts b/packages/core/src/release.ts index 2b9e225a3..9ec664736 100644 --- a/packages/core/src/release.ts +++ b/packages/core/src/release.ts @@ -283,6 +283,7 @@ export default class Release { * @param from - Tag or SHA to start at * @param to - Tag or SHA to end at (defaults to HEAD) */ + @memoize() async getCommits(from: string, to = "HEAD"): Promise { this.logger.verbose.info(`Getting commits from ${from} to ${to}`);