Skip to content

Commit

Permalink
memoize getCommits
Browse files Browse the repository at this point in the history
  • Loading branch information
hipstersmoothie committed Jul 31, 2020
1 parent 5d9bb97 commit 2a0f270
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
25 changes: 24 additions & 1 deletion packages/core/src/__tests__/release.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down Expand Up @@ -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"]))
Expand Down
4 changes: 1 addition & 3 deletions packages/core/src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<IExtendedCommit[]> {
this.logger.verbose.info(`Getting commits from ${from} to ${to}`);

Expand Down

0 comments on commit 2a0f270

Please sign in to comment.