mirror of
https://github.com/IonicaBizau/git-stats.git
synced 2025-01-03 10:22:11 +01:00
Parse the commits
This commit is contained in:
parent
02766d4834
commit
a5cb4d6a93
1 changed files with 38 additions and 15 deletions
27
lib/index.js
27
lib/index.js
|
@ -9,7 +9,10 @@ var Ul = require("ul")
|
||||||
, CliPie = require("cli-pie")
|
, CliPie = require("cli-pie")
|
||||||
, CliGhCal = require("cli-gh-cal")
|
, CliGhCal = require("cli-gh-cal")
|
||||||
, GitLogParser = require("gitlog-parser").parse
|
, GitLogParser = require("gitlog-parser").parse
|
||||||
, Exec = require("child_process").exec
|
, ChildProcess = require("child_process")
|
||||||
|
, Exec = ChildProcess.exec
|
||||||
|
, Spawn = ChildProcess.spawn
|
||||||
|
, ProgressBar = require("progress")
|
||||||
;
|
;
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
|
@ -367,15 +370,34 @@ GitStats.globalActivity = function (options, callback) {
|
||||||
var commits = {}
|
var commits = {}
|
||||||
, today = null
|
, today = null
|
||||||
, cal = []
|
, cal = []
|
||||||
|
, isFinished = false
|
||||||
|
, timeout = null
|
||||||
|
, progress = null
|
||||||
|
, complete = 0
|
||||||
;
|
;
|
||||||
|
|
||||||
GitLogParser(Exec("git log", { cwd: options.repo }).stdout).on("commit", function(commit) {
|
Exec("git rev-list HEAD --count", { cwd: options.repo }, function (err, commitCount) {
|
||||||
|
if (err) { return callback(err); }
|
||||||
|
commitCount = parseInt(commitCount);
|
||||||
|
setTimeout(function () {
|
||||||
|
if (isFinished) { return; }
|
||||||
|
progress = new ProgressBar(":bar", { total: commitCount - complete });
|
||||||
|
}, 10);
|
||||||
|
// TODO Take only the commits from the provided range (start - end)
|
||||||
|
GitLogParser(Spawn("git", ["log"], { cwd: options.repo }).stdout).on("commit", function(commit) {
|
||||||
today = Moment(commit.date).format(DATE_FORMAT);
|
today = Moment(commit.date).format(DATE_FORMAT);
|
||||||
commits[today] = commits[today] || 0;
|
commits[today] = commits[today] || 0;
|
||||||
++commits[today];
|
++commits[today];
|
||||||
|
++complete;
|
||||||
|
if (progress) {
|
||||||
|
progress.tick();
|
||||||
|
}
|
||||||
}).on("error", function (err) {
|
}).on("error", function (err) {
|
||||||
|
clearTimeout(timeout);
|
||||||
callback(err);
|
callback(err);
|
||||||
}).on("finish", function () {
|
}).on("finish", function () {
|
||||||
|
clearTimeout(timeout);
|
||||||
|
isFinished = true;
|
||||||
Object.keys(commits).forEach(function (c) {
|
Object.keys(commits).forEach(function (c) {
|
||||||
cal.push([c, commits[c]])
|
cal.push([c, commits[c]])
|
||||||
});
|
});
|
||||||
|
@ -385,4 +407,5 @@ GitStats.globalActivity = function (options, callback) {
|
||||||
, end: options.end
|
, end: options.end
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue