Skip to content

Commit 715569a

Browse files
author
Andreas Müller
committed
support new gitlab version with can "delete" time notes
1 parent 0042573 commit 715569a

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

src/models/hasTimes.js

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const Time = require('./time');
66

77
const regex = /added (.*) of time spent(?: at (.*))?/i;
88
const subRegex = /subtracted (.*) of time spent(?: at (.*))?/i;
9+
const delRegex = /deleted (.*) of spent time(?: from (.*))?/i;
910
const removeRegex = /Removed time spent/i;
1011

1112
/**
@@ -72,23 +73,43 @@ class hasTimes extends Base {
7273
});
7374

7475
let promise = this.parallel(this.notes, (note, done) => {
75-
let created = moment(note.created_at), match, subMatch;
76+
let created = moment(note.created_at), match, subMatch, delMatch;
7677

7778
if ( //
7879
// filter out user notes
7980
!note.system ||
8081
// filter out notes that are no time things
81-
!(match = regex.exec(note.body)) && !(subMatch = subRegex.exec(note.body)) && !removeRegex.exec(note.body)
82+
!(match = regex.exec(note.body)) && !(subMatch = subRegex.exec(note.body)) && !removeRegex.exec(note.body) && !(delMatch = delRegex.exec(note.body))
8283
) return done();
8384

8485
// change created date when explicitly defined
8586
if(match && match[2]) created = moment(match[2]);
8687
if(subMatch && subMatch[2]) created = moment(subMatch[2]);
88+
if(delMatch && delMatch[2]) created = moment(delMatch[2]);
8789

8890
// create a time string and a time object
89-
let timeString = match ? match[1] : (subMatch ? `-${subMatch[1]}` : `-${Time.toHumanReadable(timeSpent)}`);
91+
let timeString = null;
92+
let multiplier = 1;
93+
if(match) {
94+
timeString = match[1];
95+
}
96+
else if(subMatch) {
97+
timeString = subMatch[1];
98+
multiplier = -1;
99+
}
100+
else if(delMatch){
101+
timeString = delMatch[1];
102+
multiplier = -1;;
103+
}
104+
else {
105+
// Removed time spent -> remove all
106+
timeString = Time.toHumanReadable(timeSpent);
107+
multiplier = -1;
108+
}
109+
90110
let time = new Time(null, created, note, this, this.config);
91-
time.seconds = Time.parse(timeString, 8, 5, 4);
111+
time.seconds = Time.parse(timeString, 8, 5, 4) * multiplier;
112+
92113

93114
// add to total time spent
94115
totalTimeSpent += time.seconds;

0 commit comments

Comments
 (0)