forked from nodejs/github-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode-owners.js
More file actions
31 lines (26 loc) · 769 Bytes
/
Copy pathnode-owners.js
File metadata and controls
31 lines (26 loc) · 769 Bytes
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
31
'use static'
const { parse } = require('codeowners-utils')
// NOTE(mmarchini): `codeowners-utils` doesn't respect ./ prefix,
// so we use micromatch
const micromatch = require('micromatch')
class Owners {
constructor (ownersDefinitions) {
this._ownersDefinitions = ownersDefinitions
}
static fromFile (content) {
return new Owners(parse(content))
}
getOwnersForPaths (paths) {
let ownersForPath = []
for (const { pattern, owners } of this._ownersDefinitions) {
if (micromatch(paths, pattern).length > 0) {
ownersForPath = ownersForPath.concat(owners)
}
}
// Remove duplicates before returning
return ownersForPath.filter((v, i) => ownersForPath.indexOf(v) === i).sort()
}
}
module.exports = {
Owners
}