@@ -23,6 +23,48 @@ interface FilterRuleItem {
23
23
isMatch : ( str : string ) => boolean // Matches the filename
24
24
}
25
25
26
+ /**
27
+ * Enumerates the possible logic quantifiers that can be used when determining
28
+ * if a file is a match or not with multiple patterns.
29
+ *
30
+ * The YAML configuration property that is parsed into one of these values is
31
+ * 'predicate-quantifier' on the top level of the configuration object of the
32
+ * action.
33
+ *
34
+ * The default is to use 'some' which used to be the hardcoded behavior prior to
35
+ * the introduction of the new mechanism.
36
+ *
37
+ * @see https://en.wikipedia.org/wiki/Quantifier_(logic)
38
+ */
39
+ export enum PredicateQuantifier {
40
+ /**
41
+ * When choosing 'every' in the config it means that files will only get matched
42
+ * if all the patterns are satisfied by the path of the file, not just at least one of them.
43
+ */
44
+ EVERY = 'every' ,
45
+ /**
46
+ * When choosing 'some' in the config it means that files will get matched as long as there is
47
+ * at least one pattern that matches them. This is the default behavior if you don't
48
+ * specify anything as a predicate quantifier.
49
+ */
50
+ SOME = 'some'
51
+ }
52
+
53
+ /**
54
+ * Used to define customizations for how the file filtering should work at runtime.
55
+ */
56
+ export type FilterConfig = { readonly predicateQuantifier : PredicateQuantifier }
57
+
58
+ /**
59
+ * An array of strings (at runtime) that contains the valid/accepted values for
60
+ * the configuration parameter 'predicate-quantifier'.
61
+ */
62
+ export const SUPPORTED_PREDICATE_QUANTIFIERS = Object . values ( PredicateQuantifier )
63
+
64
+ export function isPredicateQuantifier ( x : unknown ) : x is PredicateQuantifier {
65
+ return SUPPORTED_PREDICATE_QUANTIFIERS . includes ( x as PredicateQuantifier )
66
+ }
67
+
26
68
export interface FilterResults {
27
69
[ key : string ] : File [ ]
28
70
}
@@ -31,7 +73,7 @@ export class Filter {
31
73
rules : { [ key : string ] : FilterRuleItem [ ] } = { }
32
74
33
75
// Creates instance of Filter and load rules from YAML if it's provided
34
- constructor ( yaml ?: string ) {
76
+ constructor ( yaml ?: string , public readonly filterConfig ?: FilterConfig ) {
35
77
if ( yaml ) {
36
78
this . load ( yaml )
37
79
}
@@ -62,9 +104,14 @@ export class Filter {
62
104
}
63
105
64
106
private isMatch ( file : File , patterns : FilterRuleItem [ ] ) : boolean {
65
- return patterns . some (
66
- rule => ( rule . status === undefined || rule . status . includes ( file . status ) ) && rule . isMatch ( file . filename )
67
- )
107
+ const aPredicate = ( rule : Readonly < FilterRuleItem > ) => {
108
+ return ( rule . status === undefined || rule . status . includes ( file . status ) ) && rule . isMatch ( file . filename )
109
+ }
110
+ if ( this . filterConfig ?. predicateQuantifier === 'every' ) {
111
+ return patterns . every ( aPredicate )
112
+ } else {
113
+ return patterns . some ( aPredicate )
114
+ }
68
115
}
69
116
70
117
private parseFilterItemYaml ( item : FilterItemYaml ) : FilterRuleItem [ ] {
0 commit comments