Support namespaces without tags.

This commit is contained in:
Paul Hatcherian 2022-08-21 22:40:59 -04:00
parent 3a712b126c
commit ae4e812946
5 changed files with 42 additions and 37 deletions

19
dist/index.js vendored
View file

@ -264,18 +264,13 @@ class DefaultTagFormatter {
return `${this.tagPrefix}*[0-9].*[0-9].*[0-9]`; return `${this.tagPrefix}*[0-9].*[0-9].*[0-9]`;
} }
Parse(tag) { Parse(tag) {
let stripedTag; let tagParts = tag
if (this.tagPrefix.includes('/') && tag.includes(this.tagPrefix)) { .replace(this.tagPrefix, '<--!PREFIX!-->')
let tagParts = tag .replace(this.namespace, '<--!NAMESPACE!-->')
.replace(this.tagPrefix, '<--!PREFIX!-->') .split('/');
.split('/'); const stripedTag = tagParts[tagParts.length - 1]
stripedTag = tagParts[tagParts.length - 1] .replace('<--!PREFIX!-->', this.tagPrefix)
.replace('<--!PREFIX!-->', this.tagPrefix); .replace('<--!NAMESPACE!-->', this.namespace);
}
else {
let tagParts = tag.split('/');
stripedTag = tagParts[tagParts.length - 1];
}
let versionValues = stripedTag let versionValues = stripedTag
.substring(this.tagPrefix.length) .substring(this.tagPrefix.length)
.slice(0, this.namespace === '' ? 999 : -(this.namespace.length + 1)) .slice(0, this.namespace === '' ? 999 : -(this.namespace.length + 1))

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View file

@ -22,18 +22,13 @@ class DefaultTagFormatter {
return `${this.tagPrefix}*[0-9].*[0-9].*[0-9]`; return `${this.tagPrefix}*[0-9].*[0-9].*[0-9]`;
} }
Parse(tag) { Parse(tag) {
let stripedTag; let tagParts = tag
if (this.tagPrefix.includes('/') && tag.includes(this.tagPrefix)) { .replace(this.tagPrefix, '<--!PREFIX!-->')
let tagParts = tag .replace(this.namespace, '<--!NAMESPACE!-->')
.replace(this.tagPrefix, '<--!PREFIX!-->') .split('/');
.split('/'); const stripedTag = tagParts[tagParts.length - 1]
stripedTag = tagParts[tagParts.length - 1] .replace('<--!PREFIX!-->', this.tagPrefix)
.replace('<--!PREFIX!-->', this.tagPrefix); .replace('<--!NAMESPACE!-->', this.namespace);
}
else {
let tagParts = tag.split('/');
stripedTag = tagParts[tagParts.length - 1];
}
let versionValues = stripedTag let versionValues = stripedTag
.substring(this.tagPrefix.length) .substring(this.tagPrefix.length)
.slice(0, this.namespace === '' ? 999 : -(this.namespace.length + 1)) .slice(0, this.namespace === '' ? 999 : -(this.namespace.length + 1))

View file

@ -13,7 +13,7 @@ export class DefaultTagFormatter implements TagFormatter {
this.namespace = config.namespace; this.namespace = config.namespace;
this.tagPrefix = config.tagPrefix; this.tagPrefix = config.tagPrefix;
this.namespaceSeperator = '-'; // maybe make configurable in the future this.namespaceSeperator = '-'; // maybe make configurable in the future
} }
public Format(versionInfo: VersionInformation): string { public Format(versionInfo: VersionInformation): string {
const result = `${this.tagPrefix}${versionInfo.major}.${versionInfo.minor}.${versionInfo.patch}`; const result = `${this.tagPrefix}${versionInfo.major}.${versionInfo.minor}.${versionInfo.patch}`;
@ -35,17 +35,16 @@ export class DefaultTagFormatter implements TagFormatter {
} }
public Parse(tag: string): [major: number, minor: number, patch: number] { public Parse(tag: string): [major: number, minor: number, patch: number] {
let stripedTag;
if (this.tagPrefix.includes('/') && tag.includes(this.tagPrefix)) { let tagParts = tag
let tagParts = tag .replace(this.tagPrefix, '<--!PREFIX!-->')
.replace(this.tagPrefix, '<--!PREFIX!-->') .replace(this.namespace, '<--!NAMESPACE!-->')
.split('/'); .split('/');
stripedTag = tagParts[tagParts.length - 1]
.replace('<--!PREFIX!-->', this.tagPrefix); const stripedTag = tagParts[tagParts.length - 1]
} else { .replace('<--!PREFIX!-->', this.tagPrefix)
let tagParts = tag.split('/'); .replace('<--!NAMESPACE!-->', this.namespace);
stripedTag = tagParts[tagParts.length - 1];
}
let versionValues = stripedTag let versionValues = stripedTag
.substring(this.tagPrefix.length) .substring(this.tagPrefix.length)
.slice(0, this.namespace === '' ? 999 : -(this.namespace.length + 1)) .slice(0, this.namespace === '' ? 999 : -(this.namespace.length + 1))

View file

@ -354,6 +354,22 @@ test('Namespace is tracked separately', async () => {
expect(subprojectResult.formattedVersion).toBe('0.1.1+0'); expect(subprojectResult.formattedVersion).toBe('0.1.1+0');
}, 15000); }, 15000);
test('Namespace allows dashes', async () => {
const repo = createTestRepo({ tagPrefix: '' }); // 0.0.0
repo.makeCommit('Initial Commit'); // 0.0.1
repo.exec('git tag 0.0.1');
repo.makeCommit('Second Commit'); // 0.0.2
repo.exec('git tag "0.1.0-sub/project"');
repo.makeCommit('Third Commit'); // 0.0.2 / 0.1.1
const result = await repo.runAction();
const subprojectResult = await repo.runAction({ namespace: "sub/project" });
expect(result.formattedVersion).toBe('0.0.2+1');
expect(subprojectResult.formattedVersion).toBe('0.1.1+0');
}, 15000);
test('Commits outside of path are not counted', async () => { test('Commits outside of path are not counted', async () => {
const repo = createTestRepo({ tagPrefix: '' }); // 0.0.0 const repo = createTestRepo({ tagPrefix: '' }); // 0.0.0