Skip to content

Commit 748558e

Browse files
author
Andreas Müller
committed
Merge branch 'gtt-list' of https://github.com/zealot128-os/gitlab-time-tracker into zealot128-os-gtt-list
2 parents b854bb5 + fe39396 commit 748558e

File tree

5 files changed

+59
-2
lines changed

5 files changed

+59
-2
lines changed

src/gtt-config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ if (program.opts().local) {
1313
config.assertLocalConfig();
1414
}
1515

16-
Fs.open(program.opts().local ? config.local : config.global);
16+
Fs.open(program.opts().local ? config.local : config.global);

src/gtt-list.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const program = require('commander');
2+
const colors = require('colors');
3+
const moment = require('moment');
4+
const Table = require('cli-table');
5+
6+
7+
const Config = require('./include/file-config');
8+
const Cli = require('./include/cli');
9+
const Tasks = require('./include/tasks');
10+
11+
program
12+
.arguments('[project]')
13+
.option('--verbose', 'show verbose output')
14+
.option('-c, --closed', 'show closed issues (instead of opened only)')
15+
.option('--my', 'show only issues assigned to me')
16+
.parse(process.argv);
17+
18+
Cli.verbose = program.verbose;
19+
20+
let config = new Config(process.cwd()),
21+
tasks = new Tasks(config),
22+
type = program.type ? program.type : 'issue',
23+
project = program.args[0];
24+
25+
tasks.list(project, program.closed ? 'closed' : 'opened', program.my)
26+
.then(issues => {
27+
let table = new Table({
28+
style : {compact : true, 'padding-left' : 1}
29+
});
30+
if (issues.length == 0) {
31+
console.log("No issues found.");
32+
}
33+
issues.forEach(issue => {
34+
table.push([issue.iid.toString().magenta, issue.title.green + "\n" + issue.data.web_url.gray, issue.state])
35+
})
36+
console.log(table.toString());
37+
})
38+
.catch(error => Cli.error(error));
39+

src/gtt-log.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ tasks.log()
3939
});
4040
}
4141
)
42-
.catch(error => Cli.error(error));
42+
.catch(error => Cli.error(error));

src/gtt.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ program
1212
.command('stop', 'stop monitoring time')
1313
.command('resume [project]', 'resume monitoring time for last stopped record')
1414
.command('cancel', 'cancel and discard active monitoring time')
15+
.command('list [project]', 'list all open issues')
1516
.command('log', 'log recorded time records')
1617
.command('sync', 'sync local time records to GitLab')
1718
.command('edit [id]', 'edit time record by the given id')

src/models/issue.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,23 @@ class issue extends hasTimes {
2929
return promise;
3030
}
3131

32+
list(project, state, my) {
33+
return new Promise((resolve, reject) => {
34+
let promise;
35+
const query = `scope=${my ? "assigned-to-me" : "all"}&state=${state}`;
36+
if (project) {
37+
promise = this.get(`projects/${encodeURIComponent(project)}/issues?${query}`);
38+
} else {
39+
promise = this.get(`issues/?${query}`);
40+
}
41+
promise.then(response => {
42+
const issues = response.body.map(issue => new this.constructor(this.config, issue))
43+
resolve(issues)
44+
});
45+
promise.catch(error => reject(error))
46+
})
47+
}
48+
3249
/*
3350
* properties
3451
*/

0 commit comments

Comments
 (0)