• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

moosetechnology / GitProjectHealth / 17979391720

24 Sep 2025 02:09PM UTC coverage: 77.063% (+3.7%) from 73.342%
17979391720

Pull #233

github

web-flow
Merge 486060945 into dd8ffa1f6
Pull Request #233: V2.0.0 : Refactoring importers

3479 of 3743 new or added lines in 41 files covered. (92.95%)

26 existing lines in 6 files now uncovered.

21745 of 28217 relevant lines covered (77.06%)

0.77 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

59.0
/src/GitHubHealth-Model-Importer/GithubModelImporter.class.st
1
Class {
2
        #name : #GithubModelImporter,
3
        #superclass : #GitModelImporter,
4
        #category : #'GitHubHealth-Model-Importer'
5
}
6

7
{ #category : #api }
8
GithubModelImporter >> api [
×
9

×
10
        self
×
11
                deprecated: 'Use #repoApi instead'
×
12
                on: '7 October 2024'
×
13
                in:
×
14
                'Pharo-11.0.0+build.726.sha.aece1b5473acf3830a0e082c1bc3a15d4ff3522b (64 Bit)'.
×
15

×
16
        ^ repoApi
×
17
]
×
18

19
{ #category : #api }
20
GithubModelImporter >> api: anObject [
×
21

×
22
        self
×
23
                deprecated: 'Use #repoApi: instead'
×
24
                on: '7 October 2024'
×
25
                in:
×
26
                'Pharo-11.0.0+build.726.sha.aece1b5473acf3830a0e082c1bc3a15d4ff3522b (64 Bit)'.
×
27

×
28
        repoApi := anObject
×
29
]
×
30

31
{ #category : #'import - commits' }
32
GithubModelImporter >> completeImportedCommit: aGLHCommit [
×
33

×
34
        | result |
×
35
        ('completing commit: ' , aGLHCommit short_id printString) recordInfo.
×
36
        "link commit to user"
×
37
        self importCreatorOfCommit: aGLHCommit.
×
38

×
39
        "import deletion and addition"
×
40
        result := self repoApi
×
41
                          commit: aGLHCommit id
×
42
                          ofOrganisation: aGLHCommit repository project group name
×
43
                          ofProject: aGLHCommit repository project name.
×
44
        aGLHCommit deletions:
×
45
                ((result at: #files) collect: [ :file | file at: #deletions ]) sum.
×
46
        aGLHCommit additions:
×
47
                ((result at: #files) collect: [ :file | file at: #additions ]) sum.
×
48

×
49

×
50
        "import diffs of this commits"
×
51
        self withCommitDiffs ifTrue: [
×
52
                | diffs |
×
53
                aGLHCommit diffs ifEmpty: [
×
54
                        diffs := self parseDiffresult: result.
×
55
                        diffs := aGLHCommit diffs
×
56
                                         addAll: diffs
×
57
                                         unless: self blockForDiffEquality.
×
58
                        self glhModel addAll: diffs unless: self blockForDiffEquality.
×
59
                        diffs do: [ :diff | self importDiffRangesForDiff: diff ] ] ].
×
60

×
61
        ^ aGLHCommit 
×
62
]
×
63

64
{ #category : #'import - projects' }
65
GithubModelImporter >> completeImportedProject: aGLHProject [
1✔
66

1✔
67
        ('Complete import of project: ' , aGLHProject id printString)
1✔
68
                recordInfo.
1✔
69
        aGLHProject repository ifNotNil: [ ^ aGLHProject ].
1✔
70

1✔
71
        aGLHProject repository: GLHRepository new.
1✔
72
        self glhModel add: aGLHProject repository.
1✔
73

1✔
74
        self importPipelinesOfProject: aGLHProject.
1✔
75
        self importBranchesOf: aGLHProject.
1✔
76
        self withCommitsSince ifNotNil: [ :withCommitSince | "If not nil, it means we have to import commit"
1✔
77
                | commits |
1✔
78
                commits := self importCommitsOfProject: aGLHProject.
1✔
79
                self chainsCommitsFrom: commits ]
1✔
80
]
1✔
81

82
{ #category : #'private - configure reader' }
83
GithubModelImporter >> configureReaderForBranch: reader [
1✔
84

1✔
85
        super configureReaderForBranch: reader.
1✔
86

1✔
87
        reader for: GLHBranch do: [ :mapping |
1✔
88
                mapping
1✔
89
                        mapProperty: #sha
1✔
90
                        getter: [ :branch | #ignore ]
1✔
91
                        setter: [ :branch :value | branch sha: (value at: #sha) ] ]
1✔
92
]
1✔
93

94
{ #category : #'private - configure reader' }
95
GithubModelImporter >> configureReaderForCommit: reader [
1✔
96

1✔
97
        super configureReaderForCommit: reader.
1✔
98

1✔
99
        reader for: GLHCommit do: [ :mapping |
1✔
100
                mapping mapInstVar: #id to: #sha.
1✔
101
                mapping mapInstVar: #web_url to: #html_url.
1✔
102

1✔
103
                mapping
1✔
104
                        mapProperty: #commit
1✔
105
                        getter: [ :object | #ignore ]
1✔
106
                        setter: [ :glhCommit :value |
1✔
107
                                glhCommit message: (value at: #message).
1✔
108
                                glhCommit authored_date:
1✔
109
                                        (DateAndTime fromString: (value at: #author at: #date)).
1✔
110
                                glhCommit committed_date:
1✔
111
                                        (DateAndTime fromString: (value at: #committer at: #date)) ].
1✔
112

1✔
113
                mapping
1✔
114
                        mapProperty: #author
1✔
115
                        getter: [ :object | #ignore ]
1✔
116
                        setter: [ :glhCommit :value |
1✔
117
                                value ifNotNil: [
1✔
118
                                        glhCommit author_name: (value at: #login).
1✔
119
                                        value
1✔
120
                                                at: #id
1✔
121
                                                ifPresent: [ :authorId |
1✔
122
                                                glhCommit cacheAt: #authorID put: ( value at: #id)  ] ] ].
1✔
123

1✔
124
                mapping
1✔
125
                        mapProperty: #committer
1✔
126
                        getter: [ :object | #ignore ]
1✔
127
                        setter: [ :glhCommit :value |
1✔
128
                                value ifNotNil: [ glhCommit committer_name: (value at: #login) ] ].
1✔
129

1✔
130
                (mapping mapInstVar: #parent_ids to: #parents) valueSchema:
1✔
131
                        #ArrayOfId ].
1✔
132

1✔
133
        reader for: DateAndTime customDo: [ :mapping |
1✔
134
                mapping decoder: [ :string | DateAndTime fromString: string ] ].
1✔
135

1✔
136
        reader for: #ArrayOfId customDo: [ :mapping |
1✔
137
                mapping decoder: [ :parents |
1✔
138
                        parents collect: [ :parent | parent at: #sha ] ] ]
1✔
139
]
1✔
140

141
{ #category : #'private - configure reader' }
142
GithubModelImporter >> configureReaderForGroup: reader [
1✔
143

1✔
144
        super configureReaderForGroup: reader.
1✔
145
        
1✔
146
        reader
1✔
147
                for: GLHGroup
1✔
148
                do: [ :mapping | mapping mapInstVar: #web_url to: #html_url ]
1✔
149
]
1✔
150

151
{ #category : #'private - configure reader' }
152
GithubModelImporter >> configureReaderForMergeRequest: reader [
1✔
153
        "        reader mapInstVarsFor: GLHProject. "
1✔
154

1✔
155
        super configureReaderForMergeRequest: reader.
1✔
156
        
1✔
157
        reader for: GLHMergeRequest do: [ :mapping |
1✔
158
                (mapping mapInstVar: #created_at) valueSchema: DateAndTime.
1✔
159
                (mapping mapInstVar: #updated_at) valueSchema: DateAndTime.
1✔
160
                (mapping mapInstVar: #merged_at) valueSchema: DateAndTime.
1✔
161
                (mapping mapInstVar: #closed_at) valueSchema: DateAndTime.
1✔
162

1✔
163
                mapping
1✔
164
                        mapProperty: #author
1✔
165
                        getter: [  ]
1✔
166
                        setter: [ :object :value |
1✔
167
                        object cacheAt: #authorID put: (value at: #id) ].
1✔
168
                mapping
1✔
169
                        mapProperty: #merge_user
1✔
170
                        getter: [  ]
1✔
171
                        setter: [ :object :value |
1✔
172
                                value ifNotNil: [
1✔
173
                                        object cacheAt: #mergeUserID put: (value at: #id) ] ] ].
1✔
174

1✔
175

1✔
176

1✔
177
]
1✔
178

179
{ #category : #'private - configure reader' }
180
GithubModelImporter >> configureReaderForPipeline: reader [
1✔
181

1✔
182
        super configureReaderForPipeline: reader.
1✔
183

1✔
184
        reader for: GLHPipeline do: [ :mapping |
1✔
185
                "mapping mapInstVar: #status to: #conclusion."
1✔
186

1✔
187
                mapping
1✔
188
                        mapProperty: #status
1✔
189
                        getter: [ :object | #ignore ]
1✔
190
                        setter: [ :object :value |
1✔
191
                        (object status isNil and: [value isNotNil]) ifTrue: [ object status: value ].
1✔
192
                         ].
1✔
193

1✔
194
                mapping
1✔
195
                        mapProperty: #conclusion
1✔
196
                        getter: [ :object | #ignore ]
1✔
197
                        setter: [ :object :value |
1✔
198
                        (object status isNil and: [value isNotNil]) ifTrue: [ object status: value ]. ].
1✔
199
                
1✔
200
                mapping
1✔
201
                        mapProperty: #run_started_at
1✔
202
                        getter: [ :object | #ignore ]
1✔
203
                        setter: [ :object :value |
1✔
204
                        object runDate: (DateAndTime fromString: value) ] ]
1✔
205
]
1✔
206

207
{ #category : #'private - configure reader' }
208
GithubModelImporter >> configureReaderForProject: reader [
1✔
209

1✔
210
        super configureReaderForProject: reader.
1✔
211
        
1✔
212
        reader for: GLHProject do: [ :mapping |
1✔
213
                mapping mapInstVar: #web_url to: #html_url.
1✔
214
         ].
1✔
215

1✔
216
]
1✔
217

218
{ #category : #'private - configure reader' }
219
GithubModelImporter >> configureReaderForUser: reader [
1✔
220
        super configureReaderForUser: reader.
1✔
221
        
1✔
222
        
1✔
223
                reader for: GLHUser do: [ :mapping |
1✔
224
                mapping mapInstVar: #public_email to: #email.
1✔
225
                mapping mapInstVar: #username to: #login.
1✔
226
                mapping mapInstVar: #bio to: #bio.
1✔
227
                mapping mapInstVar: #organization to: #company.
1✔
228
                mapping mapInstVar: #web_url to: #html_url.
1✔
229
 ].
1✔
230
]
1✔
231

232
{ #category : #private }
233
GithubModelImporter >> convertApiFileAsFile: aAPIFile [
×
234

×
235
        aAPIFile type = 'dir' ifTrue: [ 
×
236
                ^ GLHFileDirectory new
×
237
                          name: aAPIFile name;
×
238
                          yourself ].
×
239
        ^ GLHFileBlob new
×
240
                  name: aAPIFile name;
×
241
                  yourself
×
242
]
×
243

244
{ #category : #'import - groups' }
245
GithubModelImporter >> ensureGroupNamed: aGroupName [
×
246

×
NEW
247
        self flag: 'WARNING: group from different platform (github vs gitlab) can share the same name, thus being confused here'. 
×
248
        ^ self glhModel
×
249
                  detect: [ :a |
×
250
                  (a isKindOf: GLHGroup) and: [ a name = aGroupName ] ]
×
251
                  ifNone: [ self glhModel newGroupNamed: aGroupName ]
×
252
]
×
253

254
{ #category : #'import - repositories' }
255
GithubModelImporter >> importBranchesOf: aGLHProject [
1✔
256
        "add the pipeline (actions runs) in the project"
1✔
257

1✔
258
        | branchesResults foundBranches branches |
1✔
259
        branchesResults := self repoApi branches
1✔
260
                                   getAllForRepo: aGLHProject name
1✔
261
                                   ofOwner: aGLHProject group name.
1✔
262

1✔
263
        foundBranches := (branchesResults collect: [ :branchesResult |
1✔
264
                                  self parseBranchesResult: branchesResult ])
1✔
265
                                 flattened.
1✔
266

1✔
267

1✔
268
        "WARNING: always add branch first into repository, than into model !"
1✔
269
        branches := aGLHProject repository branches
1✔
270
                            addAll: foundBranches
1✔
271
                            unless: self blockOnNameEquality.
1✔
272

1✔
273
        "branch HEAD commit is not imported by default. use branch ref (sha) to import it specifically"
1✔
274

1✔
275
        branches := self glhModel
1✔
276
                            addAll: branches
1✔
277
                            unless: self blockForBranchEquality.
1✔
278

1✔
279
        self withFiles ifTrue: [
1✔
280
                branches do: [ :branch | self importFilesOfBranch: branch ] ].
1✔
281
        
1✔
282
        ^branches.
1✔
283
]
1✔
284

285
{ #category : #'import - commits' }
286
GithubModelImporter >> importCommit: aCommitID ofProject: aGLHProject [
1✔
287

1✔
288
        | result parsedResult |
1✔
289
        (self glhModel allWithType: GLHCommit) asOrderedCollection
1✔
290
                detect: [ :commit | commit id = aCommitID ]
1✔
291
                ifFound: [ :commit | ^ commit ].
1✔
292

1✔
293
        result := self repoApi commits
1✔
294
                          get: aCommitID
1✔
295
                          inProject: aGLHProject id.
1✔
296

1✔
297
        parsedResult := self parseCommitResult: result.
1✔
298

1✔
299
        parsedResult := self glhModel
1✔
300
                                add: parsedResult
1✔
301
                                unless: self blockOnIdEquality.
1✔
302
        parsedResult := aGLHProject repository commits
1✔
303
                                add: parsedResult
1✔
304
                                unless: self blockOnIdEquality.
1✔
305

1✔
306
        self withCommitDiffs ifTrue: [ self importDiffOfCommit: parsedResult ].
1✔
307

1✔
308
        ^ parsedResult
1✔
309
]
1✔
310

311
{ #category : #'import - commits' }
312
GithubModelImporter >> importCommitsOfProject: aGLHProject [
1✔
313

1✔
314
        | itemByPage foundCommits tmp pageNumber |
1✔
315
        itemByPage := 100.
1✔
316
        pageNumber := 1.
1✔
317
        ('Extract all commits of ' , aGLHProject name) recordInfo.
1✔
318
        foundCommits := OrderedCollection new.
1✔
319
        ('Extract commits from ' , foundCommits size printString , ' to '
1✔
320
         , (foundCommits size + itemByPage) printString) recordInfo.
1✔
321
        "also check that there is at least one commit with the error handling"
1✔
322
        [
1✔
323
        tmp := self parseCommitsResult: (self repoApi commits
1✔
324
                                getForRepo: aGLHProject name
1✔
325
                                ofOwner: aGLHProject group name
1✔
326
                                withParms: {
1✔
327
                                                (#since -> self withCommitsSince).
1✔
328
                                                (#perPage -> itemByPage).
1✔
329
                                                (#page -> pageNumber) } asDictionary) ]
1✔
330
                on: GHRepositoryEmptyError
1✔
331
                do: [ ^ {  } ].
1✔
332

1✔
333
        foundCommits addAll: tmp.
1✔
334
        [ tmp size = itemByPage ] whileTrue: [
1✔
335
                pageNumber := pageNumber + 1.
1✔
336
                ('Extract issues from ' , foundCommits size printString , ' to '
1✔
337
                 , (foundCommits size + itemByPage) printString) recordInfo.
1✔
338
                tmp := self parseCommitsResult: (self repoApi commits
1✔
339
                                        getForRepo: aGLHProject name
1✔
340
                                        ofOwner: aGLHProject group name
1✔
341
                                        withParms: {
1✔
342
                                                        (#sine -> self withCommitsSince).
1✔
343
                                                        (#perPage -> itemByPage).
1✔
344
                                                        (#page -> pageNumber) } asDictionary).
1✔
345
                foundCommits addAll: tmp ].
1✔
346

1✔
347
        "add the imported commits (unless they are already added to this repository)"
1✔
348
        aGLHProject repository commits
1✔
349
                addAll: foundCommits
1✔
350
                unless: [ :existing :new | existing id = new id ].
1✔
351
        "add the imported commits to the model unles they are already added to the model"
1✔
352
        ^ self glhModel
1✔
353
                  addAll: foundCommits
1✔
354
                  unless: [ :existing :new | existing id = new id ]
1✔
355
]
1✔
356

357
{ #category : #'import - commits' }
358
GithubModelImporter >> importCreatorOfCommit: aGLHCommit [
×
359

×
360
        | creator |
×
361
        (self glhModel allWithType: GLHUser)
×
362
                detect: [ :user | user username = aGLHCommit author_name ]
×
363
                ifFound: [ :user |
×
364
                        aGLHCommit commitCreator: user.
×
365
                        ^ user ].
×
366

×
367
        aGLHCommit author_name ifNotNil: [ :author_name |
×
368
                creator := self importUserByUsername: author_name.
×
369
                aGLHCommit commitCreator: creator ].
×
370
        ^ creator
×
371
]
×
372

373
{ #category : #'import - commits' }
374
GithubModelImporter >> importDiffOfCommit: aGLHCommit [
×
375

×
376
        | result diffsResult |
×
377
        aGLHCommit diffs ifNotEmpty: [
×
378
                'Diff already importer: '
×
379
                , aGLHCommit short_id printString recordInfo.
×
380
                ^ aGLHCommit diffs ].
×
381
        ('Import diff of commit: ' , aGLHCommit short_id printString)
×
382
                recordInfo.
×
383
        result := self repoApi
×
384
                          commit: aGLHCommit id
×
385
                          ofOrganisation: aGLHCommit repository project group name
×
386
                          ofProject: aGLHCommit repository project name.
×
387
        diffsResult := self parseDiffresult: result.
×
388

×
389
        ^ aGLHCommit diffs
×
390
                  addAll: diffsResult
×
391
                  unless: self blockForDiffEquality
×
392
]
×
393

394
{ #category : #'import - files' }
395
GithubModelImporter >> importDirectoryFiles: aDirectoryFile OfBranch: aBranch [
×
396

×
397
        | result files apiFiles |
×
398
        ('Explore ' , aDirectoryFile name) recordInfo.
×
399
        result := self api
×
400
                          contentsOfRepo: aBranch repository project name
×
401
                          ofOrganization: aBranch repository project group name
×
402
                          inBranch: aBranch name
×
403
                          withPath: aDirectoryFile path.
×
404
        apiFiles := self parseFileTreeResult: result.
×
405
        files := apiFiles collect: [ :apiFile | 
×
406
                         self convertApiFileAsFile: apiFile ].
×
407
        files do: [ :file | 
×
408
                self glhModel add: file.
×
409
                aDirectoryFile addFile: file ].
×
410
        files
×
411
                select: [ :file | file isKindOf: GLHFileDirectory ]
×
412
                thenCollect: [ :file | 
×
413
                self importDirectoryFiles: file OfBranch: aBranch ]
×
414
]
×
415

416
{ #category : #'import - files' }
417
GithubModelImporter >> importFilesOfBranch: aBranch [
×
418

×
419
        | result files apiFiles |
×
420
        result := self api
×
421
                          contentsOfRepo: aBranch repository project name
×
422
                          ofOrganization: aBranch repository project group name
×
423
                          inBranch: aBranch name
×
424
                          withPath: nil.
×
425
        apiFiles := self parseFileTreeResult: result.
×
426
        files := apiFiles collect: [ :apiFile | 
×
427
                         self convertApiFileAsFile: apiFile ].
×
428
        files do: [ :file | 
×
429
                self glhModel add: file.
×
430
                aBranch addFile: file ].
×
431
        files
×
432
                select: [ :file | file isKindOf: GLHFileDirectory ]
×
433
                thenCollect: [ :file | 
×
NEW
434
                self importDirectoryFiles: file OfBranch: aBranch ].
×
NEW
435
        ^ files
×
UNCOV
436
]
×
437

438
{ #category : #'import - groups' }
439
GithubModelImporter >> importGroup: aGroupName [
1✔
440

1✔
441
        | result groupResult |
1✔
442
        result := self repoApi organizations get: aGroupName.
1✔
443
        groupResult := self parseGroupResult: result.
1✔
444
        self glhModel add: groupResult.
1✔
445
        self importRepositoriesOfGroup: groupResult.
1✔
446
        ^ groupResult
1✔
447
]
1✔
448

449
{ #category : #'import - commits' }
450
GithubModelImporter >> importLatestCommitsOfProject: aGLHProject [
1✔
451
        "limited to the last 50 commits"
1✔
452

1✔
453
        | results parsedResults |
1✔
454
        results := self repoApi commits
1✔
455
                           getLatestForRepo: aGLHProject name
1✔
456
                           ofOwner: aGLHProject group name.
1✔
457
        parsedResults := self parseCommitsResult: results.
1✔
458
        parsedResults := self glhModel
1✔
459
                                 addAll: parsedResults
1✔
460
                                 unless: self blockOnIdEquality.
1✔
461

1✔
462
        aGLHProject repository commits
1✔
463
                addAll: parsedResults
1✔
464
                unless: self blockOnIdEquality.
1✔
465

1✔
466
        self withCommitDiffs ifTrue: [
1✔
467
                parsedResults do: [ :commit | self importDiffOfCommit: commit ] ].
1✔
468

1✔
469
        ^ parsedResults
1✔
470
]
1✔
471

472
{ #category : #'import - merge-requests' }
NEW
473
GithubModelImporter >> importLatestMergeRequestsOfProject: aGLHProject [ 
×
NEW
474
        
×
NEW
475
        | results parsedResults |
×
NEW
476
        results := self repoApi pullRequests getLatestForRepo: aGLHProject name ofOwner:  aGLHProject group name.
×
NEW
477
        parsedResults := self parseMergeRequestsResult: results.
×
NEW
478

×
NEW
479
        parsedResults := glhModel
×
NEW
480
                                 addAll: parsedResults
×
NEW
481
                                 unless: self blockOnIdEquality.
×
NEW
482
        parsedResults := aGLHProject mergeRequests
×
NEW
483
                                 addAll: parsedResults
×
NEW
484
                                 unless: self blockOnIdEquality.
×
NEW
485
        ^ parsedResults
×
NEW
486
]
×
487

488
{ #category : #'import - merge-requests' }
NEW
489
GithubModelImporter >> importLatestPullRequestsOfProject: aGLHProject [
×
NEW
490
        "alias method since PullRequest = MergeRequest in model"
×
NEW
491
        ^ self importLatestMergeRequestsOfProject: aGLHProject 
×
NEW
492
]
×
493

494
{ #category : #'import - merge-requests' }
NEW
495
GithubModelImporter >> importMergeRequestsOfProject: aProject [ 
×
496
        |response mergeRequests|
×
497
        response := self repoApi 
×
498
                        mergeRequestsOfRepo: aProject group name 
×
499
                        ofProject: aProject name.
×
500
        mergeRequests := self parseMergeRequestsResult: response. 
×
501
        
×
502
        mergeRequests := aProject mergeRequests addAll:mergeRequests unless: self blockOnIdEquality.
×
503
        ^ mergeRequests
×
504
        
×
505
]
×
506

507
{ #category : #'import - pipelines' }
508
GithubModelImporter >> importPipelinesOfProject: project [
1✔
509

1✔
510
        "add the pipeline (actions runs) in the project"
1✔
511

1✔
512
        | pipelinesResult ghApiPipelineOverview |
1✔
513
        pipelinesResult := self repoApi actions
1✔
514
                                   getLatestForRepo: project name
1✔
515
                                   ofOwner: project group name.
1✔
516
        ghApiPipelineOverview := self parsePipelinesResult: pipelinesResult.
1✔
517
        ghApiPipelineOverview workflow_runs do: [ :pipeline | 
1✔
518
                project addPipeline: pipeline ]
1✔
519
]
1✔
520

521
{ #category : #'import - projects' }
522
GithubModelImporter >> importProject: aProjectName ofGroup: aGroupName [
×
523

×
524
        | result projectResult group |
×
525
        group := self ensureGroupNamed: aGroupName.
×
NEW
526
        result := self repoApi organizations getRepository: aProjectName ofOrganization: aGroupName .
×
527
        projectResult := self parseProjectResult: result.
×
528
        projectResult group: group.
×
529
        self glhModel add: projectResult.
×
530
        self completeImportedProject: projectResult.
×
531
        ^ projectResult
×
532
]
×
533

534
{ #category : #'import - merge-requests' }
NEW
535
GithubModelImporter >> importPullRequestsOfProject: aProject [
×
NEW
536
        "alias method since PullRequest = MergeRequest in model"
×
NEW
537

×
NEW
538
        ^ self importMergeRequestsOfProject: aProject
×
NEW
539
]
×
540

541
{ #category : #'import - groups' }
542
GithubModelImporter >> importRepositoriesOfGroup: groupResult [
1✔
543
        "Github Repository = GLHProject"
1✔
544

1✔
545
        | reposResult itemByPage pageNumber reposFound tmp |
1✔
546
        itemByPage := 100.
1✔
547
        pageNumber := 1.
1✔
548
        ('Extract all repository of ' , groupResult name) recordInfo.
1✔
549
        reposFound := OrderedCollection new.
1✔
550
        ('Extract commits from ' , reposFound size printString , ' to '
1✔
551
         , (reposFound size + itemByPage) printString) recordInfo.
1✔
552
        tmp := self parseArrayOfProject: (self repoApi
1✔
553
                                organizations getRepositoriesOfOrganization: groupResult name
1✔
554
                                perPage: itemByPage
1✔
555
                                page: pageNumber).
1✔
556

1✔
557
        reposFound addAll: tmp.
1✔
558
        [ tmp size = itemByPage ] whileTrue: [
1✔
559
                pageNumber := pageNumber + 1.
1✔
560
                ('Extract issues from ' , reposFound size printString , ' to '
1✔
561
                 , (reposFound size + itemByPage) printString) recordInfo.
1✔
562
                tmp := self parseArrayOfProject: (self repoApi
1✔
563
                                        reposOfOrganization: groupResult name
1✔
564
                                        perPage: itemByPage
1✔
565
                                        page: pageNumber).
1✔
566
                reposFound addAll: tmp ].
1✔
567

1✔
568
        reposResult := self repoApi organizations getRepositoriesOfOrganization: groupResult name.
1✔
569
        groupResult projects addAll: reposFound.
1✔
570
        self glhModel addAll: groupResult projects.
1✔
571
        groupResult projects do: [ :project |
1✔
572
                self completeImportedProject: project ].
1✔
573
        ^ groupResult
1✔
574
]
1✔
575

576
{ #category : #'import - users' }
577
GithubModelImporter >> importUser: userID [
1✔
578

1✔
579
        | result userResult |
1✔
580
        (glhModel allWithType: GLHUser)
1✔
581
                detect: [ :user | user id = userID ]
1✔
582
                ifFound: [ :user | ^ user ].
1✔
583
        ('Import user: ' , userID printString) recordInfo.
1✔
584
        result := self repoApi users getUserId: userID.
1✔
585
        userResult := self parseUserResult: result.
1✔
586
        ^ glhModel
1✔
587
                  add: userResult
1✔
588
                  unless: [ :current :new | current id = new id ]
1✔
589
]
1✔
590

591
{ #category : #'import - users' }
NEW
592
GithubModelImporter >> importUserByUsername: anUsername [
×
NEW
593

×
NEW
594
        | dicUsername resultUser |
×
NEW
595
        dicUsername := ((self glhModel allWithType: GLHUser) collect: [ :user |
×
NEW
596
                                user username -> user ]) asSet asDictionary.
×
NEW
597

×
NEW
598
        dicUsername addAll: self userCatalogue collectUsernames.
×
NEW
599

×
NEW
600

×
NEW
601
        resultUser := dicUsername
×
NEW
602
                              at: anUsername
×
NEW
603
                              ifAbsent: [ "thus we have to import this new user"
×
NEW
604
                                      | userId searchResult |
×
NEW
605
                                      ('Import user with username: '
×
NEW
606
                                       , anUsername printString) recordInfo.
×
NEW
607

×
NEW
608
                                      searchResult := self repoApi users getUsername: anUsername.
×
NEW
609

×
NEW
610
                                      (searchResult class = Dictionary and: [
×
NEW
611
                                               (searchResult at: #status) includesSubstring:
×
NEW
612
                                                       '404' ])
×
NEW
613
                                              ifTrue: [ "if the result is an 403 error we fake a new user"
×
NEW
614
                                                      self glhModel
×
NEW
615
                                                              add: (GLHUser new
×
NEW
616
                                                                               username: anUsername;
×
NEW
617
                                                                               name: anUsername;
×
NEW
618
                                                                               yourself)
×
NEW
619
                                                              unless: [ :nu :ou | nu username = ou username ] ]
×
NEW
620
                                              ifFalse: [
×
NEW
621
                                                      searchResult
×
NEW
622
                                                              ifEmpty: [ "results can be empty thus we force a new user with the info we have "
×
NEW
623
                                                                      self glhModel
×
NEW
624
                                                                              add: (GLHUser new
×
NEW
625
                                                                                               username: anUsername;
×
NEW
626
                                                                                               name: anUsername;
×
NEW
627
                                                                                               yourself)
×
NEW
628
                                                                              unless: [ :nu :ou | nu username = ou username ] ]
×
NEW
629
                                                              ifNotEmpty: [ "because we may already have the researched user, we look by ID in the model"
×
NEW
630
                                                                      userId := searchResult first at: #id.
×
NEW
631
                                                                      (self glhModel allWithType: GLHUser)
×
NEW
632
                                                                              detect: [ :user | user id = userId ]
×
NEW
633
                                                                              ifNone: [ self importUser: userId ] ] ] ].
×
NEW
634

×
NEW
635
        self userCatalogue addUser: resultUser withName: anUsername.
×
NEW
636

×
NEW
637
        ^ resultUser
×
NEW
638
]
×
639

640
{ #category : #initialization }
641
GithubModelImporter >> initReader [
1✔
642

1✔
643
        super initReader. 
1✔
644
]
1✔
645

646
{ #category : #initialization }
647
GithubModelImporter >> initialize [
1✔
648

1✔
649
        super initialize.
1✔
650
        self repoApi: GithubApi new.
1✔
651
        self repoApi output: 'json'.
1✔
652
        self withCommitDiffs: false.
1✔
653
        withFiles := false.
1✔
654

1✔
655
]
1✔
656

657
{ #category : #parsing }
658
GithubModelImporter >> parseArrayOfProject: arrayOfProjects [
1✔
659

1✔
660
        | reader |
1✔
661
        " reader := NeoJSONReader on: arrayOfProjects readStream.
1✔
662
        
1✔
663
        reader
1✔
664
                for: #ArrayOfProjects
1✔
665
                customDo: [ :customMappting | 
1✔
666
                customMappting listOfElementSchema: GLHProject ].
1✔
667
        
1✔
668
        reader for: GLHProject do: [ :mapping | 
1✔
669
                mapping mapInstVar: #name to: #name.
1✔
670
                mapping mapInstVar: #description to: #description.
1✔
671
                mapping mapInstVar: #id to: #id.
1✔
672
                mapping mapInstVar: #archived to: #archived.
1✔
673
                mapping mapInstVar: #web_url to: #html_url.
1✔
674
                mapping mapInstVar: #topics to: #topics ].
1✔
675
        ^ reader nextAs: #ArrayOfProjects
1✔
676
        "
1✔
677
        reader := generalReader on: arrayOfProjects readStream.
1✔
678

1✔
679
        ^ reader nextAs: #ArrayOfProject
1✔
680
]
1✔
681

682
{ #category : #parsing }
683
GithubModelImporter >> parseBranchesResult: arrayOfBranch [
1✔
684

1✔
685
        | reader |
1✔
686
        reader := generalReader on: arrayOfBranch readStream.
1✔
687

1✔
688
        ^ reader nextAs: #ArrayOfBranch
1✔
689
]
1✔
690

691
{ #category : #parsing }
692
GithubModelImporter >> parseCommitResult: result [
1✔
693
        | reader |
1✔
694
        
1✔
695
        reader := generalReader on: result readStream.
1✔
696

1✔
697
        ^ reader nextAs: GLHCommit 
1✔
698
]
1✔
699

700
{ #category : #parsing }
701
GithubModelImporter >> parseCommitsResult: result [
1✔
702

1✔
703
        | reader |
1✔
704
        (result includesSubstring: '"status":"409"') ifTrue: [
1✔
705
                GHRepositoryEmptyError signal: 'Git Repository is empty' ].
1✔
706

1✔
707
        reader := generalReader on: result readStream.
1✔
708

1✔
709
        ^ reader nextAs: #ArrayOfCommit
1✔
710
]
1✔
711

712
{ #category : #parsing }
713
GithubModelImporter >> parseDiffresult: response [
×
714

×
715
        | result |
×
716
        result := (response at: #files) collect: [ :file |
×
717
                          GLHDiff new
×
718
                                  diffString: (file at: #patch);
×
719
                                  old_path: (file at: #filename);
×
720
                                  new_path: (file at: #filename) ].
×
721

×
722
        ^ result
×
723
]
×
724

725
{ #category : #parsing }
726
GithubModelImporter >> parseFileTreeResult: aResult [
×
727

×
728
        | reader |
×
729
        reader := NeoJSONReader on: aResult readStream.
×
730
        reader mapInstVarsFor: GHApiFile.
×
731
        reader
×
732
                for: #ArrayOfFile
×
733
                customDo: [ :customMappting | 
×
734
                customMappting listOfElementSchema: GHApiFile ].
×
735
        ^ reader nextAs: #ArrayOfFile
×
736
]
×
737

738
{ #category : #parsing }
739
GithubModelImporter >> parseGroupResult: aResult [
1✔
740

1✔
741
        | reader |
1✔
742
        reader := generalReader on: aResult readStream.
1✔
743
        
1✔
744
        ^ reader nextAs: GLHGroup
1✔
745
]
1✔
746

747
{ #category : #parsing }
748
GithubModelImporter >> parseMergeRequestsResult: response [
×
749

×
750
        | result json|
×
751
        self flag: 'temp version, must remade using NeoJsonReader'.
×
752
        json := NeoJSONReader fromString: response.
×
753
        
×
754
        result := json collect: [ :aPull |
×
755
                          GLHMergeRequest new
×
756
                                  id: (aPull at: #id);
×
757
                                  title: (aPull at: #title);
×
758
                                  state: (aPull at: #state);
×
759
                                  closed_at:
×
760
                                          ((aPull at: #closed_at) ifNotNil: #asDateAndTime);
×
761
                                  merged_at:
×
762
                                          ((aPull at: #merged_at) ifNotNil: #asDateAndTime);
×
763
                                  updated_at:
×
764
                                          ((aPull at: #updated_at) ifNotNil: #asDateAndTime);
×
765
                                  created_at:
×
766
                                          ((aPull at: #created_at) ifNotNil: #asDateAndTime);
×
767
                                  sha: (aPull at: #head at: #sha);
×
768
                                  merge_commit_sha: (aPull at: #merge_commit_sha) ].
×
769
        result := self glhModel addAll: result unless: self blockOnIdEquality.
×
770
        ^ result
×
771
]
×
772

773
{ #category : #parsing }
774
GithubModelImporter >> parsePipelinesResult: pipelineOverview [
1✔
775

1✔
776
        | reader |
1✔
777
        reader := generalReader on: pipelineOverview readStream.
1✔
778

1✔
779
        reader for: GHAPIPipelineOverview do: [ :mapping |
1✔
780
                mapping mapInstVar: #total_count to: #total_count.
1✔
781
                (mapping mapInstVar: #workflow_runs) valueSchema: #ArrayOfPipeline ].
1✔
782

1✔
783

1✔
784
        ^ reader nextAs: GHAPIPipelineOverview
1✔
785
]
1✔
786

787
{ #category : #parsing }
788
GithubModelImporter >> parseProjectResult: aResult [
×
789

×
790
        | reader |
×
NEW
791

×
NEW
792
        reader := generalReader on: aResult readStream.
×
NEW
793

×
794
        ^ reader nextAs: GLHProject
×
795
]
×
796

797
{ #category : #parsing }
798
GithubModelImporter >> parseUserResult: result [
1✔
799

1✔
800
        | reader |
1✔
801
        reader := generalReader on: result readStream.
1✔
802

1✔
803
        ^ reader nextAs: GLHUser
1✔
804
]
1✔
805

806
{ #category : #api }
807
GithubModelImporter >> privateToken [
×
808
        ^ self api privateToken
×
809
]
×
810

811
{ #category : #api }
812
GithubModelImporter >> privateToken: aTokenString [
×
813
        ^ self repoApi privateToken: aTokenString
×
814
]
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc