Skip to content
This repository was archived by the owner on May 22, 2025. It is now read-only.

Commit 7e23905

Browse files
author
Andreas Müller
committed
fixed sync when having 2 projects with same issue ids
1 parent a8fd623 commit 7e23905

File tree

2 files changed

+21
-28
lines changed

2 files changed

+21
-28
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: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -43,23 +43,27 @@ 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(() => {
6569
frame.title = this.sync.resources[type][id].data.title;
@@ -71,27 +75,16 @@ class tasks {
7175
}
7276

7377
/**
74-
* Get notes for all frames.
78+
* sync details to frames.
7579
*/
76-
syncNotes(callback) {
80+
syncDetails(callback) {
7781
return this.sync.frames.forEach((frame, done) => {
7882
let project = frame.project,
7983
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();
84+
id = frame.resource.id;
8685
}
8786

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}"`));
87+
return done();
9588
});
9689
}
9790

@@ -116,7 +109,7 @@ class tasks {
116109

117110
_addTime(frame, time) {
118111
return new Promise((resolve, reject) => {
119-
let resource = this.sync.resources[frame.resource.type][frame.resource.id];
112+
let resource = this.sync.resources[frame.project][frame.resource.type][frame.resource.id];
120113

121114
resource.createTime(Math.ceil(time), frame._stop, frame.note)
122115
.then(() => resource.getNotes())

0 commit comments

Comments
 (0)