Skip to content

Commit 485bc0a

Browse files
authored
feat(preset): support ignoreCommits option (#836)
1 parent fc8464b commit 485bc0a

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const debug = debugFactory("semantic-release:release-notes-generator");
3131
export async function generateNotes(pluginConfig, context) {
3232
const { commits, lastRelease, nextRelease, options, cwd } = context;
3333
const repositoryUrl = options.repositoryUrl.replace(/\.git$/i, "");
34-
const { parserOpts, writerOpts } = await loadChangelogConfig(pluginConfig, context);
34+
const { commitOpts, parserOpts, writerOpts } = await loadChangelogConfig(pluginConfig, context);
3535

3636
const [match, auth, host, path] = /^(?!.+:\/\/)(?:(?<auth>.*)@)?(?<host>.*?):(?<path>.*)$/.exec(repositoryUrl) || [];
3737
let { hostname, port, pathname, protocol } = new URL(
@@ -52,6 +52,11 @@ export async function generateNotes(pluginConfig, context) {
5252
return false;
5353
}
5454

55+
if (commitOpts && commitOpts.ignore && new RegExp(commitOpts.ignore).test(message) && !commitOpts.merges) {
56+
debug("Skip commit %s by ignore option", hash);
57+
return false;
58+
}
59+
5560
return true;
5661
})
5762
.map((rawCommit) => ({

lib/load-changelog-config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export default async ({ preset, config, parserOpts, writerOpts, presetConfig },
3333
}
3434

3535
return {
36+
commitOpts: loadedConfig.commits,
3637
parserOpts: { ...loadedConfig.parser, ...parserOpts },
3738
writerOpts: { ...loadedConfig.writer, ...writerOpts },
3839
};

test/integration.test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,32 @@ test.serial('Accept a partial "presetConfig" object as option', async (t) => {
249249
t.regex(changelog, new RegExp(escape("* Change test ([222](https://github.com/owner/repo/commit/222))")));
250250
});
251251

252+
test.serial('Accept ignoreCommits in "presetConfig" object as option', async (t) => {
253+
const { generateNotes } = await import("../index.js");
254+
const commits = [
255+
{ hash: "111", message: "fix: First fix" },
256+
{ hash: "222", message: "test: Change test [python]" },
257+
];
258+
const changelog = await generateNotes(
259+
{
260+
preset: "conventionalcommits",
261+
presetConfig: {
262+
ignoreCommits: "\\[python\\]",
263+
types: [
264+
{ type: "fix", section: "Bug Fixes", hidden: false },
265+
{ type: "test", section: "Test !!", hidden: false },
266+
],
267+
},
268+
},
269+
{ cwd, options: { repositoryUrl }, lastRelease, nextRelease, commits }
270+
);
271+
272+
t.regex(changelog, /### Bug Fixes/);
273+
t.regex(changelog, new RegExp(escape("First fix")));
274+
t.notRegex(changelog, /### Test !!/);
275+
t.notRegex(changelog, new RegExp(escape("* Change test ([222](https://github.com/owner/repo/commit/222))")));
276+
});
277+
252278
test.serial('Use "gitHead" from "lastRelease" and "nextRelease" if "gitTag" is not defined', async (t) => {
253279
const { generateNotes } = await import("../index.js");
254280
const commits = [

0 commit comments

Comments
 (0)