Merge pull request #569 from mikepenz/feature/566
Configuration option to filter out tags given a regex
This commit is contained in:
@@ -204,7 +204,11 @@ This configuration is a `.json` file in the following format.
|
|||||||
"Owner/qa"
|
"Owner/qa"
|
||||||
],
|
],
|
||||||
"tag_resolver": {
|
"tag_resolver": {
|
||||||
"method": "semver"
|
"method": "semver",
|
||||||
|
"filter": {
|
||||||
|
"pattern": "api-(.+)",
|
||||||
|
"flags": "gu"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"base_branches": [
|
"base_branches": [
|
||||||
"dev"
|
"dev"
|
||||||
@@ -324,7 +328,8 @@ Table of descriptions for the `configuration.json` options to configure the resu
|
|||||||
| exclude_merge_branches | An array of branches to be ignored from processing as merge commits |
|
| exclude_merge_branches | An array of branches to be ignored from processing as merge commits |
|
||||||
| tag_resolver | Section to provide configuration for the tag resolving logic. Used if no `fromTag` is provided |
|
| tag_resolver | Section to provide configuration for the tag resolving logic. Used if no `fromTag` is provided |
|
||||||
| tag_resolver.method | Defines the method to use. Current options are: `semver`, `sort`. Default: `semver` |
|
| tag_resolver.method | Defines the method to use. Current options are: `semver`, `sort`. Default: `semver` |
|
||||||
| base_branches | The target branches for the merged PR, ingnores PRs with different target branch. Values can be a `regex`. Default: allow all base branches
|
| tag_resolver.filter | Defines a regex which is used to filter out tags not matching. |
|
||||||
|
| base_branches | The target branches for the merged PR, ingnores PRs with different target branch. Values can be a `regex`. Default: allow all base branches |
|
||||||
|
|
||||||
## Contribute 🧬
|
## Contribute 🧬
|
||||||
|
|
||||||
|
|||||||
+34
-1
@@ -1,6 +1,6 @@
|
|||||||
import {resolveConfiguration} from '../src/utils'
|
import {resolveConfiguration} from '../src/utils'
|
||||||
import {ReleaseNotesBuilder} from '../src/releaseNotesBuilder'
|
import {ReleaseNotesBuilder} from '../src/releaseNotesBuilder'
|
||||||
import {TagInfo, sortTags} from '../src/tags'
|
import { TagInfo, sortTags, filterTags } from '../src/tags';
|
||||||
|
|
||||||
jest.setTimeout(180000)
|
jest.setTimeout(180000)
|
||||||
|
|
||||||
@@ -91,3 +91,36 @@ it('Should order tags alphabetical', async () => {
|
|||||||
`a,20.0.2,2.0.0,1000.0.0,10.1.0,10.1.0-2,10.0.0,1.0.0,1.0.0-a01,v1,0.1.0-b01,0.0.1,0.0.1-rc01`
|
`a,20.0.2,2.0.0,1000.0.0,10.1.0,10.1.0-2,10.0.0,1.0.0,1.0.0-a01,v1,0.1.0-b01,0.0.1,0.0.1-rc01`
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('Should filter 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: '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": "api-(.+)",
|
||||||
|
"flags": "gu"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const filtered = filterTags(tags, tagResolver)
|
||||||
|
.map(function (tag) {
|
||||||
|
return tag.name
|
||||||
|
})
|
||||||
|
.join(',')
|
||||||
|
|
||||||
|
expect(filtered).toStrictEqual(
|
||||||
|
`api-0.0.1,api-0.0.1-rc01,api-10.1.0-2`
|
||||||
|
)
|
||||||
|
})
|
||||||
+19
-2
@@ -173,7 +173,8 @@ exports.DefaultConfiguration = {
|
|||||||
transformers: [],
|
transformers: [],
|
||||||
tag_resolver: {
|
tag_resolver: {
|
||||||
// defines the logic on how to resolve the previous tag, only relevant if `fromTag` is not specified
|
// defines the logic on how to resolve the previous tag, only relevant if `fromTag` is not specified
|
||||||
method: 'semver' // defines which method to use, by default it will use `semver` (dropping all non matching tags). Alternative `sort` is also available.
|
method: 'semver',
|
||||||
|
filter: undefined // filter out all tags not matching the regex
|
||||||
},
|
},
|
||||||
base_branches: [] // target branches for the merged PR ignoring PRs with different target branch, by default it will get all PRs
|
base_branches: [] // target branches for the merged PR ignoring PRs with different target branch, by default it will get all PRs
|
||||||
};
|
};
|
||||||
@@ -884,7 +885,7 @@ var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|||||||
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.sortTags = exports.Tags = void 0;
|
exports.sortTags = 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));
|
||||||
@@ -1031,6 +1032,22 @@ class Tags {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.Tags = Tags;
|
exports.Tags = Tags;
|
||||||
|
/*
|
||||||
|
* Uses the provided filter (if available) to filter out any tags not currently relevant.
|
||||||
|
* https://github.com/mikepenz/release-changelog-builder-action/issues/566
|
||||||
|
*/
|
||||||
|
function filterTags(tags, tagResolver) {
|
||||||
|
var _a;
|
||||||
|
const filter = tagResolver.filter;
|
||||||
|
if (filter !== undefined) {
|
||||||
|
const regex = new RegExp(filter.pattern.replace('\\\\', '\\'), (_a = filter.flags) !== null && _a !== void 0 ? _a : 'gu');
|
||||||
|
return tags.filter(tag => tag.name.match(regex) !== null);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return tags;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exports.filterTags = filterTags;
|
||||||
/*
|
/*
|
||||||
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
@@ -22,12 +22,15 @@ export interface Category {
|
|||||||
exhaustive?: boolean // requires all labels to be present in the PR
|
exhaustive?: boolean // requires all labels to be present in the PR
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Transformer {
|
export interface Regex {
|
||||||
pattern: string // the regex pattern to match
|
pattern: string // the regex pattern to match
|
||||||
target?: string // the target string to transform the source string using the regex to
|
|
||||||
flags?: string // the regex flag to use for RegExp
|
flags?: string // the regex flag to use for RegExp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface Transformer extends Regex {
|
||||||
|
target?: string // the target string to transform the source string using the regex to
|
||||||
|
}
|
||||||
|
|
||||||
export interface Extractor extends Transformer {
|
export interface Extractor extends Transformer {
|
||||||
on_property?: 'title' | 'author' | 'milestone' | 'body' | undefined // retrieve the property to extract the value from
|
on_property?: 'title' | 'author' | 'milestone' | 'body' | undefined // retrieve the property to extract the value from
|
||||||
method?: 'replace' | 'match' | undefined // the method to use to extract the value, `match` will not use the `target` property
|
method?: 'replace' | 'match' | undefined // the method to use to extract the value, `match` will not use the `target` property
|
||||||
@@ -35,6 +38,7 @@ export interface Extractor extends Transformer {
|
|||||||
|
|
||||||
export interface TagResolver {
|
export interface TagResolver {
|
||||||
method: string // semver, sort
|
method: string // semver, sort
|
||||||
|
filter?: Regex // the regex to filter the tags
|
||||||
}
|
}
|
||||||
|
|
||||||
export const DefaultConfiguration: Configuration = {
|
export const DefaultConfiguration: Configuration = {
|
||||||
@@ -66,7 +70,8 @@ export const DefaultConfiguration: Configuration = {
|
|||||||
transformers: [], // transformers to apply on the PR description according to the `pr_template`
|
transformers: [], // transformers to apply on the PR description according to the `pr_template`
|
||||||
tag_resolver: {
|
tag_resolver: {
|
||||||
// defines the logic on how to resolve the previous tag, only relevant if `fromTag` is not specified
|
// defines the logic on how to resolve the previous tag, only relevant if `fromTag` is not specified
|
||||||
method: 'semver' // defines which method to use, by default it will use `semver` (dropping all non matching tags). Alternative `sort` is also available.
|
method: 'semver', // defines which method to use, by default it will use `semver` (dropping all non matching tags). Alternative `sort` is also available.
|
||||||
|
filter: undefined // filter out all tags not matching the regex
|
||||||
},
|
},
|
||||||
base_branches: [] // target branches for the merged PR ignoring PRs with different target branch, by default it will get all PRs
|
base_branches: [] // target branches for the merged PR ignoring PRs with different target branch, by default it will get all PRs
|
||||||
}
|
}
|
||||||
|
|||||||
+20
@@ -191,6 +191,26 @@ export class Tags {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Uses the provided filter (if available) to filter out any tags not currently relevant.
|
||||||
|
* https://github.com/mikepenz/release-changelog-builder-action/issues/566
|
||||||
|
*/
|
||||||
|
export function filterTags(
|
||||||
|
tags: TagInfo[],
|
||||||
|
tagResolver: TagResolver
|
||||||
|
): TagInfo[] {
|
||||||
|
const filter = tagResolver.filter
|
||||||
|
if (filter !== undefined) {
|
||||||
|
const regex = new RegExp(
|
||||||
|
filter.pattern.replace('\\\\', '\\'),
|
||||||
|
filter.flags ?? 'gu'
|
||||||
|
)
|
||||||
|
return tags.filter(tag => tag.name.match(regex) !== null)
|
||||||
|
} else {
|
||||||
|
return tags
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Sorts an array of tags as shown below:
|
Sorts an array of tags as shown below:
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user