Skip to content

Commit c6bc3b2

Browse files
committed
New Features (WIP)
* on stop, sync * on create, immediatly create issue and display * on status, show issue url
1 parent fe39396 commit c6bc3b2

File tree

4 files changed

+46
-7
lines changed

4 files changed

+46
-7
lines changed

src/gtt-create.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ const Config = require('./include/file-config');
66
const Cli = require('./include/cli');
77
const Tasks = require('./include/tasks');
88

9+
const Issue = require('./models/issue');
10+
911
program
1012
.arguments('[project] [title]')
1113
.option('-t, --type <type>', 'specify resource type: issue, merge_request')
14+
.option('-s, --skip-create', "don't create issue immediately")
1215
.option('--verbose', 'show verbose output')
1316
.parse(process.argv);
1417

@@ -18,6 +21,7 @@ let config = new Config(process.cwd()),
1821
tasks = new Tasks(config),
1922
type = program.type ? program.type : 'issue',
2023
title = program.args.length === 1 ? program.args[0] : program.args[1],
24+
now = program.now,
2125
project = program.args.length === 2 ? program.args[0] : null;
2226

2327
if (program.args.length < 2 && !config.get('project'))
@@ -27,5 +31,19 @@ if (!title)
2731
Cli.error('Wrong or missing title');
2832

2933
tasks.start(project, type, title)
30-
.then(frame => console.log(`Starting project ${config.get('project').magenta} and create ${type} "${title.blue}" at ${moment().format('HH:mm').green}`))
31-
.catch(error => Cli.error(error));
34+
.then((frame) => {
35+
console.log(`Starting project ${config.get('project').magenta} and create ${type} "${title.blue}" at ${moment().format('HH:mm').green}`)
36+
if (type == 'issue' && !program.skipCreate) {
37+
const issue = new Issue(frame.config, {})
38+
issue.make(frame.project, title, true).then((response) => {
39+
console.log(`Issue created: ${response.body.web_url}`)
40+
frame.resource.id = response.body.iid
41+
delete frame.resource.new
42+
frame.write()
43+
}).catch((d) => {
44+
console.log(`Issue not created`)
45+
console.log(d.body)
46+
})
47+
}
48+
})
49+
.catch(error => Cli.error(error));

src/gtt-status.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ tasks.status()
2222
return;
2323
}
2424

25-
frames.forEach(frame => console.log(`Project ${frame.project.magenta} ${frame.resource.type.blue} ${('#' + frame.resource.id).blue} is running, started ${moment(frame.start).fromNow().green} (id: ${frame.id})`));
25+
frames.forEach(frame => {
26+
console.log(`Project ${frame.project.magenta} ${frame.resource.type.blue} ${('#' + frame.resource.id).blue} is running, started ${moment(frame.start).fromNow().green} (id: ${frame.id})`)
27+
if (frame.resource.id) {
28+
const url = frame.config.data.url.replace(/api\/v\d\//, frame.project) + "/issues/" + frame.resource.id
29+
console.log(url.gray)
30+
}
31+
});
2632
})
27-
.catch(error => Cli.error('Could not read frames.', error));
33+
.catch(error => Cli.error('Could not read frames.', error));

src/gtt-stop.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,20 @@ tasks.stop()
2323

2424
console.log(`Stopping project ${frame.project.magenta} for new ${frame.resource.type} "${(frame.resource.id).blue}", started ${moment(frame.start).fromNow().green} (id: ${frame.id})`)
2525
});
26-
})
27-
.catch(error => Cli.error(error));
26+
tasks.syncInit()
27+
.then(() => tasks.sync.frames.length === 0 ? process.exit(0) : null)
28+
.then(() => {
29+
Cli.bar(`${Cli.fetch} Fetching or creating issues & merge requests...`, tasks.sync.frames.length);
30+
return tasks.syncResolve(Cli.advance);
31+
})
32+
.then(() => {
33+
Cli.bar(`${Cli.process} Processing issues & merge requests...`, tasks.sync.frames.length);
34+
return tasks.syncNotes(Cli.advance);
35+
})
36+
.then(() => {
37+
Cli.bar(`${Cli.update} Syncing time records...`, tasks.sync.frames.length);
38+
return tasks.syncUpdate(Cli.advance)
39+
})
40+
.catch(error => Cli.x(error));
41+
})
42+
.catch(error => Cli.error(error));

src/models/issue.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class issue extends hasTimes {
1616
let promise;
1717

1818
if (create) {
19-
promise = this.post(`projects/${encodeURIComponent(project)}/issues`, {title: id});
19+
promise = this.post(`projects/${encodeURIComponent(project)}/issues`, {title: id, description: "/assign @" + process.env.USER });
2020
} else {
2121
promise = this.get(`projects/${encodeURIComponent(project)}/issues/${id}`);
2222
}

0 commit comments

Comments
 (0)