|
1 | 1 | 'use strict'
|
2 | 2 |
|
3 | 3 | // order of entries in this map *does* matter for the resolved labels
|
4 |
| -const subSystemLabelsMap = { |
| 4 | +// earlier entries override later entries |
| 5 | +const subSystemLabelsMap = new Map([ |
5 | 6 | // don't want to label it a c++ update when we're "only" bumping the Node.js version
|
6 |
| - 'c++': /^src\/(?!node_version\.h)/, |
| 7 | + [/^src\/(?!node_version\.h)/, 'c++'], |
7 | 8 | // meta is a very specific label for things that are policy and or meta-info related
|
8 |
| - 'meta': /^([A-Z]+$|CODE_OF_CONDUCT|ROADMAP|WORKING_GROUPS|GOVERNANCE|CHANGELOG|\.mail|\.git.+)/, |
| 9 | + [/^([A-Z]+$|CODE_OF_CONDUCT|ROADMAP|WORKING_GROUPS|GOVERNANCE|CHANGELOG|\.mail|\.git.+)/, 'meta'], |
9 | 10 | // things that edit top-level .md files are always a doc change
|
10 |
| - 'doc': /^\w+\.md$/, |
| 11 | + [/^\w+\.md$/, 'doc'], |
11 | 12 | // libuv needs an explicit mapping, as the ordinary /deps/ mapping below would
|
12 | 13 | // end up as libuv changes labeled with "uv" (which is a non-existing label)
|
13 |
| - 'libuv': /^deps\/uv\//, |
14 |
| - '$1': /^deps\/([^/]+)/ |
15 |
| -} |
| 14 | + [/^deps\/uv\//, 'libuv'], |
| 15 | + [/^deps\/([^/]+)/, '$1'] |
| 16 | +]) |
16 | 17 |
|
17 |
| -const exclusiveLabelsMap = { |
18 |
| - test: /^test\//, |
19 |
| - doc: /^doc\//, |
20 |
| - benchmark: /^benchmark\// |
21 |
| -} |
| 18 | +const exclusiveLabelsMap = new Map([ |
| 19 | + [/^test\//, 'test'], |
| 20 | + [/^doc\//, 'doc'], |
| 21 | + [/^benchmark\//, 'benchmark'] |
| 22 | +]) |
22 | 23 |
|
23 | 24 | function resolveLabels (filepathsChanged) {
|
24 | 25 | const exclusiveLabels = matchExclusiveSubSystem(filepathsChanged)
|
@@ -54,30 +55,23 @@ function matchSubSystemsByRegex (rxLabelsMap, filepathsChanged) {
|
54 | 55 | }
|
55 | 56 |
|
56 | 57 | function mappedSubSystemForFile (labelsMap, filepath) {
|
57 |
| - return Object.keys(labelsMap).map((labelName) => { |
58 |
| - const rxForLabel = labelsMap[labelName] |
59 |
| - const matches = rxForLabel.exec(filepath) |
| 58 | + for (const [regex, label] of labelsMap) { |
| 59 | + const matches = regex.exec(filepath) |
60 | 60 |
|
61 |
| - // return undefined when subsystem regex didn't match, |
62 |
| - // we'll filter out these values with the .filter() below |
63 | 61 | if (matches === null) {
|
64 |
| - return undefined |
| 62 | + continue |
65 | 63 | }
|
66 | 64 |
|
67 | 65 | // label names starting with $ means we want to extract a matching
|
68 | 66 | // group from the regex we've just matched against
|
69 |
| - if (labelName.startsWith('$')) { |
70 |
| - const wantedMatchGroup = labelName.substr(1) |
| 67 | + if (label.startsWith('$')) { |
| 68 | + const wantedMatchGroup = label.substr(1) |
71 | 69 | return matches[wantedMatchGroup]
|
72 | 70 | }
|
73 | 71 |
|
74 | 72 | // use label name as is when label doesn't look like a regex matching group
|
75 |
| - return labelName |
76 |
| - }).filter(withoutUndefinedValues)[0] |
77 |
| -} |
78 |
| - |
79 |
| -function withoutUndefinedValues (label) { |
80 |
| - return label !== undefined |
| 73 | + return label |
| 74 | + } |
81 | 75 | }
|
82 | 76 |
|
83 | 77 | function matchesAnExclusiveLabel (filepath) {
|
|
0 commit comments