-
Notifications
You must be signed in to change notification settings - Fork 486
/
Copy pathgithub.js
41 lines (35 loc) · 1.02 KB
/
github.js
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
32
33
34
35
36
37
38
39
40
41
const path = require('path');
const findGit = require('./git/find_git');
const getGithubURLPrefix = require('./git/url_prefix');
/**
* Attempts to link code to its place on GitHub.
*
* @name linkGitHub
* @param {Object} comment parsed comment
* @returns {Object} comment with github inferred
*/
module.exports = function(comment) {
const paths = findGit(comment.context.file);
const urlPrefix = paths && getGithubURLPrefix(paths);
if (urlPrefix) {
const fileRelativePath = comment.context.file
.replace(paths.root + path.sep, '')
.split(path.sep)
.join('/');
let startLine;
let endLine;
if (comment.kind == 'typedef') {
startLine = comment.loc.start.line;
endLine = comment.loc.end.line;
} else {
startLine = comment.context.loc.start.line;
endLine = comment.context.loc.end.line;
}
comment.context.github = {
url:
urlPrefix + fileRelativePath + '#L' + startLine + '-' + 'L' + endLine,
path: fileRelativePath
};
}
return comment;
};