-
-
Notifications
You must be signed in to change notification settings - Fork 157
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 --tag-parser-pattern & --tag-parser-replacement for unconventional tag coercion into valid semver. #222
base: master
Are you sure you want to change the base?
Conversation
…ge section in README.
--tag-parser-pattern [regex] # pattern used to capture values in tags for replacement | ||
--tag-parser-replacement [string] # replaces captures supplied in the --tag-parser-pattern option to create valid semver tags |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Documents option usage.
``` | ||
|
||
Note, both options need to be supplied for this to work. Also note, `$` signs in the replacement string must be escaped. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Documents parsing strategies and their differences.
.option('--tag-parser-pattern <regex>', 'pattern used to capture values in tags for replacement') | ||
.option('--tag-parser-replacement <string>', 'replaces captures supplied in the --tag-parser-pattern option to create valid semver tags') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adds options to commander.
const [tag, date] = string.split(DIVIDER) | ||
return { | ||
tag, | ||
date, | ||
title: tag, | ||
version: inferSemver(tag.replace(tagPrefix, '')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moves the tagPrefix replacement logic into the inferSemver
.
const inferSemver = (tag, { tagPrefix, tagParserPattern, tagParserReplacement }) => { | ||
if (!!tagParserPattern && !!tagParserReplacement) { | ||
return tag.replace(new RegExp(tagParserPattern), tagParserReplacement) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adds the logic for the pattern/replacement options.
|
||
if (!!tagPrefix && tag.startsWith(tagPrefix)) { | ||
tag = tag.replace(new RegExp(`^${tagPrefix}`), '') | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we are removing the "prefix" via the tagPrefix
option, actually check if the tag "starts with" the supply string and only remove it from the beginning.
'2.1.0-build.2355', | ||
'0.1.0-build.2345' | ||
]) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adds test.
This looks interesting but couldn’t the same be achieved with the existing |
@cookpete Good question! From what I remember (it's been a while since I looked at the code), |
Description
This PR adds the ability to pass in a regex capture pattern and a replacement string in order for auto-changelog to properly include, validate, and sort custom tagging approaches.
Stories
--tag-prefix
option to remove a non-semver string from tags but it cannot remove multiple invalid strings.--tag-pattern
, cannot properly sort said tags in their semver order (e.g.v4.10.1@next
appears beforev4.2.0@next
)Changes
--tag-parser-pattern
to allow user to supply a regex for capturing semver MAJOR.MINOR.PATCH[-pre-release.BUILD].--tag-parser-replacement
to allow user to replace the captured values and coerce the tag to valid semver.Proofs