Skip to content

Commit

Permalink
fix(owners): path shouldn't start with .
Browse files Browse the repository at this point in the history
  • Loading branch information
mmarchini committed Aug 9, 2020
1 parent e64662f commit 1999f82
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 28 deletions.
15 changes: 7 additions & 8 deletions lib/node-owners.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
'use static'

const { parse } = require('codeowners-utils')
// NOTE(mmarchini): `codeowners-utils` doesn't respect ./ prefix,
// so we use micromatch
const micromatch = require('micromatch')
const { parse, matchPattern } = require('codeowners-utils')

class Owners {
constructor (ownersDefinitions) {
Expand All @@ -15,14 +12,16 @@ class Owners {
}

getOwnersForPaths (paths) {
let ownersForPath = []
let ownersForPaths = []
for (const { pattern, owners } of this._ownersDefinitions) {
if (micromatch(paths, pattern).length > 0) {
ownersForPath = ownersForPath.concat(owners)
for (const path of paths) {
if (matchPattern(path, pattern)) {
ownersForPaths = ownersForPaths.concat(owners)
}
}
}
// Remove duplicates before returning
return ownersForPath.filter((v, i) => ownersForPath.indexOf(v) === i).sort()
return ownersForPaths.filter((v, i) => ownersForPaths.indexOf(v) === i).sort()
}
}

Expand Down
18 changes: 7 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"express": "^4.13.4",
"glob": "^7.0.3",
"lru-cache": "^4.0.1",
"micromatch": "^4.0.2",
"request": "^2.88.0"
},
"devDependencies": {
Expand Down
16 changes: 8 additions & 8 deletions test/_fixtures/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
./file1 @nodejs/test1
./file2 @nodejs/test2
./file3 @nodejs/test1 @nodejs/test2
./file4 @nodejs/test1
./file5 @nodejs/test3
./folder1/* @nodejs/test3
./folder2/file1.* @nodejs/test4 @nodejs/test5
./lib/timers.js @nodejs/team @nodejs/team2
/file1 @nodejs/test1
/file2 @nodejs/test2
/file3 @nodejs/test1 @nodejs/test2
/file4 @nodejs/test1
/file5 @nodejs/test3
/folder1/* @nodejs/test3
/folder2/file1.* @nodejs/test4 @nodejs/test5
/lib/timers.js @nodejs/team @nodejs/team2

0 comments on commit 1999f82

Please sign in to comment.