Ignore non-version branches, reset diagnostics between tests

This commit is contained in:
Paul Hatcherian 2023-09-30 04:51:49 -04:00
parent cfbfddabdd
commit ec20cad99a
17 changed files with 2358 additions and 1307 deletions

View file

@ -14,11 +14,15 @@ class BranchVersioningTagFormatter extends DefaultTagFormatter_1.DefaultTagForma
}
constructor(config, branchName) {
super(config);
this.branchName = branchName;
const pattern = config.versionFromBranch === true ?
new RegExp("[0-9]+.[0-9]+$|[0-9]+$") :
this.getRegex(config.versionFromBranch);
const result = pattern.exec(branchName);
if (result === null) {
this.major = NaN;
this.onVersionBranch = false;
return;
}
let branchVersion;
switch (result === null || result === void 0 ? void 0 : result.length) {
case 1:
@ -30,6 +34,7 @@ class BranchVersioningTagFormatter extends DefaultTagFormatter_1.DefaultTagForma
default:
throw new Error(`Unable to parse version from branch named '${branchName}' using pattern '${pattern}'`);
}
this.onVersionBranch = true;
const versionValues = branchVersion.split('.');
if (versionValues.length > 2) {
throw new Error(`The version string '${branchVersion}' parsed from branch '${branchName}' is invalid. It must be in the format 'major.minor' or 'major'`);
@ -45,7 +50,20 @@ class BranchVersioningTagFormatter extends DefaultTagFormatter_1.DefaultTagForma
}
}
}
GetPattern() {
let pattern = super.GetPattern();
if (!this.onVersionBranch) {
return pattern;
}
if (this.minor === undefined) {
return pattern.replace('*[0-9].*[0-9].*[0-9]', `${this.major}.*[0-9].*[0-9]`);
}
return pattern.replace('*[0-9].*[0-9].*[0-9]', `${this.major}.${this.minor}.*[0-9]`);
}
IsValid(tag) {
if (!this.onVersionBranch) {
return super.IsValid(tag);
}
if (!super.IsValid(tag)) {
return false;
}
@ -59,6 +77,9 @@ class BranchVersioningTagFormatter extends DefaultTagFormatter_1.DefaultTagForma
return true;
}
Parse(tag) {
if (!this.onVersionBranch) {
return super.Parse(tag);
}
const parsed = super.Parse(tag);
return [this.major, this.minor || parsed[1], parsed[2]];
}