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

add defaultReleaseType option #1911

Merged
merged 1 commit into from Mar 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
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