Merge pull request #1304 from mikepenz/test/tag_resolver_negation
Test inverse tag resolver
This commit is contained in:
+66
-1
@@ -1,4 +1,5 @@
|
|||||||
import {filterTags, prepareAndSortTags, TagInfo} from '../src/pr-collector/tags'
|
import { validateTransformer } from '../src/pr-collector/regexUtils'
|
||||||
|
import {filterTags, prepareAndSortTags, TagInfo, transformTags} from '../src/pr-collector/tags'
|
||||||
|
|
||||||
jest.setTimeout(180000)
|
jest.setTimeout(180000)
|
||||||
|
|
||||||
@@ -114,3 +115,67 @@ it('Should filter tags correctly using the regex', async () => {
|
|||||||
|
|
||||||
expect(filtered).toStrictEqual(`api-0.0.1,api-0.0.1-rc01,api-10.1.0-2`)
|
expect(filtered).toStrictEqual(`api-0.0.1,api-0.0.1-rc01,api-10.1.0-2`)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('Should filter tags correctly using the regex (inverse)', async () => {
|
||||||
|
const tags: TagInfo[] = [
|
||||||
|
{name: 'api-0.0.1', commit: ''},
|
||||||
|
{name: 'api-0.0.1-rc01', commit: ''},
|
||||||
|
{name: 'config-0.1.0', commit: ''},
|
||||||
|
{name: '0.1.0-b01', commit: ''},
|
||||||
|
{name: '1.0.0', commit: ''},
|
||||||
|
{name: '1.0.0-a01', commit: ''},
|
||||||
|
{name: '2.0.0', commit: ''},
|
||||||
|
{name: 'ap-10.0.0', commit: ''},
|
||||||
|
{name: '10.1.0', commit: ''},
|
||||||
|
{name: 'api-10.1.0-2', commit: ''},
|
||||||
|
{name: '20.0.2', commit: ''}
|
||||||
|
]
|
||||||
|
|
||||||
|
const tagResolver = {
|
||||||
|
method: 'non-existing-method',
|
||||||
|
filter: {
|
||||||
|
pattern: '^(?!\\w+-)(.+)',
|
||||||
|
flags: 'gu'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const filtered = filterTags(tags, tagResolver)
|
||||||
|
.map(function (tag) {
|
||||||
|
return tag.name
|
||||||
|
})
|
||||||
|
.join(',')
|
||||||
|
|
||||||
|
expect(filtered).toStrictEqual(`0.1.0-b01,1.0.0,1.0.0-a01,2.0.0,10.1.0,20.0.2`)
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
it('Should transform tags correctly using the regex', async () => {
|
||||||
|
const tags: TagInfo[] = [
|
||||||
|
{name: 'api-0.0.1', commit: ''},
|
||||||
|
{name: 'api-0.0.1-rc01', commit: ''},
|
||||||
|
{name: 'config-0.1.0', commit: ''},
|
||||||
|
{name: '0.1.0-b01', commit: ''},
|
||||||
|
{name: '2.0.0', commit: ''},
|
||||||
|
{name: '10.1.0', commit: ''},
|
||||||
|
{name: 'api-10.1.0-2', commit: ''},
|
||||||
|
{name: '20.0.2', commit: ''}
|
||||||
|
]
|
||||||
|
|
||||||
|
const tagResolver = {
|
||||||
|
method: 'non-existing-method',
|
||||||
|
transformer: {
|
||||||
|
pattern: '(api\-)?(.+)',
|
||||||
|
target: "$2"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const transformer = validateTransformer(tagResolver.transformer)
|
||||||
|
if(transformer != null) {
|
||||||
|
const transformed = transformTags(tags, transformer)
|
||||||
|
.map(function (tag) {
|
||||||
|
return tag.name
|
||||||
|
})
|
||||||
|
.join(',')
|
||||||
|
|
||||||
|
expect(transformed).toStrictEqual(`0.0.1,0.0.1-rc01,config-0.1.0,0.1.0-b01,2.0.0,10.1.0,10.1.0-2,20.0.2`)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|||||||
+2
-1
@@ -1020,7 +1020,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.prepareAndSortTags = exports.filterTags = exports.Tags = void 0;
|
exports.prepareAndSortTags = exports.transformTags = exports.filterTags = exports.Tags = void 0;
|
||||||
const core = __importStar(__nccwpck_require__(2186));
|
const core = __importStar(__nccwpck_require__(2186));
|
||||||
const github = __importStar(__nccwpck_require__(5438));
|
const github = __importStar(__nccwpck_require__(5438));
|
||||||
const semver = __importStar(__nccwpck_require__(1383));
|
const semver = __importStar(__nccwpck_require__(1383));
|
||||||
@@ -1219,6 +1219,7 @@ function transformTags(tags, transformer) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
exports.transformTags = transformTags;
|
||||||
/*
|
/*
|
||||||
Sorts an array of tags as shown below:
|
Sorts an array of tags as shown below:
|
||||||
|
|
||||||
|
|||||||
+1
-1
File diff suppressed because one or more lines are too long
@@ -211,7 +211,7 @@ export function filterTags(tags: TagInfo[], tagResolver: TagResolver): TagInfo[]
|
|||||||
/**
|
/**
|
||||||
* Helper function to transform the tag name given the transformer
|
* Helper function to transform the tag name given the transformer
|
||||||
*/
|
*/
|
||||||
function transformTags(tags: TagInfo[], transformer: RegexTransformer): TagInfo[] {
|
export function transformTags(tags: TagInfo[], transformer: RegexTransformer): TagInfo[] {
|
||||||
return tags.map(function (tag) {
|
return tags.map(function (tag) {
|
||||||
if (transformer.pattern) {
|
if (transformer.pattern) {
|
||||||
const transformedName = tag.name.replace(transformer.pattern, transformer.target)
|
const transformedName = tag.name.replace(transformer.pattern, transformer.target)
|
||||||
|
|||||||
Reference in New Issue
Block a user