Skip to content

Commit 835855a

Browse files
committed
feat: support delete time spent
https://docs.gitlab.com/ee/user/project/time_tracking.html#delete-time-spent From GitLab 15.1, there is delete button.
1 parent 18582dc commit 835855a

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/models/hasTimes.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const Time = require('./time');
77
const regex = /added (.*) of time spent(?: at (.*))?/i;
88
const subRegex = /subtracted (.*) of time spent(?: at (.*))?/i;
99
const removeRegex = /Removed time spent/i;
10+
const delRegex = /deleted (.*) of spent time from (.*)/i;
1011

1112
/**
1213
* base model for models that have times
@@ -68,21 +69,26 @@ class hasTimes extends Base {
6869
});
6970

7071
let promise = this.parallel(this.notes, (note, done) => {
71-
let created = moment(note.created_at), match, subMatch;
72+
let created = moment(note.created_at), match, subMatch, delMatch;
7273

7374
if ( //
7475
// filter out user notes
7576
!note.system ||
7677
// filter out notes that are no time things
77-
!(match = regex.exec(note.body)) && !(subMatch = subRegex.exec(note.body)) && !removeRegex.exec(note.body)
78+
!(match = regex.exec(note.body)) && !(subMatch = subRegex.exec(note.body)) && !(delMatch = delRegex.exec(note.body)) && !removeRegex.exec(note.body)
7879
) return done();
7980

8081
// change created date when explicitly defined
8182
if(match && match[2]) created = moment(match[2]);
8283
if(subMatch && subMatch[2]) created = moment(subMatch[2]);
84+
if(delMatch && delMatch[2]) created = moment(delMatch[2]);
85+
86+
// collect minus items
87+
let minusFlag = subMatch | delMatch;
88+
let minusMatch = minusFlag ? subMatch ? subMatch[1] : delMatch ? delMatch[1] : 0 : 0;
8389

8490
// create a time string and a time object
85-
let timeString = match ? match[1] : (subMatch ? `-${subMatch[1]}` : `-${Time.toHumanReadable(timeSpent)}`);
91+
let timeString = match ? match[1] : (minusMatch ? `-${minusMatch}` : `-${Time.toHumanReadable(timeSpent)}`);
8692
let time = new Time(null, created, note, this, this.config);
8793
time.seconds = Time.parse(timeString, 8, 5, 4);
8894

0 commit comments

Comments
 (0)