Skip to content

Commit

Permalink
Merge pull request #2086 from hborawski/conventional-commits-skip
Browse files Browse the repository at this point in the history
use strict check so SEMVER.noVersion can add skip-release
  • Loading branch information
adierkens committed Sep 30, 2021
2 parents d79865f + f3bd5a5 commit d1b3438
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 4 deletions.
1 change: 0 additions & 1 deletion packages/core/src/git.ts
Expand Up @@ -258,7 +258,6 @@ export default class Git {
}

/** Get the labels for a PR */
@memoize()
async getLabels(prNumber: number): Promise<string[]> {
this.logger.verbose.info(`Getting labels for PR: ${prNumber}`);

Expand Down
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

0 comments on commit d1b3438

Please sign in to comment.