Skip to content
This repository was archived by the owner on May 22, 2025. It is now read-only.

Commit 02d1502

Browse files
committed
Merge branch 'zealot128-os-gtt-resume'
2 parents 8c835d7 + 9a55e39 commit 02d1502

File tree

5 files changed

+58
-9
lines changed

5 files changed

+58
-9
lines changed

readme.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -782,12 +782,6 @@ report.mergeRequests.forEach(mergeRequest => {
782782
It can include times outside the queried time frame. `spent` on the other hand
783783
is the total amount of time spent in the given time frame.
784784

785-
#### Why 'total spent' and 'spent' are showing different amounts.
786-
787-
gtt can only track time records from notes/comments. If you start your
788-
issue or merge request with `/spend [time]` in its description, gtt won't
789-
take it into consideration (for now).
790-
791785
## contributing
792786

793787
I would love to integrate unit testing in this project, but unfortunately my knowledge of

src/gtt-resume.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const program = require('commander');
2+
const colors = require('colors');
3+
const moment = require('moment');
4+
5+
const Config = require('./include/file-config');
6+
const Cli = require('./include/cli');
7+
const Tasks = require('./include/tasks');
8+
9+
program
10+
.arguments('[project]')
11+
.option('--verbose', 'show verbose output')
12+
.parse(process.argv);
13+
14+
Cli.verbose = program.verbose;
15+
16+
let config = new Config(process.cwd()).set('project', program.args[0]),
17+
tasks = new Tasks(config);
18+
19+
if (!config.get('project'))
20+
Cli.error('No project set');
21+
22+
tasks.resume()
23+
.then(frame => console.log(`Starting project ${config.get('project').magenta} ${frame.resource.type.blue} ${('#' + frame.resource.id).blue} at ${moment().format('HH:mm').green}`))
24+
.catch(error => Cli.error(error));

src/gtt.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ program
99
.command('create [project] [title]', 'start monitoring time for the given project and create a new issue or merge request with the given title')
1010
.command('status', 'shows if time monitoring is running')
1111
.command('stop', 'stop monitoring time')
12+
.command('resume [project]', 'resume monitoring time for last stopped record')
1213
.command('cancel', 'cancel and discard active monitoring time')
1314
.command('log', 'log recorded time records')
1415
.command('sync', 'sync local time records to GitLab')

src/include/tasks.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class tasks {
115115
resource.createTime(Math.ceil(time))
116116
.then(() => resource.getNotes())
117117
.then(() => {
118-
if(frame.resource.new) {
118+
if (frame.resource.new) {
119119
delete frame.resource.new;
120120
frame.resource.id = resource.data.iid;
121121
}
@@ -174,6 +174,28 @@ class tasks {
174174
});
175175
}
176176

177+
/**
178+
*
179+
* @returns {Promise}
180+
*/
181+
resume() {
182+
return new Promise((resolve, reject) => {
183+
let project = this.config.get('project'),
184+
frames = new FrameCollection(this.config);
185+
186+
if (!project) return reject("No project set.");
187+
188+
frames
189+
.filter(frame => frame.project === project)
190+
.sort((a, b) => moment(a.stop).isBefore(moment(b.stop)) ? 1 : -1);
191+
192+
let last = frames.frames[0];
193+
this.start(last.project, last.resource.type, last.resource.id)
194+
.then(frame => resolve(frame))
195+
.catch(error => reject(error));
196+
});
197+
}
198+
177199
/**
178200
*
179201
* @param project

src/models/frameCollection.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ class frameCollection extends Base {
1818
.filter(frame => frame);
1919
}
2020

21+
sort(func) {
22+
this.frames.sort(func);
23+
24+
return this;
25+
}
26+
2127
filter(func) {
2228
let arr = [];
2329

@@ -29,9 +35,11 @@ class frameCollection extends Base {
2935
if (func(frame)) {
3036
arr.push(frame);
3137
}
32-
33-
this.frames = arr;
3438
});
39+
40+
this.frames = arr;
41+
42+
return this;
3543
}
3644

3745
forEach(iterator) {

0 commit comments

Comments
 (0)