mirror of
https://github.com/dorny/paths-filter.git
synced 2025-06-23 10:58:03 +02:00
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:
@ -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), [])
|
||||
}
|
||||
|
Reference in New Issue
Block a user