|
1 | 1 | import * as core from '@actions/core';
|
2 | 2 | import * as github from '@actions/github';
|
3 | 3 | import * as yaml from 'js-yaml';
|
4 |
| -import {Minimatch} from 'minimatch'; |
| 4 | +import {Minimatch, IMinimatch} from 'minimatch'; |
5 | 5 |
|
6 | 6 | async function run() {
|
7 | 7 | try {
|
@@ -116,15 +116,28 @@ function getLabelGlobMapFromObject(configObject: any): Map<string, string[]> {
|
116 | 116 | return labelGlobs;
|
117 | 117 | }
|
118 | 118 |
|
| 119 | +function printPattern(matcher: IMinimatch): string { |
| 120 | + return (matcher.negate ? "!" : "") + matcher.pattern; |
| 121 | +} |
| 122 | + |
119 | 123 | function checkGlobs(changedFiles: string[], globs: string[]): boolean {
|
120 |
| - for (const glob of globs) { |
121 |
| - core.debug(` checking pattern ${glob}`); |
122 |
| - const matcher = new Minimatch(glob); |
123 |
| - for (const changedFile of changedFiles) { |
124 |
| - core.debug(` - ${changedFile}`); |
| 124 | + const matchers = globs.map(g => new Minimatch(g)); |
| 125 | + for (const changedFile of changedFiles) { |
| 126 | + core.debug(` testing patterns against ${changedFile}`); |
| 127 | + for (const matcher of matchers) { |
| 128 | + core.debug(` - ${printPattern(matcher)}`); |
125 | 129 | if (matcher.match(changedFile)) {
|
126 |
| - core.debug(` ${changedFile} matches`); |
127 |
| - return true; |
| 130 | + // match and not an exclusion rule |
| 131 | + if (!matcher.negate) { |
| 132 | + core.debug(` ${printPattern(matcher)} matches`); |
| 133 | + return true; |
| 134 | + } |
| 135 | + } else { |
| 136 | + // non-match, but is an exclusion rule |
| 137 | + if (matcher.negate) { |
| 138 | + core.debug(` ${printPattern(matcher)} excluded`); |
| 139 | + break; |
| 140 | + } |
128 | 141 | }
|
129 | 142 | }
|
130 | 143 | }
|
|
0 commit comments