Skip to content

Commit c4b2341

Browse files
author
Andreas Müller
committed
Merge branch 'master' of github.com:ndu2/gitlab-time-tracker
2 parents 31355d2 + e0975a6 commit c4b2341

File tree

3 files changed

+26
-31
lines changed

3 files changed

+26
-31
lines changed

src/gtt-sync.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ tasks.syncInit()
3434
})
3535
.then(() => {
3636
Cli.bar(`${Cli.process} Processing issues & merge requests...`, tasks.sync.frames.length);
37-
return tasks.syncNotes(Cli.advance);
37+
return tasks.syncDetails(Cli.advance);
3838
})
3939
.then(() => {
4040
Cli.bar(`${Cli.update} Syncing time records...`, tasks.sync.frames.length);

src/include/tasks.js

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -43,26 +43,29 @@ class tasks {
4343
* @returns {Promise}
4444
*/
4545
syncResolve(callback) {
46-
this.sync.resources = {
47-
issue: {},
48-
merge_request: {}
49-
};
50-
46+
this.sync.resources = {}
47+
5148
// resolve issues and merge requests
5249
return this.sync.frames.forEach((frame, done) => {
5350
let project = frame.project,
5451
type = frame.resource.type,
55-
id = frame.resource.id,
56-
resource = this.sync.resources[type][id];
52+
id = frame.resource.id;
53+
if(!(project in this.sync.resources))
54+
{
55+
this.sync.resources[project]=
56+
{
57+
issue: {},
58+
merge_request: {}
59+
};
60+
}
5761

58-
if (resource !== undefined && resource.data.project_id)
62+
if(id in this.sync.resources[project][type]) {
5963
return done();
60-
61-
this.sync.resources[type][id] = new classes[type](this.config, {});
62-
this.sync.resources[type][id]
64+
}
65+
this.sync.resources[project][type][id] = new classes[type](this.config, {});
66+
this.sync.resources[project][type][id]
6367
.make(project, id, frame.resource.new)
6468
.then(() => {
65-
frame.title = this.sync.resources[type][id].data.title;
6669
if (callback) callback();
6770
done();
6871
})
@@ -71,27 +74,18 @@ class tasks {
7174
}
7275

7376
/**
74-
* Get notes for all frames.
77+
* sync details to frames.
7578
*/
76-
syncNotes(callback) {
79+
syncDetails(callback) {
7780
return this.sync.frames.forEach((frame, done) => {
7881
let project = frame.project,
7982
type = frame.resource.type,
80-
id = frame.resource.id,
81-
notes;
82-
83-
if ((notes = this.sync.resources[type][id].notes) && notes.length > 0) {
84-
if (callback) callback();
85-
return done();
83+
id = frame.resource.id;
84+
85+
if(id in this.sync.resources[project][type]) {
86+
frame.title = this.sync.resources[project][type][id].data.title;
8687
}
87-
88-
this.sync.resources[type][id]
89-
.getNotes()
90-
.then(() => {
91-
if (callback) callback();
92-
done();
93-
})
94-
.catch(error => done(`Could not get notes from ${type} ${id} on "${project}"`));
88+
return done();
9589
});
9690
}
9791

@@ -116,13 +110,14 @@ class tasks {
116110

117111
_addTime(frame, time) {
118112
return new Promise((resolve, reject) => {
119-
let resource = this.sync.resources[frame.resource.type][frame.resource.id];
113+
let resource = this.sync.resources[frame.project][frame.resource.type][frame.resource.id];
120114

121115
resource.createTime(Math.ceil(time), frame._stop, frame.note)
122116
.then(() => resource.getNotes())
123117
.then(() => {
124118
if (frame.resource.new) {
125119
delete frame.resource.new;
120+
frame.resource.title = frame.resource.id;
126121
frame.resource.id = resource.data.iid;
127122
}
128123

src/models/hasTimes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class hasTimes extends Base {
2727
* @returns {*}
2828
*/
2929
createTime(time, created_at, note) {
30-
if(note === null) {
30+
if(note === null || note === undefined) {
3131
note = '';
3232
}
3333
else {

0 commit comments

Comments
 (0)