mirror of
https://github.com/IonicaBizau/git-stats.git
synced 2025-01-11 14:01:54 +01:00
Improved the removeCommit function
The date field is not mandatory anymore.
This commit is contained in:
parent
e8b643a718
commit
9c211d67af
1 changed files with 15 additions and 9 deletions
24
lib/index.js
24
lib/index.js
|
@ -14,6 +14,7 @@ var Ul = require("ul")
|
||||||
, Typpy = require("typpy")
|
, Typpy = require("typpy")
|
||||||
, Exec = ChildProcess.exec
|
, Exec = ChildProcess.exec
|
||||||
, Spawn = ChildProcess.spawn
|
, Spawn = ChildProcess.spawn
|
||||||
|
, IterateObject = require("iterate-object")
|
||||||
;
|
;
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
|
@ -209,7 +210,7 @@ GitStats.prototype.record = function (data, callback) {
|
||||||
* @function
|
* @function
|
||||||
* @param {Object} data The commit data containing:
|
* @param {Object} data The commit data containing:
|
||||||
*
|
*
|
||||||
* - `date` (String|Date): The date object or a string in a format that can be parsed.
|
* - `date` (String|Date): The date object or a string in a format that can be parsed. If not provided, the hash object will be searched in all dates.
|
||||||
* - `hash` (String): The commit hash.
|
* - `hash` (String): The commit hash.
|
||||||
* - `_data` (Object): If this field is provided, it should be the content of the git-stats data file as object. It will be modified in-memory and then returned.
|
* - `_data` (Object): If this field is provided, it should be the content of the git-stats data file as object. It will be modified in-memory and then returned.
|
||||||
* - `save` (Boolean): If `false`, the result will *not* be saved in the file.
|
* - `save` (Boolean): If `false`, the result will *not* be saved in the file.
|
||||||
|
@ -230,8 +231,7 @@ GitStats.prototype.removeCommit = function (data, callback) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!/^moment|date$/.test(Typpy(data.date))) {
|
if (!/^moment|date$/.test(Typpy(data.date))) {
|
||||||
callback(new Error("The date field should be a string or a date object."));
|
data.date = null;
|
||||||
return GitStats;
|
|
||||||
} else if (Typpy(data.date, Date)) {
|
} else if (Typpy(data.date, Date)) {
|
||||||
data.date = Moment(data.date);
|
data.date = Moment(data.date);
|
||||||
}
|
}
|
||||||
|
@ -244,13 +244,19 @@ GitStats.prototype.removeCommit = function (data, callback) {
|
||||||
function modify (err, stats) {
|
function modify (err, stats) {
|
||||||
|
|
||||||
if (err) { return callback(err); }
|
if (err) { return callback(err); }
|
||||||
|
if (!data.date) {
|
||||||
|
debugger
|
||||||
|
IterateObject(stats.commits, function (todayObj) {
|
||||||
|
delete todayObj[data.hash];
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
var commits = stats.commits
|
||||||
|
, day = data.date.format(DATE_FORMAT)
|
||||||
|
, today = commits[day] = Object(commits[day])
|
||||||
|
;
|
||||||
|
|
||||||
var commits = stats.commits
|
delete today[data.hash];
|
||||||
, day = data.date.format(DATE_FORMAT)
|
}
|
||||||
, today = commits[day] = Object(commits[day])
|
|
||||||
;
|
|
||||||
|
|
||||||
delete today[data.hash];
|
|
||||||
|
|
||||||
if (data.save === false) {
|
if (data.save === false) {
|
||||||
callback(null, stats);
|
callback(null, stats);
|
||||||
|
|
Loading…
Reference in a new issue