Skip to content

Commit

Permalink
Add support for GitHub CODEOWNERS (OctoLinker#786)
Browse files Browse the repository at this point in the history
* Add support for GitHub CODEOWNERS

* remove e2e test
  • Loading branch information
stefanbuck authored Jan 24, 2020
1 parent c98adb2 commit edd1c4d
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 3 deletions.
5 changes: 5 additions & 0 deletions e2e/fixtures/.github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# should ignore lines below

*
javascript/**/*.js @stefanbuck
# /docker @stefanbuck
1 change: 1 addition & 0 deletions packages/core/load-plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ export { default as Sass } from '@octolinker/plugin-sass';
export { default as TypeScript } from '@octolinker/plugin-typescript';
export { default as Vim } from '@octolinker/plugin-vim';
export { default as GitHubActions } from '@octolinker/plugin-github-actions';
export { default as GitHubCodeowners } from '@octolinker/plugin-github-codeowners';
1 change: 1 addition & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@octolinker/plugin-dot-net-core": "1.0.0",
"@octolinker/plugin-gemfile-manifest": "1.0.0",
"@octolinker/plugin-github-actions": "1.0.0",
"@octolinker/plugin-github-codeowners": "1.0.0",
"@octolinker/plugin-go": "1.0.0",
"@octolinker/plugin-haskell": "1.0.0",
"@octolinker/plugin-homebrew-manifest": "1.0.0",
Expand Down
7 changes: 4 additions & 3 deletions packages/helper-insert-link/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ function injectUrl(node, value, startOffset, endOffset) {
try {
// Take quote marks into account to narrow down match
// in case value is given on the left and right hand side
const textMatch = node.textContent
.slice(startOffset - 1, endOffset + 1)
.trim(); // we don't want to include whitespace in the link
if (startOffset > 0) {
startOffset -= 1;
}
const textMatch = node.textContent.slice(startOffset, endOffset + 1).trim(); // we don't want to include whitespace in the link

findAndReplaceDOMText(node, {
find: textMatch,
Expand Down
47 changes: 47 additions & 0 deletions packages/plugin-github-codeowners/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { join, dirname, extname } from 'path';
import relativeFile from '@octolinker/resolver-relative-file';
import resolverTrustedUrl from '@octolinker/resolver-trusted-url';

export default {
name: 'GithubCodeowners',

resolve(path, [target]) {
if (target.endsWith('/**')) {
target = target.replace('/**', '');
}

if (target.endsWith('/*')) {
target = target.replace('/*', '');
}

if (target.includes('*')) {
return '';
}

if (target.startsWith('/')) {
target = `.${target}`;
}

target = join('../', target);

const basePath = join(dirname(path), target);
const fileExt = extname(basePath);

if (!fileExt) {
return resolverTrustedUrl({ target: basePath });
}

return relativeFile({ path, target });
},

getPattern() {
return {
pathRegexes: [/\.github\/CODEOWNERS$/],
githubClasses: [],
};
},

getLinkRegexes() {
return /^([^\s#]+)/gm;
},
};
13 changes: 13 additions & 0 deletions packages/plugin-github-codeowners/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "@octolinker/plugin-github-codeowners",
"version": "1.0.0",
"description": "",
"repository": "https://github.com/octolinker/octolinker/tree/master/packages/plugin-github-codeowners",
"license": "MIT",
"main": "./index.js",
"dependencies": {
"@octolinker/resolver-relative-file": "1.0.0",
"@octolinker/resolver-trusted-url": "1.0.0",
"@octolinker/helper-grammar-regex-collection": "1.0.0"
}
}

0 comments on commit edd1c4d

Please sign in to comment.