Added the globalActivity function

This commit is contained in:
Ionică Bizău 2015-07-08 11:20:13 +03:00
parent a69c63aa22
commit ca16554bf1

View file

@ -8,6 +8,8 @@ var Ul = require("ul")
, IsThere = require("is-there") , IsThere = require("is-there")
, CliPie = require("cli-pie") , CliPie = require("cli-pie")
, CliGhCal = require("cli-gh-cal") , CliGhCal = require("cli-gh-cal")
, GitLogParser = require("gitlog-parser").parse
, Exec = require("child_process").exec
; ;
// Constants // Constants
@ -317,7 +319,7 @@ GitStats.authorsPie = function (options, callback) {
}); });
if (!IsThere(options.repo)) { if (!IsThere(options.repo)) {
return callback(new Error("Repository is missing.")); return callback(new Error("The repository folder doesn't exist."));
} }
var repo = new Gry(options.repo) var repo = new Gry(options.repo)
@ -347,3 +349,40 @@ GitStats.authorsPie = function (options, callback) {
callback(null, pie.toString()); callback(null, pie.toString());
}); });
}; };
GitStats.globalActivity = function (options, callback) {
if (typeof options === "string") {
options = {
repo: options
};
}
options.repo = Abs(options.repo);
if (!IsThere(options.repo)) {
return callback(new Error("The repository folder doesn't exist."));
}
var commits = {}
, today = null
, cal = []
;
GitLogParser(Exec("git log", { cwd: options.repo }).stdout).on("commit", function(commit) {
today = Moment(commit.date).format(DATE_FORMAT);
commits[today] = commits[today] || 0;
++commits[today];
}).on("error", function (err) {
callback(err);
}).on("finish", function () {
Object.keys(commits).forEach(function (c) {
cal.push([c, commits[c]])
});
callback(null, CliGhCal(cal, {
theme: options.theme
, start: options.start
, end: options.end
}));
});
};