diff --git a/src/gtt-status.js b/src/gtt-status.js index 6367a38..0f64e31 100755 --- a/src/gtt-status.js +++ b/src/gtt-status.js @@ -8,6 +8,7 @@ const Tasks = require('./include/tasks'); program .option('--verbose', 'show verbose output') + .option('-s', 'short output') .parse(process.argv); Cli.verbose = program.opts().verbose; @@ -18,10 +19,17 @@ let config = new Config(__dirname), tasks.status() .then(frames => { if (frames.length === 0) { - console.log('No projects are started right now.'); + if (program.opts().s) { + console.log('gtt idle '); + }else { + console.log('No projects are started right now.'); + } return; } - - frames.forEach(frame => console.log(`Project ${frame.project.magenta} ${frame.resource.type.blue} ${('#' + frame.resource.id).blue} ${frame.note?frame.note:''} is running, started ${moment(frame.start).fromNow().green} (id: ${frame.id})`)); + if (program.opts().s) { + frames.forEach(frame => console.log(`${frame.project.magenta} ${frame.resource.type.blue} ${('#' + frame.resource.id).blue} ${moment(frame.start).fromNow().green} (id: ${frame.id})`)); + } else { + frames.forEach(frame => console.log(`Project ${frame.project.magenta} ${frame.resource.type.blue} ${('#' + frame.resource.id).blue} ${frame.note?frame.note:''} is running, started ${moment(frame.start).fromNow().green} (id: ${frame.id})`)); + } }) .catch(error => Cli.error('Could not read frames.', error)); \ No newline at end of file diff --git a/src/gtt-sync.js b/src/gtt-sync.js index d70de13..e4ccaef 100755 --- a/src/gtt-sync.js +++ b/src/gtt-sync.js @@ -34,7 +34,7 @@ tasks.syncInit() }) .then(() => { Cli.bar(`${Cli.process} Processing issues & merge requests...`, tasks.sync.frames.length); - return tasks.syncNotes(Cli.advance); + return tasks.syncDetails(Cli.advance); }) .then(() => { Cli.bar(`${Cli.update} Syncing time records...`, tasks.sync.frames.length); diff --git a/src/include/tasks.js b/src/include/tasks.js index 9a63816..c8301d8 100755 --- a/src/include/tasks.js +++ b/src/include/tasks.js @@ -43,26 +43,29 @@ class tasks { * @returns {Promise} */ syncResolve(callback) { - this.sync.resources = { - issue: {}, - merge_request: {} - }; - + this.sync.resources = {} + // resolve issues and merge requests return this.sync.frames.forEach((frame, done) => { let project = frame.project, type = frame.resource.type, - id = frame.resource.id, - resource = this.sync.resources[type][id]; + id = frame.resource.id; + if(!(project in this.sync.resources)) + { + this.sync.resources[project]= + { + issue: {}, + merge_request: {} + }; + } - if (resource !== undefined && resource.data.project_id) + if(id in this.sync.resources[project][type]) { return done(); - - this.sync.resources[type][id] = new classes[type](this.config, {}); - this.sync.resources[type][id] + } + this.sync.resources[project][type][id] = new classes[type](this.config, {}); + this.sync.resources[project][type][id] .make(project, id, frame.resource.new) .then(() => { - frame.title = this.sync.resources[type][id].data.title; if (callback) callback(); done(); }) @@ -71,27 +74,18 @@ class tasks { } /** - * Get notes for all frames. + * sync details to frames. */ - syncNotes(callback) { + syncDetails(callback) { return this.sync.frames.forEach((frame, done) => { let project = frame.project, type = frame.resource.type, - id = frame.resource.id, - notes; - - if ((notes = this.sync.resources[type][id].notes) && notes.length > 0) { - if (callback) callback(); - return done(); + id = frame.resource.id; + + if(id in this.sync.resources[project][type]) { + frame.title = this.sync.resources[project][type][id].data.title; } - - this.sync.resources[type][id] - .getNotes() - .then(() => { - if (callback) callback(); - done(); - }) - .catch(error => done(`Could not get notes from ${type} ${id} on "${project}"`)); + return done(); }); } @@ -116,13 +110,14 @@ class tasks { _addTime(frame, time) { return new Promise((resolve, reject) => { - let resource = this.sync.resources[frame.resource.type][frame.resource.id]; + let resource = this.sync.resources[frame.project][frame.resource.type][frame.resource.id]; resource.createTime(Math.ceil(time), frame._stop, frame.note) .then(() => resource.getNotes()) .then(() => { if (frame.resource.new) { delete frame.resource.new; + frame.resource.title = frame.resource.id; frame.resource.id = resource.data.iid; } diff --git a/src/models/hasTimes.js b/src/models/hasTimes.js index 0eb1d86..8a1c705 100755 --- a/src/models/hasTimes.js +++ b/src/models/hasTimes.js @@ -27,7 +27,7 @@ class hasTimes extends Base { * @returns {*} */ createTime(time, created_at, note) { - if(note === null) { + if(note === null || note === undefined) { note = ''; } else {