Skip to content

Commit 4a04ae9

Browse files
author
Wolfgang Wohanka
committed
gtt List von Stefan @zealot128
1 parent 6cf60b8 commit 4a04ae9

File tree

6 files changed

+88
-1
lines changed

6 files changed

+88
-1
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/gtt-list.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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));

src/gtt.js

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

src/include/tasks.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,11 @@ class tasks {
196196
});
197197
}
198198

199+
list(project, state, my) {
200+
this.config.set('project', project);
201+
return (new classes['issue'](this.config, {})).list(this.config.get('project'), state, my);
202+
}
203+
199204
/**
200205
*
201206
* @param project

src/models/branch.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const _ = require('underscore');
2+
const Base = require('./base');
3+
4+
/**
5+
* branch model
6+
*/
7+
class branch extends Base {
8+
constructor(config) {
9+
super(config);
10+
}
11+
12+
make(project, id) {
13+
let promise;
14+
console.log(project);
15+
16+
promise = this.post(`projects/${encodeURIComponent(project)}/repository/branches`, {branch: id, ref: 'master'});
17+
18+
return promise;
19+
}
20+
21+
22+
23+
}
24+
25+
module.exports = branch;

src/models/issue.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,24 @@ class issue extends hasTimes {
2828

2929
return promise;
3030
}
31+
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+
3149

3250
/*
3351
* properties

0 commit comments

Comments
 (0)