- move around some parts of the code
This commit is contained in:
@@ -1,42 +1,5 @@
|
||||
import * as core from '@actions/core'
|
||||
import {Extractor, Property, Regex, Rule, Transformer} from './configuration'
|
||||
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 {
|
||||
const transformers: RegexTransformer[] = rules.map(rule => validateTransformer(rule)).filter(t => t !== null) as RegexTransformer[]
|
||||
if (exhaustive) {
|
||||
return transformers.every(transformer => {
|
||||
return matches(pr, transformer, 'rule')
|
||||
})
|
||||
} else {
|
||||
return transformers.some(transformer => {
|
||||
return matches(pr, transformer, 'rule')
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the configured property results in a positive `test` with the regex.
|
||||
*/
|
||||
function matches(pr: PullRequestInfo, extractor: RegexTransformer, extractor_usecase: string): boolean {
|
||||
if (extractor.pattern == null) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (extractor.onProperty !== undefined && extractor.onProperty.length === 1) {
|
||||
const prop = extractor.onProperty[0]
|
||||
const value = retrieveProperty(pr, prop, extractor_usecase)
|
||||
const matched = extractor.pattern.test(value)
|
||||
if (core.isDebug()) {
|
||||
core.debug(` Pattern ${extractor.pattern} resulted in ${matched} for ${value} on PR ${pr.number} (usecase: ${extractor_usecase})`)
|
||||
}
|
||||
return matched
|
||||
}
|
||||
return false
|
||||
}
|
||||
import {Extractor, Property, Regex, RegexTransformer, Transformer} from './types'
|
||||
|
||||
export function validateTransformer(transformer?: Regex): RegexTransformer | null {
|
||||
if (transformer === undefined) {
|
||||
@@ -95,11 +58,3 @@ export function buildRegex(
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
export interface RegexTransformer {
|
||||
pattern: RegExp | null
|
||||
target: string
|
||||
onProperty?: Property[]
|
||||
method?: 'replace' | 'match'
|
||||
onEmpty?: string
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user