forked from twitter/opensource-website
-
Notifications
You must be signed in to change notification settings - Fork 5
/
getCommitsData.js
executable file
·70 lines (59 loc) · 2.11 KB
/
getCommitsData.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
var fs = require('fs');
var path = require('path');
var util = require('util');
var spawn = require('child_process').spawn;
var jsonSanitizer = require('./modules/jsonSanitizer');
var commitsToJson = require('./modules/commitsToJson');
var eKnights = require('./modules/repositories').repositories;
var numStat = require('./modules/numStat');
var colors = require('colors');
/**
* @description write File
* @param {type} commits
* @param {Repository} repo
* @returns {void}
*/
function writeFile(commits, repo) {
var data = new Array();
function addSt(i) {
if (i === 0) {
data.sort(function(a, b) {
// Turn strings into dates, and then subtract them to get a value that is either negative, positive, or zero.
return new Date(b.date) - new Date(a.date);
});
fs.writeFile(outputPath + repo.getFolderName() + ".json", JSON.stringify(data), function(err) {
});
return;
}
var result = '';
var args = new Array(
'--git-dir=' + repo.getDotGitFolder()
, 'diff'
, '--numstat'
, commits[i].commit
, commits[i - 1].commit
);
var process = spawn('git', args);
process.stdout.on('data', function(data) { // Store stdout in result
result += data.toString();
});
process.on('exit', function(code) { // When exit run the callback with the results.
// console.log(commits[i - 1].commit + ' ' + commits[i].commit);
var ns = numStat.parseNumStat(result);
ns.sha = commits[i].commit;
ns.body = commits[i].body;
ns.date = commits[i].date;
data.push(ns);
addSt(--i);
});
process.stderr.on('data', function(data) {
var buff = new Buffer(data);
//console.log(buff.toString('utf8').red);
});
}
addSt(commits.length - 1);
}
var outputPath = './';
for (var i = 0; i < 1; i++) {
commitsToJson.commitsArray(eKnights[i].getMainRepository(), writeFile);
}