Skip to content

Commit

Permalink
Merge pull request #1086 from krohrsb/chore/conventional-no-bump
Browse files Browse the repository at this point in the history
fix(conventional-commits): skip release when no increment detected
  • Loading branch information
hipstersmoothie authored Mar 30, 2020
2 parents 02bcb22 + 38d1cbf commit f1a09c0
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,57 @@ test("should add conventional commit label if none/skip", async () => {
const result = await logParse.normalizeCommit(commit);
expect(result?.labels).toStrictEqual(["skip-release", "internal", "patch"]);
});

test("should not add skip when a non skip commit is present with a skip commit", async () => {
const commit = makeCommitFromMsg("fix: a test");
const conventionalCommitsPlugin = new ConventionalCommitsPlugin();
const logParse = new LogParse();
const autoHooks = makeHooks();
const mockGit = ({
getUserByEmail: jest.fn(),
searchRepo: jest.fn(),
getCommitDate: jest.fn(),
getFirstCommit: jest.fn(),
getPr: jest.fn(),
getLatestRelease: () => Promise.resolve("1.2.3"),
getGitLog: () =>
Promise.resolve([commit, makeCommitFromMsg("chore: a test 2")]),
getCommitsForPR: () => Promise.resolve([{ sha: "1" }]),
} as unknown) as Git;

conventionalCommitsPlugin.apply({
hooks: autoHooks,
labels: defaultLabels,
semVerLabels: versionLabels,
logger: dummyLog(),
git: mockGit,
release: new Release(mockGit),
} as Auto);

autoHooks.onCreateLogParse.call(logParse);

const result = await logParse.normalizeCommit(commit);
expect(result?.labels).toStrictEqual(["patch"]);
});

test("should skip when not a fix/feat/breaking change commit", async () => {
const conventionalCommitsPlugin = new ConventionalCommitsPlugin();
const autoHooks = makeHooks();
conventionalCommitsPlugin.apply({
hooks: autoHooks,
labels: defaultLabels,
semVerLabels: versionLabels,
logger: dummyLog(),
} as Auto);

const logParseHooks = makeLogParseHooks();
autoHooks.onCreateLogParse.call({
hooks: logParseHooks,
} as LogParse);

const commit = makeCommitFromMsg("chore: i should not trigger a release");
expect(await logParseHooks.parseCommit.promise({ ...commit })).toStrictEqual({
...commit,
labels: ["skip-release"],
});
});
7 changes: 4 additions & 3 deletions plugins/conventional-commits/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ export default class ConventionalCommitsPlugin implements IPlugin {
mappers.increment,
parse(commit.subject)
);
const incrementLabel = auto.semVerLabels.get(
conventionalCommit.increment as VersionLabel
);
// conventional commits will return a falsy value when no incrememnt is detected (e.g., chore/perf/refactor commits)
const commitIncrement =
(conventionalCommit.increment as VersionLabel) || "skip";
const incrementLabel = auto.semVerLabels.get(commitIncrement);
const allSemVerLabels = [
auto.semVerLabels.get(SEMVER.major),
auto.semVerLabels.get(SEMVER.minor),
Expand Down

0 comments on commit f1a09c0

Please sign in to comment.