mirror of
https://github.com/dorny/paths-filter.git
synced 2025-06-08 00:59:04 +00:00
Export files matching rules (#32)
* Export files matching rules * Improve debug output * Fix PR test workflow * Always quote output path + fix PR test * Use proper single quote escaping in workflow file * Improve error handling and docs for list-files input parameter
This commit is contained in:
parent
483986d0a7
commit
3f845744aa
8 changed files with 205 additions and 125 deletions
|
@ -23,7 +23,11 @@ interface FilterRuleItem {
|
|||
matcher: minimatch.IMinimatch // Matches the filename
|
||||
}
|
||||
|
||||
export default class Filter {
|
||||
export interface FilterResults {
|
||||
[key: string]: File[]
|
||||
}
|
||||
|
||||
export class Filter {
|
||||
rules: {[key: string]: FilterRuleItem[]} = {}
|
||||
|
||||
// Creates instance of Filter and load rules from YAML if it's provided
|
||||
|
@ -49,20 +53,20 @@ export default class Filter {
|
|||
}
|
||||
}
|
||||
|
||||
// Returns dictionary with match result per rule
|
||||
match(files: File[]): {[key: string]: boolean} {
|
||||
const result: {[key: string]: boolean} = {}
|
||||
match(files: File[]): FilterResults {
|
||||
const result: FilterResults = {}
|
||||
for (const [key, patterns] of Object.entries(this.rules)) {
|
||||
const match = files.some(file =>
|
||||
patterns.some(
|
||||
rule => (rule.status === undefined || rule.status.includes(file.status)) && rule.matcher.match(file.filename)
|
||||
)
|
||||
)
|
||||
result[key] = match
|
||||
result[key] = files.filter(file => this.isMatch(file, patterns))
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
private isMatch(file: File, patterns: FilterRuleItem[]): boolean {
|
||||
return patterns.some(
|
||||
rule => (rule.status === undefined || rule.status.includes(file.status)) && rule.matcher.match(file.filename)
|
||||
)
|
||||
}
|
||||
|
||||
private parseFilterItemYaml(item: FilterItemYaml): FilterRuleItem[] {
|
||||
if (Array.isArray(item)) {
|
||||
return flat(item.map(i => this.parseFilterItemYaml(i)))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue