@@ -40,7 +40,7 @@ type githubExporter struct {
40
40
41
41
// cache identifiers used to speed up exporting operations
42
42
// cleared for each bug
43
- cachedIDs map [string ]string
43
+ cachedOperationIDs map [string ]string
44
44
45
45
// cache labels used to speed up exporting labels events
46
46
cachedLabels map [string ]string
@@ -52,7 +52,7 @@ func (ge *githubExporter) Init(conf core.Configuration) error {
52
52
//TODO: initialize with multiple tokens
53
53
ge .identityToken = make (map [string ]string )
54
54
ge .identityClient = make (map [string ]* githubv4.Client )
55
- ge .cachedIDs = make (map [string ]string )
55
+ ge .cachedOperationIDs = make (map [string ]string )
56
56
ge .cachedLabels = make (map [string ]string )
57
57
return nil
58
58
}
@@ -74,7 +74,7 @@ func (ge *githubExporter) allowOrigin(origin string) bool {
74
74
return false
75
75
}
76
76
77
- // getIdentityClient return an identity github api v4 client
77
+ // getIdentityClient return a githubv4 API client configured with the access token of the given identity.
78
78
// if no client were found it will initialize it from the known tokens map and cache it for next use
79
79
func (ge * githubExporter ) getIdentityClient (id string ) (* githubv4.Client , error ) {
80
80
client , ok := ge .identityClient [id ]
@@ -97,31 +97,29 @@ func (ge *githubExporter) getIdentityClient(id string) (*githubv4.Client, error)
97
97
}
98
98
99
99
// ExportAll export all event made by the current user to Github
100
- func (ge * githubExporter ) ExportAll (repo * cache.RepoCache , since time.Time ) <- chan core.ExportResult {
100
+ func (ge * githubExporter ) ExportAll (repo * cache.RepoCache , since time.Time ) ( <- chan core.ExportResult , error ) {
101
101
out := make (chan core.ExportResult )
102
102
103
- go func (out chan <- core.ExportResult ) {
104
- defer close (out )
103
+ user , err := repo .GetUserIdentity ()
104
+ if err != nil {
105
+ return nil , err
106
+ }
105
107
106
- user , err := repo .GetUserIdentity ()
107
- if err != nil {
108
- out <- core .NewExportError (err , "" )
109
- return
110
- }
108
+ ge .identityToken [user .Id ()] = ge .conf [keyToken ]
111
109
112
- ge .identityToken [user .Id ()] = ge .conf [keyToken ]
110
+ // get repository node id
111
+ ge .repositoryID , err = getRepositoryNodeID (
112
+ ge .conf [keyOwner ],
113
+ ge .conf [keyProject ],
114
+ ge .conf [keyToken ],
115
+ )
113
116
114
- // get repository node id
115
- ge .repositoryID , err = getRepositoryNodeID (
116
- ge .conf [keyOwner ],
117
- ge .conf [keyProject ],
118
- ge .conf [keyToken ],
119
- )
117
+ if err != nil {
118
+ return nil , err
119
+ }
120
120
121
- if err != nil {
122
- out <- core .NewExportError (err , ge .repositoryID )
123
- return
124
- }
121
+ go func () {
122
+ defer close (out )
125
123
126
124
var allIdentitiesIds []string
127
125
for id := range ge .identityToken {
@@ -140,6 +138,7 @@ func (ge *githubExporter) ExportAll(repo *cache.RepoCache, since time.Time) <-ch
140
138
snapshot := b .Snapshot ()
141
139
142
140
// ignore issues created before since date
141
+ // TODO: compare the Lamport time instead of using the unix time
143
142
if snapshot .CreatedAt .Before (since ) {
144
143
out <- core .NewExportNothing (b .Id (), "bug created before the since date" )
145
144
continue
@@ -152,9 +151,9 @@ func (ge *githubExporter) ExportAll(repo *cache.RepoCache, since time.Time) <-ch
152
151
out <- core .NewExportNothing (id , "not an actor" )
153
152
}
154
153
}
155
- }(out )
154
+ }()
156
155
157
- return out
156
+ return out , nil
158
157
}
159
158
160
159
// exportBug publish bugs and related events
@@ -176,7 +175,7 @@ func (ge *githubExporter) exportBug(b *cache.BugCache, since time.Time, out chan
176
175
// skip bug if origin is not allowed
177
176
origin , ok := createOp .GetMetadata (keyOrigin )
178
177
if ok && ! ge .allowOrigin (origin ) {
179
- out <- core .NewExportNothing (b .Id (), fmt .Sprintf ("issue taged with origin: %s" , origin ))
178
+ out <- core .NewExportNothing (b .Id (), fmt .Sprintf ("issue tagged with origin: %s" , origin ))
180
179
return
181
180
}
182
181
@@ -186,7 +185,8 @@ func (ge *githubExporter) exportBug(b *cache.BugCache, since time.Time, out chan
186
185
githubURL , ok := createOp .GetMetadata (keyGithubUrl )
187
186
if ! ok {
188
187
// if we find github ID, github URL must be found too
189
- panic ("expected to find github issue URL" )
188
+ err := fmt .Errorf ("expected to find github issue URL" )
189
+ out <- core .NewExportError (err , b .Id ())
190
190
}
191
191
192
192
out <- core .NewExportNothing (b .Id (), "bug already exported" )
@@ -199,9 +199,6 @@ func (ge *githubExporter) exportBug(b *cache.BugCache, since time.Time, out chan
199
199
client , err := ge .getIdentityClient (author .Id ())
200
200
if err != nil {
201
201
// if bug is still not exported and we do not have the author stop the execution
202
-
203
- // fmt.Println("warning: skipping issue due to missing token for bug creator")
204
- // this is not an error, don't export bug
205
202
out <- core .NewExportNothing (b .Id (), fmt .Sprintf ("missing author token" ))
206
203
return
207
204
}
@@ -252,7 +249,7 @@ func (ge *githubExporter) exportBug(b *cache.BugCache, since time.Time, out chan
252
249
bugCreationHash = hash .String ()
253
250
254
251
// cache operation github id
255
- ge .cachedIDs [bugCreationHash ] = bugGithubID
252
+ ge .cachedOperationIDs [bugCreationHash ] = bugGithubID
256
253
257
254
for _ , op := range snapshot .Operations [1 :] {
258
255
// ignore SetMetadata operations
@@ -268,10 +265,10 @@ func (ge *githubExporter) exportBug(b *cache.BugCache, since time.Time, out chan
268
265
return
269
266
}
270
267
271
- // ignore imported (or exported) operations from github
268
+ // ignore operations already existing in github (due to import or export)
272
269
// cache the ID of already exported or imported issues and events from Github
273
270
if id , ok := op .GetMetadata (keyGithubId ); ok {
274
- ge .cachedIDs [hash .String ()] = id
271
+ ge .cachedOperationIDs [hash .String ()] = id
275
272
out <- core .NewExportNothing (hash .String (), "already exported operation" )
276
273
continue
277
274
}
@@ -299,7 +296,7 @@ func (ge *githubExporter) exportBug(b *cache.BugCache, since time.Time, out chan
299
296
out <- core .NewExportComment (hash .String ())
300
297
301
298
// cache comment id
302
- ge .cachedIDs [hash .String ()] = id
299
+ ge .cachedOperationIDs [hash .String ()] = id
303
300
304
301
case * bug.EditCommentOperation :
305
302
@@ -324,7 +321,7 @@ func (ge *githubExporter) exportBug(b *cache.BugCache, since time.Time, out chan
324
321
} else {
325
322
326
323
// case comment edition operation: we need to edit the Github comment
327
- commentID , ok := ge .cachedIDs [targetHash ]
324
+ commentID , ok := ge .cachedOperationIDs [targetHash ]
328
325
if ! ok {
329
326
panic ("unexpected error: comment id not found" )
330
327
}
@@ -424,7 +421,7 @@ func getRepositoryNodeID(owner, project, token string) (string, error) {
424
421
}
425
422
426
423
if resp .StatusCode != http .StatusOK {
427
- return "" , fmt .Errorf ("error retrieving repository node id %v " , resp .StatusCode )
424
+ return "" , fmt .Errorf ("HTTP error %v retrieving repository node id" , resp .StatusCode )
428
425
}
429
426
430
427
aux := struct {
@@ -668,9 +665,15 @@ func updateGithubIssueStatus(gc *githubv4.Client, id string, status bug.Status)
668
665
m := & updateIssueMutation {}
669
666
670
667
// set state
671
- state := githubv4 .IssueStateClosed
672
- if status == bug .OpenStatus {
668
+ var state githubv4.IssueState
669
+
670
+ switch status {
671
+ case bug .OpenStatus :
672
+ state = githubv4 .IssueStateOpen
673
+ case bug .ClosedStatus :
673
674
state = githubv4 .IssueStateOpen
675
+ default :
676
+ panic ("unknown bug state" )
674
677
}
675
678
676
679
input := githubv4.UpdateIssueInput {
0 commit comments