forked from qltysh-archive/javascript-test-reporter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit_info.js
More file actions
52 lines (46 loc) · 1.33 KB
/
git_info.js
File metadata and controls
52 lines (46 loc) · 1.33 KB
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
var crypto = require('crypto');
var childProcess = require('child_process');
module.exports = {
head: function(cb) {
childProcess.exec("git log -1 --pretty=format:%H", function (error, stdout, stderr) {
return cb(error, stdout);
});
},
committedAt: function(cb) {
childProcess.exec("git log -1 --pretty=format:%ct", function (error, stdout, stderr) {
var result = null;
var timestamp = null;
if (stdout) {
timestamp = parseInt(stdout, 10);
if (!isNaN(timestamp) && timestamp !== 0) {
result = timestamp;
}
}
return cb(error, result);
});
},
branch: function(cb) {
childProcess.exec("git branch", function (error, stdout, stderr) {
var returnBranch = null;
if (stdout) {
var branches = stdout.split("\n");
branches.forEach(function(val) {
if(val.charAt(0) === "*") {
returnBranch = val;
}
});
if (returnBranch) {
returnBranch = returnBranch.replace("* ", "");
}
}
return cb(error, returnBranch);
});
},
calculateBlobId: function(content) {
var header = 'blob ' + content.length + '\0';
var store = header + content;
var shasum = crypto.createHash('sha1');
shasum.update(store);
return shasum.digest("hex");
}
};