forked from nodejs/github-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ping reviewers based on which files were changed
Using a custom OWNERS file, `github-bot` will ping the appropriate teams based on which files were changed in a Pull Request. This feature is inteded to work around GitHub's limitation which prevents teams without explicit write access from being added as reviewers (thus preventing the vast majority of teams in the org from being used on GitHub's CODEOWNERS feature). The OWNERS file is a yaml file (to simplify parsing) composed of key-value paris. The key is always a string and represents a glob of the changed files. The value is always an array of strings, and each string is a team to be pinged. Ref: nodejs/node#33984
- Loading branch information
Showing
5 changed files
with
1,530 additions
and
1,205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
'use static' | ||
|
||
const yaml = require('js-yaml') | ||
const micromatch = require('micromatch') | ||
|
||
class Owners { | ||
constructor (ownersDefinitions) { | ||
console.log(ownersDefinitions) | ||
this._ownersDefinitions = ownersDefinitions | ||
} | ||
|
||
static fromYaml (content) { | ||
console.log(content) | ||
return new Owners(yaml.safeLoad(content)) | ||
} | ||
|
||
getOwnersForPaths (paths) { | ||
let owners = [] | ||
for (const ownersGlob of Object.keys(this._ownersDefinitions)) { | ||
console.log(paths, ownersGlob, micromatch(paths, ownersGlob)) | ||
if (micromatch(paths, ownersGlob).length > 0) { | ||
owners = owners.concat(this._ownersDefinitions[ownersGlob]) | ||
} | ||
} | ||
// Remove duplicates before returning | ||
return owners.filter((v, i) => owners.indexOf(v) === i) | ||
} | ||
} | ||
|
||
module.exports = { | ||
Owners | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.