- enhance handling for exhaustive matching
- exhaustive will apply on rules and labels alike - simplify code - introduce new testcases to check the new behavior
This commit is contained in:
+1
-1
@@ -5,7 +5,7 @@ import {PullRequestInfo, retrieveProperty} from './pullRequests'
|
||||
/**
|
||||
* Checks if any of the rules match the given PR
|
||||
*/
|
||||
export function matchesRules(rules: Rule[], pr: PullRequestInfo, exhaustive: Boolean): Boolean {
|
||||
export function matchesRules(rules: Rule[], pr: PullRequestInfo, exhaustive: Boolean): boolean {
|
||||
const transformers: RegexTransformer[] = rules.map(rule => validateTransformer(rule)).filter(t => t !== null) as RegexTransformer[]
|
||||
if (exhaustive) {
|
||||
return transformers.every(transformer => {
|
||||
|
||||
+27
-33
@@ -121,51 +121,45 @@ export function buildChangelog(diffInfo: DiffInfo, prs: PullRequestInfo[], optio
|
||||
}
|
||||
}
|
||||
|
||||
if (category.labels !== undefined) {
|
||||
if (category.exhaustive === true) {
|
||||
if (
|
||||
haveEveryElements(
|
||||
category.labels.map(lbl => lbl.toLocaleLowerCase('en')),
|
||||
pr.labels
|
||||
)
|
||||
) {
|
||||
pullRequests.push(body)
|
||||
matched = true
|
||||
}
|
||||
} else {
|
||||
if (
|
||||
haveCommonElements(
|
||||
category.labels.map(lbl => lbl.toLocaleLowerCase('en')),
|
||||
pr.labels
|
||||
)
|
||||
) {
|
||||
pullRequests.push(body)
|
||||
matched = true
|
||||
}
|
||||
// in case we have exhaustive matching enabled, and have labels and/or rules
|
||||
// validate for an exhaustive match (e.g. every provided rule applies)
|
||||
if (category.exhaustive === true && (category.labels !== undefined || category.rules !== undefined)) {
|
||||
if (category.labels !== undefined) {
|
||||
matched = haveEveryElements(
|
||||
category.labels.map(lbl => lbl.toLocaleLowerCase('en')),
|
||||
pr.labels
|
||||
)
|
||||
}
|
||||
if (matched && category.rules !== undefined) {
|
||||
matched = matchesRules(category.rules, pr, true)
|
||||
}
|
||||
} else {
|
||||
// if not exhaustive, do individual matches
|
||||
if (category.labels !== undefined) {
|
||||
// check if either any of the labels applies
|
||||
matched = haveCommonElements(
|
||||
category.labels.map(lbl => lbl.toLocaleLowerCase('en')),
|
||||
pr.labels
|
||||
)
|
||||
}
|
||||
if (!matched && category.rules !== undefined) {
|
||||
// if no label did apply, check if any rule applies
|
||||
matched = matchesRules(category.rules, pr, false)
|
||||
}
|
||||
}
|
||||
|
||||
if (category.rules !== undefined) {
|
||||
if (matchesRules(category.rules, pr, category.exhaustive === true)) {
|
||||
pullRequests.push(body)
|
||||
matched = true
|
||||
}
|
||||
if (matched) {
|
||||
pullRequests.push(body) // if matched add the PR to the list
|
||||
}
|
||||
}
|
||||
|
||||
if (!matched) {
|
||||
// we allow to have pull requests included in an "uncategorized" category
|
||||
for (const [category, pullRequests] of categorized) {
|
||||
if (
|
||||
(category.labels === undefined || category.labels.length === 0) &&
|
||||
category.rules === undefined &&
|
||||
category.exclude_labels === undefined
|
||||
) {
|
||||
if ((category.labels === undefined || category.labels.length === 0) && category.rules === undefined) {
|
||||
pullRequests.push(body)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
uncategorizedPrs.push(body)
|
||||
} else {
|
||||
categorizedPrs.push(body)
|
||||
|
||||
+2
-2
@@ -166,10 +166,10 @@ export function createOrSet<T>(map: Map<string, T[]>, key: string, value: T): vo
|
||||
}
|
||||
}
|
||||
|
||||
export function haveCommonElements(arr1: string[], arr2: Set<string>): Boolean {
|
||||
export function haveCommonElements(arr1: string[], arr2: Set<string>): boolean {
|
||||
return arr1.some(item => arr2.has(item))
|
||||
}
|
||||
|
||||
export function haveEveryElements(arr1: string[], arr2: Set<string>): Boolean {
|
||||
export function haveEveryElements(arr1: string[], arr2: Set<string>): boolean {
|
||||
return arr1.every(item => arr2.has(item))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user