diff --git a/src/gtt-config.js b/src/gtt-config.js index db5d245..06375b1 100755 --- a/src/gtt-config.js +++ b/src/gtt-config.js @@ -13,4 +13,4 @@ if (program.local) { config.assertLocalConfig(); } -Fs.open(program.local ? config.local : config.global); \ No newline at end of file +Fs.open(program.local ? config.local : config.global); diff --git a/src/gtt-list.js b/src/gtt-list.js new file mode 100755 index 0000000..085cc2f --- /dev/null +++ b/src/gtt-list.js @@ -0,0 +1,39 @@ +const program = require('commander'); +const colors = require('colors'); +const moment = require('moment'); +const Table = require('cli-table'); + + +const Config = require('./include/file-config'); +const Cli = require('./include/cli'); +const Tasks = require('./include/tasks'); + +program + .arguments('[project]') + .option('--verbose', 'show verbose output') + .option('-c, --closed', 'show closed issues (instead of opened only)') + .option('--my', 'show only issues assigned to me') + .parse(process.argv); + +Cli.verbose = program.verbose; + +let config = new Config(process.cwd()), + tasks = new Tasks(config), + type = program.type ? program.type : 'issue', + project = program.args[0]; + +tasks.list(project, program.closed ? 'closed' : 'opened', program.my) + .then(issues => { + let table = new Table({ + style : {compact : true, 'padding-left' : 1} + }); + if (issues.length == 0) { + console.log("No issues found."); + } + issues.forEach(issue => { + table.push([issue.iid.toString().magenta, issue.title.green + "\n" + issue.data.web_url.gray, issue.state]) + }) + console.log(table.toString()); + }) + .catch(error => Cli.error(error)); + diff --git a/src/gtt-log.js b/src/gtt-log.js index cc7547c..101d25e 100755 --- a/src/gtt-log.js +++ b/src/gtt-log.js @@ -41,4 +41,4 @@ tasks.log() }); } ) - .catch(error => Cli.error(error)); \ No newline at end of file + .catch(error => Cli.error(error)); diff --git a/src/gtt.js b/src/gtt.js index 0dedde0..a1793b5 100755 --- a/src/gtt.js +++ b/src/gtt.js @@ -11,6 +11,7 @@ program .command('stop', 'stop monitoring time') .command('resume [project]', 'resume monitoring time for last stopped record') .command('cancel', 'cancel and discard active monitoring time') + .command('list [project]', 'list all open issues') .command('log', 'log recorded time records') .command('sync', 'sync local time records to GitLab') .command('edit [id]', 'edit time record by the given id') diff --git a/src/include/tasks.js b/src/include/tasks.js index 79a3b16..f2f7227 100755 --- a/src/include/tasks.js +++ b/src/include/tasks.js @@ -196,6 +196,11 @@ class tasks { }); } + list(project, state, my) { + this.config.set('project', project); + return (new classes['issue'](this.config, {})).list(this.config.get('project'), state, my); + } + /** * * @param project @@ -260,4 +265,4 @@ class tasks { } } -module.exports = tasks; \ No newline at end of file +module.exports = tasks; diff --git a/src/models/issue.js b/src/models/issue.js index ddf7c5c..0c4caad 100755 --- a/src/models/issue.js +++ b/src/models/issue.js @@ -29,6 +29,23 @@ class issue extends hasTimes { return promise; } + list(project, state, my) { + return new Promise((resolve, reject) => { + let promise; + const query = `scope=${my ? "assigned-to-me" : "all"}&state=${state}`; + if (project) { + promise = this.get(`projects/${encodeURIComponent(project)}/issues?${query}`); + } else { + promise = this.get(`issues/?${query}`); + } + promise.then(response => { + const issues = response.body.map(issue => new this.constructor(this.config, issue)) + resolve(issues) + }); + promise.catch(error => reject(error)) + }) + } + /* * properties */ @@ -107,4 +124,4 @@ class issue extends hasTimes { } } -module.exports = issue; \ No newline at end of file +module.exports = issue;