-
Notifications
You must be signed in to change notification settings - Fork 484
/
Copy pathgithub.js
30 lines (27 loc) · 866 Bytes
/
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
'use strict';
var path = require('path');
var findGit = require('../lib/git/find_git');
var getGithubURLPrefix = require('../lib/git/url_prefix');
/**
* Attempts to link code to its place on GitHub.
*
* @name linkGitHub
* @param {Object} comment parsed comment
* @return {Object} comment with github inferred
*/
module.exports = function (comment) {
var repoPath = findGit(comment.context.file);
var root = repoPath ? path.dirname(repoPath) : '.';
var urlPrefix = getGithubURLPrefix(root);
var fileRelativePath = comment.context.file.replace(root + path.sep, '')
.split(path.sep)
.join('/');
if (urlPrefix) {
comment.context.path = fileRelativePath;
comment.context.github = urlPrefix +
fileRelativePath +
'#L' + comment.context.loc.start.line + '-' +
'L' + comment.context.loc.end.line;
}
return comment;
};