Feat: support flags when using regexp

This commit is contained in:
DELMAS Nicolas 2022-09-23 15:44:55 +02:00
parent 8a595f42df
commit 472c83c1ce
11 changed files with 52 additions and 10 deletions

View file

@ -12,8 +12,12 @@ class ActionConfig {
this.useBranches = false;
/** A string which, if present in a git commit, indicates that a change represents a major (breaking) change. Wrap with '/' to match using a regular expression. */
this.majorPattern = "(MAJOR)";
/** A string which indicates the flags used by the `majorPattern` regular expression. */
this.majorFlags = "(MAJOR)";
/** A string which, if present in a git commit, indicates that a change represents a minor (feature) change. Wrap with '/' to match using a regular expression. */
this.minorPattern = "(MINOR)";
/** A string which indicates the flags used by the `minorPattern` regular expression. */
this.minorFlags = "(MINOR)";
/** Pattern to use when formatting output version */
this.versionFormat = '${major}.${minor}.${patch}';
/** Path to check for changes. If any changes are detected in the path the 'changed' output will true. Enter multiple paths separated by spaces. */

View file

@ -66,6 +66,8 @@ function run() {
useBranches: core.getInput('use_branches') === 'true',
majorPattern: core.getInput('major_pattern'),
minorPattern: core.getInput('minor_pattern'),
majorFlags: core.getInput('major_regexp_flags'),
minorFlags: core.getInput('minor_regexp_flags'),
versionFormat: core.getInput('version_format'),
changePath: core.getInput('change_path'),
namespace: core.getInput('namespace'),

View file

@ -15,12 +15,12 @@ const VersionType_1 = require("./VersionType");
class DefaultVersionClassifier {
constructor(config) {
const searchBody = config.searchCommitBody;
this.majorPattern = this.parsePattern(config.majorPattern, searchBody);
this.minorPattern = this.parsePattern(config.minorPattern, searchBody);
this.majorPattern = this.parsePattern(config.majorPattern, config.majorFlags, searchBody);
this.minorPattern = this.parsePattern(config.minorPattern, config.minorFlags, searchBody);
}
parsePattern(pattern, searchBody) {
parsePattern(pattern, flags, searchBody) {
if (pattern.startsWith('/') && pattern.endsWith('/')) {
var regex = new RegExp(pattern.slice(1, -1));
var regex = new RegExp(pattern.slice(1, -1), flags);
return searchBody ?
(commit) => regex.test(commit.subject) || regex.test(commit.body) :
(commit) => regex.test(commit.subject);