Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
New command: gtt list
* First iteration with project filter, scope (my/all), state (opened/closed) toggle
  • Loading branch information
zealot128 committed Oct 11, 2017
commit fe39396138fdfb5b078bec4591e9a2edcf70512c
2 changes: 1 addition & 1 deletion src/gtt-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ if (program.local) {
config.assertLocalConfig();
}

Fs.open(program.local ? config.local : config.global);
Fs.open(program.local ? config.local : config.global);
39 changes: 39 additions & 0 deletions src/gtt-list.js
Original file line number Diff line number Diff line change
@@ -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));

2 changes: 1 addition & 1 deletion src/gtt-log.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ tasks.log()
});
}
)
.catch(error => Cli.error(error));
.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 @@ -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')
Expand Down
7 changes: 6 additions & 1 deletion src/include/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -260,4 +265,4 @@ class tasks {
}
}

module.exports = tasks;
module.exports = tasks;
19 changes: 18 additions & 1 deletion src/models/issue.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -107,4 +124,4 @@ class issue extends hasTimes {
}
}

module.exports = issue;
module.exports = issue;