1 | const path = require('path');
|
2 | const findGit = require('./git/find_git');
|
3 | const getGithubURLPrefix = require('./git/url_prefix');
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | module.exports = function(comment) {
|
13 | const repoPath = findGit(comment.context.file);
|
14 | const root = repoPath ? path.dirname(repoPath) : '.';
|
15 | const urlPrefix = getGithubURLPrefix(root);
|
16 | const fileRelativePath = comment.context.file
|
17 | .replace(root + path.sep, '')
|
18 | .split(path.sep)
|
19 | .join('/');
|
20 |
|
21 | if (urlPrefix) {
|
22 | let startLine;
|
23 | let endLine;
|
24 |
|
25 | if (comment.kind == 'typedef') {
|
26 | startLine = comment.loc.start.line;
|
27 | endLine = comment.loc.end.line;
|
28 | } else {
|
29 | startLine = comment.context.loc.start.line;
|
30 | endLine = comment.context.loc.end.line;
|
31 | }
|
32 |
|
33 | comment.context.github = {
|
34 | url:
|
35 | urlPrefix + fileRelativePath + '#L' + startLine + '-' + 'L' + endLine,
|
36 | path: fileRelativePath
|
37 | };
|
38 | }
|
39 | return comment;
|
40 | };
|