- refactor regex handling for the different usecases to allow providing the preferred method

- introduce new `exec` and `execAll` variants which support named groups
- introduce `replaceAll` in addition to `replace`
- update test cases
- cleanup code
This commit is contained in:
Mike Penz
2024-03-01 15:20:31 +00:00
committed by GitHub
parent 225bc31b07
commit 89d1f43dfa
8 changed files with 209 additions and 75 deletions
+2 -2
View File
@@ -1,13 +1,13 @@
import * as core from '@actions/core'
import {RegexTransformer, Rule} from './pr-collector/types'
import {PullRequestInfo, retrieveProperty} from './pr-collector/pullRequests'
import {validateTransformer} from './pr-collector/regexUtils'
import {validateRegex} from './pr-collector/regexUtils'
/**
* Checks if any of the rules match the given PR
*/
export function matchesRules(rules: Rule[], pr: PullRequestInfo, exhaustive: Boolean): boolean {
const transformers: RegexTransformer[] = rules.map(rule => validateTransformer(rule)).filter(t => t !== null) as RegexTransformer[]
const transformers: RegexTransformer[] = rules.map(rule => validateRegex(rule)).filter(t => t !== null) as RegexTransformer[]
if (exhaustive) {
return transformers.every(transformer => {
return matches(pr, transformer, 'rule')