-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
52 lines (46 loc) · 1.77 KB
/
index.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
42
43
44
45
46
47
48
49
50
51
52
const { convertV1ToV2, convertV2ToV1 } = require('idyll-ast').converters;
const AST = require('idyll-ast/v1');
var getRepoInfo = require('git-repo-info');
var d3 = require("d3");
require("d3-time-format");
var remoteOriginUrl = require('remote-origin-url');
var parseTime = d3.timeParse("%Y-%m-%dT%H:%M:%S.%LZ");
var formatTime = d3.timeFormat("%B %e, %Y");
module.exports = (ast) => {
ast = convertV2ToV1(ast);
var url = remoteOriginUrl.sync();
var info = getRepoInfo();
let elements = [];
elements.push(AST.createNode('span', { id: 'revisionTitle' }, ['Revision: ']));
let commitUrl = '';
let commitText = '';
if (info.commitMessage !== null) {
commitText = info.commitMessage;
}
else if (info.abbreviatedSha !== null) {
commitText = info.abbreviatedSha;
}
if (url === undefined) {
url = '';
}
else {
url = url.split('.git')[0];
if (!url.includes("http") && url.includes("git@")) {
url = "https://" + url.split('git@')[1].replace(':', '/');
}
commitUrl = url + '/commit/' + info.sha;
}
elements.push(AST.createNode('a', { href: commitUrl, id: 'revisionMessage' }, [commitText]));
if (info.committer !== null) {
let author = info.committer.split('<')[0];
elements.push(AST.createNode('span', { id: 'revisionAuthor' }, [' by ' + author]));
}
if (info.committerDate !== null) {
elements.push(AST.createNode('span', { id: 'revisionDate' }, [' on ' + formatTime(parseTime(info.committerDate))]));
}
let revisionDiv = AST.createNode('div', { id: 'revisionDiv' }, elements);
let ASTwithRevision = AST.modifyNodesByName(ast, 'Revision', (node) => {
return revisionDiv;
});
return convertV1ToV2(ASTwithRevision);
};