Support reusable paths blocks via yaml anchors (#13)

* Add support for nested arrays of path expressions

* Remove pull_request trigger type options

Default value is fine: opened, synchronize, reopened

* Add CHANGELOG

* Update README
This commit is contained in:
Michal Dorner 2020-06-19 23:39:06 +02:00 committed by GitHub
parent 4eb15bc267
commit 7d201829e2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 301 additions and 91 deletions

View file

@ -15,10 +15,11 @@ export default class Filter {
}
for (const name of Object.keys(doc)) {
const patterns = doc[name] as string[]
if (!Array.isArray(patterns)) {
const patternsNode = doc[name]
if (!Array.isArray(patternsNode)) {
this.throwInvalidFormatError()
}
const patterns = flat(patternsNode) as string[]
if (!patterns.every(x => typeof x === 'string')) {
this.throwInvalidFormatError()
}
@ -40,3 +41,9 @@ export default class Filter {
throw new Error('Invalid filter YAML format: Expected dictionary of string arrays')
}
}
// Creates a new array with all sub-array elements recursively concatenated
// In future could be replaced by Array.prototype.flat (supported on Node.js 11+)
function flat(arr: any[]): any[] {
return arr.reduce((acc, val) => acc.concat(Array.isArray(val) ? flat(val) : val), [])
}