Skip to content

Commit b854bb5

Browse files
authored
Merge pull request #6 from ndu2/stats_warnings
changed: print warnings if stats do not match notes sum of times. thi…
2 parents fec31d3 + 55610aa commit b854bb5

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed

src/models/hasTimes.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class hasTimes extends Base {
1515
constructor(config) {
1616
super(config);
1717
this.times = [];
18+
this.timesWarnings = [];
1819
}
1920

2021
/**
@@ -58,6 +59,7 @@ class hasTimes extends Base {
5859
*/
5960
getTimes() {
6061
let times = [],
62+
timesWarnings = [],
6163
timeSpent = 0,
6264
totalTimeSpent = 0,
6365
timeUsers = {},
@@ -127,18 +129,22 @@ class hasTimes extends Base {
127129
!(created.isSameOrAfter(moment(this.config.get('from'))) && created.isSameOrBefore(moment(this.config.get('to'))))
128130
) return resolve();
129131

132+
// warn about difference, but do not correct as gitlab API
133+
// stats forget the times after an issue is moved to another project.
130134
let difference = this.data.time_stats.total_time_spent - totalTimeSpent,
131135
note = Object.assign({noteable_type: this._typeSingular}, this.data);
132-
133-
times.unshift(new Time(Time.toHumanReadable(difference, this.config.get('hoursPerDay')), null, note, this, this.config));
134-
136+
note.timeWarning = {};
137+
note.timeWarning['stats'] = this.data.time_stats.total_time_spent;
138+
note.timeWarning['notes'] = totalTimeSpent;
139+
timesWarnings.push(new Time(Time.toHumanReadable(difference, this.config.get('hoursPerDay')), null, note, this, this.config));
135140
resolve();
136141
}));
137142

138143
promise.then(() => {
139144
_.each(timeUsers, (time, name) => this[`time_${name}`] = Time.toHumanReadable(time, this.config.get('hoursPerDay'), timeFormat));
140145
this.timeSpent = timeSpent;
141-
this.times = times
146+
this.times = times;
147+
this.timesWarnings = timesWarnings;
142148
});
143149

144150
return promise;

src/output/base.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ class base {
3838
this.write(this.formats.headline(string));
3939
}
4040

41+
/**
42+
* print a headline for warnings
43+
* @param string
44+
*/
45+
warningHeadline(string) {
46+
if (this.config.get('noWarnings')) return;
47+
this.headline(string);
48+
}
4149
/**
4250
* print a warning
4351
* @param string
@@ -104,6 +112,7 @@ class base {
104112
let users = {};
105113
let projects = {};
106114
let times = [];
115+
let timesWarnings = [];
107116

108117
let spentFreeLabels = this.config.get('freeLabels');
109118
if(undefined === spentFreeLabels) {
@@ -132,6 +141,7 @@ class base {
132141
}
133142
times.push(time);
134143
});
144+
issue.timesWarnings.forEach(warning => timesWarnings.push(warning));
135145

136146
totalEstimate += parseInt(issue.stats.time_estimate);
137147
totalSpent += parseInt(issue.stats.total_time_spent);
@@ -164,6 +174,7 @@ class base {
164174
this.spent = spent;
165175
this.spentFree = spentFree;
166176
this.totalSpent = totalSpent;
177+
this.timesWarnings = timesWarnings;
167178
}
168179

169180
/**

src/output/invoice.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,21 @@ ${closing}
8989
<h1 style="page-break-before: always;"><br/><br/>Stundenrapport</h1>`;
9090

9191
this.headline('Total');
92-
this.write(stats.substr(1));
92+
//this.write(stats.substr(1));
93+
this.write(this.config.toHumanReadable(this.spent, 'stats'));
94+
this.write(this.config.toHumanReadable(this.spentFree, 'statsFree'));
95+
96+
// warnings
97+
let warnings = '';
98+
99+
this.timesWarnings.forEach( warning => {
100+
let stats = this.config.toHumanReadable(warning.data.timeWarning.stats, 'stats');
101+
let notes = this.config.toHumanReadable(warning.data.timeWarning.notes, 'stats');
102+
warnings += `\n* ${warning.data.iid} ${warning.data.title}: Difference between stats and notes of ${warning.time}.`;
103+
warnings += `<br/>Stats: ${stats}, Notes: ${notes}`
104+
});
105+
this.warningHeadline('Warnings');
106+
this.warning(warnings+'\n');
93107
}
94108

95109
makeIssues() {

0 commit comments

Comments
 (0)