Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use strict check so SEMVER.noVersion can add skip-release #2086

Merged
merged 2 commits into from Sep 30, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -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({
Expand Down Expand Up @@ -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 = [
Expand Down
8 changes: 6 additions & 2 deletions plugins/conventional-commits/src/index.ts
Expand Up @@ -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]);
Expand Down