Package Exports
- codeowners-api
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (codeowners-api) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
codeowners-api
Simple module to interact with github codeowners This npm module was implemented mainly to support the chrome extension - codeowners-ext
Note on Github Oauth2 access tokens In order to get all the teams a user is part of, you need to provide a Github access token.
API
filterForCodeOwner(paths: string[], user: string)
Given an array of paths and the name of a github user (prefixed with @), returns the paths that this user is the codeowner of.
Using GithubAPI, the library will also get all the list of teams that this user is part of, inorder to return the mapping which includes this user, and all his/her teams
codeownersFileExists()
Returns true if a CODEOWNERS file exists for the given github repo
getCodeownersFile()
Returns string of the CODEOWNERS file in the given repo
Testing
> yarn test
Sample Usage
Based on this CODEOWNERS file:
#This is a comment
* @oreporan
/tests/*.txt @elaygl
# Another Comment!!
/tests/test2/someFile.txt @oreporan
/packages/some/ @elayglWill create this result:
const params = {repo: '', owner: '', auth: ''};
const codeOwnersApi = new Codeowner(params);
const result = await codeOwnersApi.filterForCodeOwner(
['/something/a.py', 'tests/something.js', 'tests/something.txt', 'packages/some/deep/dir/index.tsx'],
'@elaygl'
);
console.log(result) // [ 'tests/something.txt', 'packages/some/deep/dir/index.tsx' ]Authors
Ore Poran and Elay Gliskberg