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:
Michal Dorner 2020-08-30 21:18:14 +02:00 committed by GitHub
parent 483986d0a7
commit 3f845744aa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 205 additions and 125 deletions

View file

@ -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)))