- add new ability to filter out tags based on a regex

- FIX https://github.com/mikepenz/release-changelog-builder-action/issues/566
This commit is contained in:
Mike Penz
2021-11-05 08:52:21 +01:00
parent 431f48dd0f
commit ed954db1f6
6 changed files with 89 additions and 9 deletions
+8 -3
View File
@@ -22,12 +22,15 @@ export interface Category {
exhaustive?: boolean // requires all labels to be present in the PR
}
export interface Transformer {
export interface Regex {
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
}
export interface Transformer extends Regex {
target?: string // the target string to transform the source string using the regex to
}
export interface Extractor extends Transformer {
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
@@ -35,6 +38,7 @@ export interface Extractor extends Transformer {
export interface TagResolver {
method: string // semver, sort
filter?: Regex // the regex to filter the tags
}
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`
tag_resolver: {
// 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
}
+20
View File
@@ -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: