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 support for including commit pattern #258

Merged
merged 10 commits into from
May 13, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 36 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,40 +21,42 @@ Usage: auto-changelog [options]

Options:

-o, --output [file] # output file, default: CHANGELOG.md
-c, --config [file] # config file location, default: .auto-changelog
-t, --template [template] # specify template to use [compact, keepachangelog, json], default: compact
-r, --remote [remote] # specify git remote to use for links, default: origin
-p, --package # use version from package.json as latest release
-v, --latest-version [version] # use specified version as latest release
-u, --unreleased # include section for unreleased changes
-l, --commit-limit [count] # number of commits to display per release, default: 3
-b, --backfill-limit [count] # number of commits to backfill empty releases with, default: 3
--commit-url [url] # override url for commits, use {id} for commit id
--issue-url [url] # override url for issues, use {id} for issue id
--merge-url [url] # override url for merges, use {id} for merge id
--compare-url [url] # override url for compares, use {from} and {to} for tags
--issue-pattern [regex] # override regex pattern for issues in commit messages
--breaking-pattern [regex] # regex pattern for breaking change commits
--merge-pattern [regex] # add custom regex pattern for merge commits
--ignore-commit-pattern [regex] # pattern to ignore when parsing commits
rouzwelt marked this conversation as resolved.
Show resolved Hide resolved
--tag-pattern [regex] # override regex pattern for version tags
--tag-prefix [prefix] # prefix used in version tags, default: v
--starting-version [tag] # specify earliest version to include in changelog
--starting-date [yyyy-mm-dd] # specify earliest date to include in changelog
--ending-version [tag] # specify latest version to include in changelog
--sort-commits [property] # sort commits by property [relevance, date, date-desc, subject, subject-desc], default: relevance
--release-summary # display tagged commit message body as release summary
--unreleased-only # only output unreleased changes
--hide-empty-releases # hide empty releases
--hide-credit # hide auto-changelog credit
--handlebars-setup [file] # handlebars setup file
--append-git-log [string] # string to append to git log command
--append-git-tag [string] # string to append to git tag command
--prepend # prepend changelog to output file
--stdout # output changelog to stdout
-V, --version # output the version number
-h, --help # output usage information
-o, --output [file] # output file, default: CHANGELOG.md
-c, --config [file] # config file location, default: .auto-changelog
-t, --template [template] # specify template to use [compact, keepachangelog, json], default: compact
-r, --remote [remote] # specify git remote to use for links, default: origin
-p, --package # use version from package.json as latest release
-v, --latest-version [version] # use specified version as latest release
-u, --unreleased # include section for unreleased changes
-l, --commit-limit [count] # number of commits to display per release, default: 3
-b, --backfill-limit [count] # number of commits to backfill empty releases with, default: 3
--commit-url [url] # override url for commits, use {id} for commit id
--issue-url [url] # override url for issues, use {id} for issue id
--merge-url [url] # override url for merges, use {id} for merge id
--compare-url [url] # override url for compares, use {from} and {to} for tags
--issue-pattern [regex] # override regex pattern for issues in commit messages
--breaking-pattern [regex] # regex pattern for breaking change commits
--merge-pattern [regex] # add custom regex pattern for merge commits
--blacklist-commit-pattern [regex] # pattern to blacklist when parsing commits
--whitelist-commit-pattern [regex] # pattern to whitelist when parsing commits, merge commits are be included by default unless strict flag is chekced
--strict-whitelist # make the commits whitelist strict to provided pattern by --include-commits-pattern
--tag-pattern [regex] # override regex pattern for version tags
--tag-prefix [prefix] # prefix used in version tags, default: v
--starting-version [tag] # specify earliest version to include in changelog
--starting-date [yyyy-mm-dd] # specify earliest date to include in changelog
--ending-version [tag] # specify latest version to include in changelog
--sort-commits [property] # sort commits by property [relevance, date, date-desc, subject, subject-desc], default: relevance
--release-summary # display tagged commit message body as release summary
--unreleased-only # only output unreleased changes
--hide-empty-releases # hide empty releases
--hide-credit # hide auto-changelog credit
--handlebars-setup [file] # handlebars setup file
--append-git-log [string] # string to append to git log command
--append-git-tag [string] # string to append to git tag command
--prepend # prepend changelog to output file
--stdout # output changelog to stdout
-V, --version # output the version number
-h, --help # output usage information


# Write log to CHANGELOG.md in current directory
Expand Down
21 changes: 18 additions & 3 deletions src/commits.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ const parseCommits = (string, options = {}) => {
.split(COMMIT_SEPARATOR)
.slice(1)
.map(commit => parseCommit(commit, options))
.filter(commit => filterCommit(commit, options))
.filter(commit => blacklistCommits(commit, options))
rouzwelt marked this conversation as resolved.
Show resolved Hide resolved
.filter(commit => whitelistCommits(commit, options))
}

const parseCommit = (commit, options = {}) => {
Expand Down Expand Up @@ -135,8 +136,22 @@ const getMerge = (commit, message, options = {}) => {
return null
}

const filterCommit = (commit, { ignoreCommitPattern }) => {
if (ignoreCommitPattern && new RegExp(ignoreCommitPattern).test(commit.subject)) {
const blacklistCommits = (commit, { blacklistCommitPattern }) => {
if (blacklistCommitPattern && new RegExp(blacklistCommitPattern).test(commit.subject)) {
return false
}
return true
}

const whitelistCommits = (commit, { whitelistCommitPattern, strictWhitelist, mergePattern }) => {
if (whitelistCommitPattern) {
if (new RegExp(whitelistCommitPattern).test(commit.subject)) return true
if (!strictWhitelist) {
const patterns = getMergePatterns({mergePattern})
for (const pattern of patterns) {
if (pattern.test(commit.message)) return true
}
}
return false
}
return true
Expand Down
4 changes: 3 additions & 1 deletion src/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ const getOptions = async argv => {
.option('--issue-pattern <regex>', 'override regex pattern for issues in commit messages')
.option('--breaking-pattern <regex>', 'regex pattern for breaking change commits')
.option('--merge-pattern <regex>', 'add custom regex pattern for merge commits')
.option('--ignore-commit-pattern <regex>', 'pattern to ignore when parsing commits')
.option('--blacklist-commit-pattern <regex>', 'pattern to blacklist when parsing commits')
.option('--whitelist-commit-pattern <regex>', 'pattern to whitelist when parsing commits, merge commits are be included by default unless strict flag is chekced')
.option('--strict-whitelist', 'make the commits whitelist strict to provided pattern by --include-commits-pattern')
.option('--tag-pattern <regex>', 'override regex pattern for version tags')
.option('--tag-prefix <prefix>', 'prefix used in version tags')
.option('--starting-version <tag>', 'specify earliest version to include in changelog')
Expand Down