Skip to content
This repository was archived by the owner on May 22, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/gtt-resume.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const program = require('commander');
const colors = require('colors');
const moment = require('moment');

const Config = require('./include/file-config');
const Cli = require('./include/cli');
const Tasks = require('./include/tasks');

program
.option('--verbose', 'show verbose output')
.parse(process.argv);

Cli.verbose = program.verbose;

let config = new Config(process.cwd()),
tasks = new Tasks(config);


tasks.resume()
.then(frame => console.log(`Starting project ${config.get('project').magenta} ${frame.resource.type.blue} ${('#' + frame.resource.id).blue} at ${moment().format('HH:mm').green}`))
.catch(error => Cli.error(error));
1 change: 1 addition & 0 deletions src/gtt.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ program
.command('create [project] [title]', 'start monitoring time for the given project and create a new issue or merge request with the given title')
.command('status', 'shows if time monitoring is running')
.command('stop', 'stop monitoring time')
.command('resume', 'resume monitoring time for last stopped record')
.command('cancel', 'cancel and discard active monitoring time')
.command('log', 'log recorded time records')
.command('sync', 'sync local time records to GitLab')
Expand Down
23 changes: 23 additions & 0 deletions src/include/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,29 @@ class tasks {
});
}

/**
*
* @returns {Promise}
*/
resume() {
return new Promise((resolve, reject) => {
let project;
let frames = new FrameCollection(this.config).frames
if (project = this.config.get('project')) {
frames = frames.filter(frame => frame.project == project)
}
const last = frames.filter(frame => frame.stop)
.sort((a, b) => -1 * a.stop.localeCompare(b.stop))[0]
if (last) {
this.start(last.project, last.resource.type, last.resource.id)
.then(frames => resolve(frames))
.catch(error => reject(error))
} else {
reject("No recent entry found for project")
}
});
}

/**
*
* @param project
Expand Down