Add --tag-parser-pattern & --tag-parser-replacement for unconventional tag coercion into valid semver. - #222
Add --tag-parser-pattern & --tag-parser-replacement for unconventional tag coercion into valid semver.#222yulolimum wants to merge 8 commits into
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 |
| ``` | ||
|
|
||
| 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.
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') |
| tag, | ||
| date, | ||
| title: tag, | ||
| version: inferSemver(tag.replace(tagPrefix, '')) |
There was a problem hiding this comment.
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.
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.
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' | ||
| ]) | ||
| }) |
|
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-prefixoption 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@nextappears beforev4.2.0@next)Changes
--tag-parser-patternto allow user to supply a regex for capturing semver MAJOR.MINOR.PATCH[-pre-release.BUILD].--tag-parser-replacementto allow user to replace the captured values and coerce the tag to valid semver.Proofs