mirror of
https://github.com/IonicaBizau/git-stats.git
synced 2024-12-22 21:32:10 +01:00
Added the globalActivity function
This commit is contained in:
parent
a69c63aa22
commit
ca16554bf1
1 changed files with 40 additions and 1 deletions
41
lib/index.js
41
lib/index.js
|
@ -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
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in a new issue