-
Notifications
You must be signed in to change notification settings - Fork 1
/
owners.js
30 lines (28 loc) · 960 Bytes
/
owners.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
let buildRegexList = function(areaOwners) {
let list = [];
areaOwners.forEach(function(owners, label) {
list.push([new RegExp(label), owners]);
});
return list;
};
let labelToOwners = function(label, excludeUser, mapping, regexList) {
let owners;
const ownersForExactLabel = mapping.get(label);
if (ownersForExactLabel !== undefined) { // exact label match
owners = ownersForExactLabel;
} else { // regex label match
for (let i = 0; i < regexList.length; i++) {
const re = regexList[i][0];
const ownersForRegexLabel = regexList[i][1];
if (re.test(label)) {
owners = ownersForRegexLabel;
}
}
}
if (owners !== undefined && excludeUser !== undefined) {
owners = owners.filter(owner => owner !== excludeUser);
}
return owners;
};
exports.labelToOwners = labelToOwners;
exports.buildRegexList = buildRegexList;