diff --git a/packages/core/src/git.ts b/packages/core/src/git.ts index 98c87921d..72212af5b 100644 --- a/packages/core/src/git.ts +++ b/packages/core/src/git.ts @@ -258,7 +258,6 @@ export default class Git { } /** Get the labels for a PR */ - @memoize() async getLabels(prNumber: number): Promise { this.logger.verbose.info(`Getting labels for PR: ${prNumber}`); diff --git a/plugins/conventional-commits/__tests__/conventional-commits.test.ts b/plugins/conventional-commits/__tests__/conventional-commits.test.ts index 88f1d753a..28d73f36c 100644 --- a/plugins/conventional-commits/__tests__/conventional-commits.test.ts +++ b/plugins/conventional-commits/__tests__/conventional-commits.test.ts @@ -41,7 +41,32 @@ describe("parseCommit", () => { ).toStrictEqual(commit); }); - test("should add correct semver label to commit", async () => { + test("should add correct semver label to commit - skip", async () => { + const conventionalCommitsPlugin = new ConventionalCommitsPlugin(); + const autoHooks = makeHooks(); + conventionalCommitsPlugin.apply({ + hooks: autoHooks, + labels: defaultLabels, + semVerLabels: versionLabels, + logger: dummyLog(), + git: { getCommitsForPR: () => Promise.resolve([]) } as any, + } as Auto); + + const logParseHooks = makeLogParseHooks(); + autoHooks.onCreateLogParse.call({ + hooks: logParseHooks, + } as LogParse); + + const commit = makeCommitFromMsg("chore: normal commit with no bump"); + expect( + await logParseHooks.parseCommit.promise({ ...commit }) + ).toStrictEqual({ + ...commit, + labels: ["skip-release"], + }); + }); + + test("should add correct semver label to commit - fix", async () => { const conventionalCommitsPlugin = new ConventionalCommitsPlugin(); const autoHooks = makeHooks(); conventionalCommitsPlugin.apply({ @@ -479,6 +504,42 @@ describe("prCheck", () => { expect(addLabelToPr).toHaveBeenCalledWith(1, "patch"); }); + test("should add skip label for non-release commits", async () => { + const conventionalCommitsPlugin = new ConventionalCommitsPlugin(); + const autoHooks = makeHooks(); + const addLabelToPr = jest.fn(); + const auto = ({ + hooks: autoHooks, + labels: defaultLabels, + semVerLabels: versionLabels, + logger: dummyLog(), + git: { + getLabels: async () => [], + getCommitsForPR: async () => { + return [ + { + sha: "1234", + commit: { + message: "chore: normal commit", + }, + }, + ]; + }, + addLabelToPr, + }, + } as unknown) as Auto; + + conventionalCommitsPlugin.apply(auto); + + await auto.hooks.prCheck.promise({ + pr: { + number: 1, + } as any, + }); + + expect(addLabelToPr).toHaveBeenCalledWith(1, "skip-release"); + }); + test("should add correct semver label to pr - custom labels", async () => { const conventionalCommitsPlugin = new ConventionalCommitsPlugin(); const customLabels = [ diff --git a/plugins/conventional-commits/src/index.ts b/plugins/conventional-commits/src/index.ts index b0b8751c9..d9f78660b 100644 --- a/plugins/conventional-commits/src/index.ts +++ b/plugins/conventional-commits/src/index.ts @@ -185,15 +185,19 @@ export default class ConventionalCommitsPlugin implements IPlugin { .reduce(getHigherSemverTag, SEMVER.noVersion); if ( - !bump || + bump === undefined || + bump === null || bump === SEMVER.premajor || bump === SEMVER.preminor || bump === SEMVER.prepatch ) { + return; } + + const bumpOrSkip = bump === SEMVER.noVersion ? 'skip' : bump; - const label = auto.semVerLabels?.get(bump); + const label = auto.semVerLabels?.get(bumpOrSkip); if (label) { await auto.git.addLabelToPr(pr.number, label[0]);