Skip to content

Commit

Permalink
Merge pull request #1911 from intuit/conv-commits-default-release-type
Browse files Browse the repository at this point in the history
add defaultReleaseType option
  • Loading branch information
hipstersmoothie committed Mar 22, 2021
2 parents 8f919db + bcd3146 commit 6737ad6
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
17 changes: 17 additions & 0 deletions plugins/conventional-commits/README.md
Expand Up @@ -35,6 +35,8 @@ yarn add -D @auto-it/conventional-commits

## Options

### `preset`

You can use any [conventional-changelog preset](https://www.npmjs.com/search?q=conventional-changelog%20preset%20) with this plugin.
Using a preset will completely override this plugin's default behavior with whatever the preset defines.

Expand All @@ -47,3 +49,18 @@ Using a preset will completely override this plugin's default behavior with what
]
}
```

### `defaultReleaseType`

The default release type to apply when the conventional commit isn't "fix", "feat" or "breaking" (ex: "chore:").
Defaults to `skip`.

```json
{
"plugins": [
"npm",
["conventional-commits", { "defaultReleaseType": "patch" }]
// other plugins
]
}
```
Expand Up @@ -160,6 +160,32 @@ describe("parseCommit", () => {
labels: ["skip-release"],
});
});

test("should be able to configure the default release type", async () => {
const conventionalCommitsPlugin = new ConventionalCommitsPlugin({
defaultReleaseType: "patch",
});
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: ["patch"],
});
});
});

describe("normalizeCommit", () => {
Expand Down
12 changes: 9 additions & 3 deletions plugins/conventional-commits/src/index.ts
Expand Up @@ -77,9 +77,11 @@ const defaultPreset = {
const optionalOptions = t.partial({
/** A path to the formula template */
preset: t.string,
/** The default release type to apply when the conventional commit isn't "fix", "feat" or "breaking" */
defaultReleaseType: t.string,
});

const VERSIONS = [SEMVER.major, SEMVER.minor, SEMVER.patch, "skip"] as const;
const VERSIONS = [SEMVER.major, SEMVER.minor, SEMVER.patch] as const;

export type ConventionalCommitsOptions = t.TypeOf<typeof optionalOptions>;

Expand All @@ -103,7 +105,10 @@ export default class ConventionalCommitsPlugin implements IPlugin {

/** Initialize the plugin with it's options */
constructor(options: ConventionalCommitsOptions = {}) {
this.options = options;
this.options = {
defaultReleaseType: "skip",
...options,
};
}

/** Tap into auto plugin points. */
Expand All @@ -128,7 +133,8 @@ export default class ConventionalCommitsPlugin implements IPlugin {
const result = whatBump([conventionalCommit]);

if (result?.level !== null && result?.level !== undefined) {
const bump = VERSIONS[result.level];
const bump =
VERSIONS[result.level] || this.options.defaultReleaseType;
return bump;
}
};
Expand Down

0 comments on commit 6737ad6

Please sign in to comment.