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

moosetechnology / GitProjectHealth / 18011396276

25 Sep 2025 02:48PM UTC coverage: 77.799% (+4.5%) from 73.342%
18011396276

Pull #233

github

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

4095 of 4342 new or added lines in 42 files covered. (94.31%)

26 existing lines in 6 files now uncovered.

22407 of 28801 relevant lines covered (77.8%)

0.78 hits per line

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

71.86
/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
                (mapping mapInstVar: #diffs to: #files) valueSchema: #ArrayOfDiff. 
1✔
134
                        
1✔
135
                         ].
1✔
136

1✔
137
        reader for: DateAndTime customDo: [ :mapping |
1✔
138
                mapping decoder: [ :string | DateAndTime fromString: string ] ].
1✔
139

1✔
140
        reader for: #ArrayOfId customDo: [ :mapping |
1✔
141
                mapping decoder: [ :parents |
1✔
142
                        parents collect: [ :parent | parent at: #sha ] ] ]
1✔
143
]
1✔
144

145
{ #category : #'private - configure reader' }
146
GithubModelImporter >> configureReaderForDiff: reader [
1✔
147

1✔
148
        super configureReaderForDiff: reader.
1✔
149

1✔
150
        reader for: GLHDiff do: [ :mapping |
1✔
151
                mapping mapInstVar: #new_path to: #filename.
1✔
152
                mapping mapInstVar: #old_path to: #filename.
1✔
153
                mapping mapInstVar: #diffString to: #patch. ]
1✔
154
]
1✔
155

156
{ #category : #'private - configure reader' }
157
GithubModelImporter >> configureReaderForGroup: reader [
1✔
158

1✔
159
        super configureReaderForGroup: reader.
1✔
160
        
1✔
161
        reader
1✔
162
                for: GLHGroup
1✔
163
                do: [ :mapping | mapping mapInstVar: #web_url to: #html_url ]
1✔
164
]
1✔
165

166
{ #category : #'private - configure reader' }
167
GithubModelImporter >> configureReaderForMergeRequest: reader [
1✔
168
        "        reader mapInstVarsFor: GLHProject. "
1✔
169

1✔
170
        super configureReaderForMergeRequest: reader.
1✔
171
        
1✔
172
        reader for: GLHMergeRequest do: [ :mapping |
1✔
173
                (mapping mapInstVar: #created_at) valueSchema: DateAndTime.
1✔
174
                (mapping mapInstVar: #updated_at) valueSchema: DateAndTime.
1✔
175
                (mapping mapInstVar: #merged_at) valueSchema: DateAndTime.
1✔
176
                (mapping mapInstVar: #closed_at) valueSchema: DateAndTime.
1✔
177

1✔
178
                mapping
1✔
179
                        mapProperty: #author
1✔
180
                        getter: [  ]
1✔
181
                        setter: [ :object :value |
1✔
182
                        object cacheAt: #authorID put: (value at: #id) ].
1✔
183
                mapping
1✔
184
                        mapProperty: #merge_user
1✔
185
                        getter: [  ]
1✔
186
                        setter: [ :object :value |
1✔
187
                                value ifNotNil: [
1✔
188
                                        object cacheAt: #mergeUserID put: (value at: #id) ] ] ].
1✔
189

1✔
190

1✔
191

1✔
192
]
1✔
193

194
{ #category : #'private - configure reader' }
195
GithubModelImporter >> configureReaderForPipeline: reader [
1✔
196

1✔
197
        super configureReaderForPipeline: reader.
1✔
198

1✔
199
        reader for: GLHPipeline do: [ :mapping |
1✔
200
                "mapping mapInstVar: #status to: #conclusion."
1✔
201

1✔
202
                mapping
1✔
203
                        mapProperty: #status
1✔
204
                        getter: [ :object | #ignore ]
1✔
205
                        setter: [ :object :value |
1✔
206
                        (object status isNil and: [value isNotNil]) ifTrue: [ object status: value ].
1✔
207
                         ].
1✔
208

1✔
209
                mapping
1✔
210
                        mapProperty: #conclusion
1✔
211
                        getter: [ :object | #ignore ]
1✔
212
                        setter: [ :object :value |
1✔
213
                        (object status isNil and: [value isNotNil]) ifTrue: [ object status: value ]. ].
1✔
214
                
1✔
215
                mapping
1✔
216
                        mapProperty: #run_started_at
1✔
217
                        getter: [ :object | #ignore ]
1✔
218
                        setter: [ :object :value |
1✔
219
                        object runDate: (DateAndTime fromString: value) ] ]
1✔
220
]
1✔
221

222
{ #category : #'private - configure reader' }
223
GithubModelImporter >> configureReaderForProject: reader [
1✔
224

1✔
225
        super configureReaderForProject: reader.
1✔
226
        
1✔
227
        reader for: GLHProject do: [ :mapping |
1✔
228
                mapping mapInstVar: #web_url to: #html_url.
1✔
229
         ].
1✔
230

1✔
231
]
1✔
232

233
{ #category : #'private - configure reader' }
234
GithubModelImporter >> configureReaderForUser: reader [
1✔
235
        super configureReaderForUser: reader.
1✔
236
        
1✔
237
        
1✔
238
                reader for: GLHUser do: [ :mapping |
1✔
239
                mapping mapInstVar: #public_email to: #email.
1✔
240
                mapping mapInstVar: #username to: #login.
1✔
241
                mapping mapInstVar: #bio to: #bio.
1✔
242
                mapping mapInstVar: #organization to: #company.
1✔
243
                mapping mapInstVar: #web_url to: #html_url.
1✔
244
 ].
1✔
245
]
1✔
246

247
{ #category : #private }
248
GithubModelImporter >> convertApiFileAsFile: aAPIFile [
×
249

×
250
        aAPIFile type = 'dir' ifTrue: [ 
×
251
                ^ GLHFileDirectory new
×
252
                          name: aAPIFile name;
×
253
                          yourself ].
×
254
        ^ GLHFileBlob new
×
255
                  name: aAPIFile name;
×
256
                  yourself
×
257
]
×
258

259
{ #category : #'import - groups' }
260
GithubModelImporter >> ensureGroupNamed: aGroupName [
×
261

×
NEW
262
        self flag: 'WARNING: group from different platform (github vs gitlab) can share the same name, thus being confused here'. 
×
263
        ^ self glhModel
×
264
                  detect: [ :a |
×
265
                  (a isKindOf: GLHGroup) and: [ a name = aGroupName ] ]
×
266
                  ifNone: [ self glhModel newGroupNamed: aGroupName ]
×
267
]
×
268

269
{ #category : #'import - repositories' }
270
GithubModelImporter >> importBranchesOf: aGLHProject [
1✔
271
        "add the pipeline (actions runs) in the project"
1✔
272

1✔
273
        | branchesResults foundBranches branches |
1✔
274
        branchesResults := self repoApi branches
1✔
275
                                   getAllForRepo: aGLHProject name
1✔
276
                                   ofOwner: aGLHProject group name.
1✔
277

1✔
278
        foundBranches := (branchesResults collect: [ :branchesResult |
1✔
279
                                  self parseBranchesResult: branchesResult ])
1✔
280
                                 flattened.
1✔
281

1✔
282

1✔
283
        "WARNING: always add branch first into repository, than into model !"
1✔
284
        branches := aGLHProject repository branches
1✔
285
                            addAll: foundBranches
1✔
286
                            unless: self blockOnNameEquality.
1✔
287

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

1✔
290
        branches := self glhModel
1✔
291
                            addAll: branches
1✔
292
                            unless: self blockForBranchEquality.
1✔
293

1✔
294
        self withFiles ifTrue: [
1✔
295
                branches do: [ :branch | self importFilesOfBranch: branch ] ].
1✔
296
        
1✔
297
        ^branches.
1✔
298
]
1✔
299

300
{ #category : #'import - commits' }
301
GithubModelImporter >> importCommit: aCommitID ofProject: aGLHProject [
1✔
302

1✔
303
        | result parsedResult |
1✔
304
        (self glhModel allWithType: GLHCommit) asOrderedCollection
1✔
305
                detect: [ :commit | commit id = aCommitID ]
1✔
306
                ifFound: [ :commit | ^ commit ].
1✔
307

1✔
308
        result := self repoApi commits
1✔
309
                          get: aCommitID
1✔
310
                          inProject: aGLHProject id.
1✔
311

1✔
312
        parsedResult := self parseCommitResult: result.
1✔
313

1✔
314
        parsedResult := self glhModel
1✔
315
                                add: parsedResult
1✔
316
                                unless: self blockOnIdEquality.
1✔
317
        parsedResult := aGLHProject repository commits
1✔
318
                                add: parsedResult
1✔
319
                                unless: self blockOnIdEquality.
1✔
320

1✔
321
        self withCommitDiffs ifTrue: [ self importDiffOfCommit: parsedResult ].
1✔
322

1✔
323
        ^ parsedResult
1✔
324
]
1✔
325

326
{ #category : #'import - commits' }
327
GithubModelImporter >> importCommitsOfProject: aGLHProject [
1✔
328

1✔
329
        | itemByPage foundCommits tmp pageNumber |
1✔
330
        itemByPage := 100.
1✔
331
        pageNumber := 1.
1✔
332
        ('Extract all commits of ' , aGLHProject name) recordInfo.
1✔
333
        foundCommits := OrderedCollection new.
1✔
334
        ('Extract commits from ' , foundCommits size printString , ' to '
1✔
335
         , (foundCommits size + itemByPage) printString) recordInfo.
1✔
336
        "also check that there is at least one commit with the error handling"
1✔
337
        [
1✔
338
        tmp := self parseCommitsResult: (self repoApi commits
1✔
339
                                getForRepo: aGLHProject name
1✔
340
                                ofOwner: aGLHProject group name
1✔
341
                                withParms: {
1✔
342
                                                (#since -> self withCommitsSince).
1✔
343
                                                (#perPage -> itemByPage).
1✔
344
                                                (#page -> pageNumber) } asDictionary) ]
1✔
345
                on: GHRepositoryEmptyError
1✔
346
                do: [ ^ {  } ].
1✔
347

1✔
348
        foundCommits addAll: tmp.
1✔
349
        [ tmp size = itemByPage ] whileTrue: [
1✔
350
                pageNumber := pageNumber + 1.
1✔
351
                ('Extract issues from ' , foundCommits size printString , ' to '
1✔
352
                 , (foundCommits size + itemByPage) printString) recordInfo.
1✔
353
                tmp := self parseCommitsResult: (self repoApi commits
1✔
354
                                        getForRepo: aGLHProject name
1✔
355
                                        ofOwner: aGLHProject group name
1✔
356
                                        withParms: {
1✔
357
                                                        (#sine -> self withCommitsSince).
1✔
358
                                                        (#perPage -> itemByPage).
1✔
359
                                                        (#page -> pageNumber) } asDictionary).
1✔
360
                foundCommits addAll: tmp ].
1✔
361

1✔
362
        "add the imported commits (unless they are already added to this repository)"
1✔
363
        aGLHProject repository commits
1✔
364
                addAll: foundCommits
1✔
365
                unless: [ :existing :new | existing id = new id ].
1✔
366
        "add the imported commits to the model unles they are already added to the model"
1✔
367
        ^ self glhModel
1✔
368
                  addAll: foundCommits
1✔
369
                  unless: [ :existing :new | existing id = new id ]
1✔
370
]
1✔
371

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

×
375
        | creator |
×
376
        (self glhModel allWithType: GLHUser)
×
377
                detect: [ :user | user username = aGLHCommit author_name ]
×
378
                ifFound: [ :user |
×
379
                        aGLHCommit commitCreator: user.
×
380
                        ^ user ].
×
381

×
382
        aGLHCommit author_name ifNotNil: [ :author_name |
×
383
                creator := self importUserByUsername: author_name.
×
384
                aGLHCommit commitCreator: creator ].
×
385
        ^ creator
×
386
]
×
387

388
{ #category : #'import - diffs' }
389
GithubModelImporter >> importDiffOfCommit: aGLHCommit [
1✔
390

1✔
391
        | result diffs |
1✔
392
        aGLHCommit diffs ifNotEmpty: [
1✔
393
                'Diff already importer: '
1✔
394
                , aGLHCommit short_id printString recordInfo.
1✔
395
                ^ aGLHCommit diffs ].
1✔
396
        ('Import diff of commit: ' , aGLHCommit short_id printString)
1✔
397
                recordInfo.
1✔
398

1✔
399
        result := self repoApi commits
1✔
400
                          getCommit: aGLHCommit id
1✔
401
                          ForRepo: aGLHCommit repository project name
1✔
402
                          ofOwner: aGLHCommit repository project group name.
1✔
403
                
1✔
404
        diffs := (self parseCommitResult: result) diffs.
1✔
405
        
1✔
406
        diffs do: [ :diff | 
1✔
407
                self parseDiffString: diff.
1✔
408
                ].        
1✔
409

1✔
410
        diffs := aGLHCommit diffs
1✔
411
                         addAll: diffs
1✔
412
                         unless: self blockForDiffRangeEquality.
1✔
413
        diffs := glhModel
1✔
414
                         addAll: diffs
1✔
415
                         unless: self blockForDiffRangeEquality.
1✔
416

1✔
417
        ^ aGLHCommit diffs
1✔
418
]
1✔
419

420
{ #category : #'import - merge-requests' }
421
GithubModelImporter >> importDiffOfMergeRequest: aGLHMergeRequest [ 
1✔
422
        |diffsResult|
1✔
423
        
1✔
424
        diffsResult := self importDiffOfCommit: aGLHMergeRequest mergedCommit.
1✔
425
        
1✔
426
        diffsResult := aGLHMergeRequest diffs
1✔
427
                addAll: diffsResult
1✔
428
                unless: self blockForDiffEquality.
1✔
429
        self glhModel
1✔
430
                addAll: diffsResult
1✔
431
                unless: self blockForDiffEquality.
1✔
432

1✔
433
        aGLHMergeRequest diffs do: [ :diff | self importDiffRangesForDiff: diff ].
1✔
434
        ^ aGLHMergeRequest diffs. 
1✔
435
]
1✔
436

437
{ #category : #'import - files' }
438
GithubModelImporter >> importDirectoryFiles: aDirectoryFile OfBranch: aBranch [
×
439

×
440
        | result files apiFiles |
×
441
        ('Explore ' , aDirectoryFile name) recordInfo.
×
442
        result := self api
×
443
                          contentsOfRepo: aBranch repository project name
×
444
                          ofOrganization: aBranch repository project group name
×
445
                          inBranch: aBranch name
×
446
                          withPath: aDirectoryFile path.
×
447
        apiFiles := self parseFileTreeResult: result.
×
448
        files := apiFiles collect: [ :apiFile | 
×
449
                         self convertApiFileAsFile: apiFile ].
×
450
        files do: [ :file | 
×
451
                self glhModel add: file.
×
452
                aDirectoryFile addFile: file ].
×
453
        files
×
454
                select: [ :file | file isKindOf: GLHFileDirectory ]
×
455
                thenCollect: [ :file | 
×
456
                self importDirectoryFiles: file OfBranch: aBranch ]
×
457
]
×
458

459
{ #category : #'import - files' }
460
GithubModelImporter >> importFilesOfBranch: aBranch [
×
461

×
462
        | result files apiFiles |
×
463
        result := self api
×
464
                          contentsOfRepo: aBranch repository project name
×
465
                          ofOrganization: aBranch repository project group name
×
466
                          inBranch: aBranch name
×
467
                          withPath: nil.
×
468
        apiFiles := self parseFileTreeResult: result.
×
469
        files := apiFiles collect: [ :apiFile | 
×
470
                         self convertApiFileAsFile: apiFile ].
×
471
        files do: [ :file | 
×
472
                self glhModel add: file.
×
473
                aBranch addFile: file ].
×
474
        files
×
475
                select: [ :file | file isKindOf: GLHFileDirectory ]
×
476
                thenCollect: [ :file | 
×
NEW
477
                self importDirectoryFiles: file OfBranch: aBranch ].
×
NEW
478
        ^ files
×
UNCOV
479
]
×
480

481
{ #category : #'import - groups' }
482
GithubModelImporter >> importGroup: aGroupName [
1✔
483

1✔
484
        | result groupResult |
1✔
485
        result := self repoApi organizations get: aGroupName.
1✔
486
        groupResult := self parseGroupResult: result.
1✔
487
        self glhModel add: groupResult.
1✔
488
        self importRepositoriesOfGroup: groupResult.
1✔
489
        ^ groupResult
1✔
490
]
1✔
491

492
{ #category : #'import - commits' }
493
GithubModelImporter >> importLatestCommitsOfProject: aGLHProject [
1✔
494
        "limited to the last 50 commits"
1✔
495

1✔
496
        | results parsedResults |
1✔
497
        results := self repoApi commits
1✔
498
                           getLatestForRepo: aGLHProject name
1✔
499
                           ofOwner: aGLHProject group name.
1✔
500
        parsedResults := self parseCommitsResult: results.
1✔
501
        
1✔
502
        
1✔
503
        parsedResults := self glhModel
1✔
504
                                 addAll: parsedResults
1✔
505
                                 unless: self blockOnIdEquality.
1✔
506

1✔
507
        aGLHProject repository commits
1✔
508
                addAll: parsedResults
1✔
509
                unless: self blockOnIdEquality.
1✔
510

1✔
511
        self withCommitDiffs ifTrue: [
1✔
512
                parsedResults do: [ :commit | 
1✔
513
                        self importDiffOfCommit: commit. 
1✔
514
                        
1✔
515
                         ] ].
1✔
516

1✔
517
        ^ parsedResults
1✔
518
]
1✔
519

520
{ #category : #'import - merge-requests' }
521
GithubModelImporter >> importLatestMergeRequestsOfProject: aGLHProject [ 
1✔
522
        
1✔
523
        | results parsedResults |
1✔
524
        results := self repoApi pullRequests getLatestForRepo: aGLHProject name ofOwner:  aGLHProject group name.
1✔
525
        parsedResults := self parseMergeRequestsResult: results.
1✔
526

1✔
527
        parsedResults := glhModel
1✔
528
                                 addAll: parsedResults
1✔
529
                                 unless: self blockOnIdEquality.
1✔
530
        parsedResults := aGLHProject mergeRequests
1✔
531
                                 addAll: parsedResults
1✔
532
                                 unless: self blockOnIdEquality.
1✔
533
        ^ parsedResults
1✔
534
]
1✔
535

536
{ #category : #'import - merge-requests' }
NEW
537
GithubModelImporter >> importLatestPullRequestsOfProject: aGLHProject [
×
NEW
538
        "alias method since PullRequest = MergeRequest in model"
×
NEW
539
        ^ self importLatestMergeRequestsOfProject: aGLHProject 
×
NEW
540
]
×
541

542
{ #category : #'import - merge-requests' }
543
GithubModelImporter >> importMergeRequestMergeCommits: aGLHMergeRequest [
1✔
544

1✔
545
        | foundCommits |
1✔
546
        foundCommits := OrderedCollection new.
1✔
547

1✔
548
        ('Import commit sha of MR:  ' , aGLHMergeRequest iid printString)
1✔
549
                recordInfo.
1✔
550
        "the founds commits are added to the model during their respective import"
1✔
551
        aGLHMergeRequest mergeRequestCommit: ((self
1✔
552
                          importCommit: aGLHMergeRequest sha
1✔
553
                          ofProject: aGLHMergeRequest project) ifNotNil: [ :commit |
1✔
554
                         foundCommits add: commit ]).
1✔
555

1✔
556
        ('Import commit merge_commit_sha of MR:  '
1✔
557
         , aGLHMergeRequest iid printString) recordInfo.
1✔
558
        aGLHMergeRequest mergedCommit: ((self
1✔
559
                          importCommit: aGLHMergeRequest merge_commit_sha
1✔
560
                          ofProject: aGLHMergeRequest project) ifNotNil: [ :commit |
1✔
561
                         foundCommits add: commit ]).
1✔
562

1✔
563
        ('Import commit squash_commit_sha of MR:  '
1✔
564
         , aGLHMergeRequest iid printString) recordInfo.
1✔
565
        aGLHMergeRequest squashCommit: ((self
1✔
566
                          importCommit: aGLHMergeRequest squash_commit_sha
1✔
567
                          ofProject: aGLHMergeRequest project) ifNotNil: [ :commit |
1✔
568
                         foundCommits add: commit ]).
1✔
569

1✔
570

1✔
571
        self chainsCommitsFrom: foundCommits.
1✔
572
        ^ foundCommits
1✔
573
]
1✔
574

575
{ #category : #'import - merge-requests' }
576
GithubModelImporter >> importMergeRequestsOfProject: aGLHProject [
1✔
577

1✔
578
        | response mergeRequests |
1✔
579
        response := self repoApi pullRequests
1✔
580
                            getLatestForRepo: aGLHProject name
1✔
581
                            ofOwner: aGLHProject group name.
1✔
582
        mergeRequests := self parseMergeRequestsResult: response.
1✔
583

1✔
584
        mergeRequests := aGLHProject mergeRequests
1✔
585
                                 addAll: mergeRequests
1✔
586
                                 unless: self blockOnIdEquality.
1✔
587
                
1✔
588
        "gets it related commits"
1✔
589
        aGLHProject mergeRequests do: [ :mr |
1✔
590
                self importMergeRequestMergeCommits: mr ].
1✔
591

1✔
592

1✔
593
        self withCommitDiffs ifTrue: [
1✔
594
                aGLHProject mergeRequests do: [ :mr |
1✔
595
                        self importDiffOfMergeRequest: mr ] ].
1✔
596
        
1✔
597
        ^ mergeRequests
1✔
598
]
1✔
599

600
{ #category : #'import - pipelines' }
601
GithubModelImporter >> importPipelinesOfProject: project [
1✔
602

1✔
603
        "add the pipeline (actions runs) in the project"
1✔
604

1✔
605
        | pipelinesResult ghApiPipelineOverview |
1✔
606
        pipelinesResult := self repoApi actions
1✔
607
                                   getLatestForRepo: project name
1✔
608
                                   ofOwner: project group name.
1✔
609
        ghApiPipelineOverview := self parsePipelinesResult: pipelinesResult.
1✔
610
        ghApiPipelineOverview workflow_runs do: [ :pipeline | 
1✔
611
                project addPipeline: pipeline ]
1✔
612
]
1✔
613

614
{ #category : #'import - projects' }
615
GithubModelImporter >> importProject: aProjectName ofGroup: aGroupName [
×
616

×
617
        | result projectResult group |
×
618
        group := self ensureGroupNamed: aGroupName.
×
NEW
619
        result := self repoApi organizations getRepository: aProjectName ofOrganization: aGroupName .
×
620
        projectResult := self parseProjectResult: result.
×
621
        projectResult group: group.
×
622
        self glhModel add: projectResult.
×
623
        self completeImportedProject: projectResult.
×
624
        ^ projectResult
×
625
]
×
626

627
{ #category : #'import - merge-requests' }
NEW
628
GithubModelImporter >> importPullRequestsOfProject: aProject [
×
NEW
629
        "alias method since PullRequest = MergeRequest in model"
×
NEW
630

×
NEW
631
        ^ self importMergeRequestsOfProject: aProject
×
NEW
632
]
×
633

634
{ #category : #'import - groups' }
635
GithubModelImporter >> importRepositoriesOfGroup: groupResult [
1✔
636
        "Github Repository = GLHProject"
1✔
637

1✔
638
        | reposResult itemByPage pageNumber reposFound tmp |
1✔
639
        itemByPage := 100.
1✔
640
        pageNumber := 1.
1✔
641
        ('Extract all repository of ' , groupResult name) recordInfo.
1✔
642
        reposFound := OrderedCollection new.
1✔
643
        ('Extract commits from ' , reposFound size printString , ' to '
1✔
644
         , (reposFound size + itemByPage) printString) recordInfo.
1✔
645
        tmp := self parseArrayOfProject: (self repoApi
1✔
646
                                organizations getRepositoriesOfOrganization: groupResult name
1✔
647
                                perPage: itemByPage
1✔
648
                                page: pageNumber).
1✔
649

1✔
650
        reposFound addAll: tmp.
1✔
651
        [ tmp size = itemByPage ] whileTrue: [
1✔
652
                pageNumber := pageNumber + 1.
1✔
653
                ('Extract issues from ' , reposFound size printString , ' to '
1✔
654
                 , (reposFound size + itemByPage) printString) recordInfo.
1✔
655
                tmp := self parseArrayOfProject: (self repoApi
1✔
656
                                        reposOfOrganization: groupResult name
1✔
657
                                        perPage: itemByPage
1✔
658
                                        page: pageNumber).
1✔
659
                reposFound addAll: tmp ].
1✔
660

1✔
661
        reposResult := self repoApi organizations getRepositoriesOfOrganization: groupResult name.
1✔
662
        groupResult projects addAll: reposFound.
1✔
663
        self glhModel addAll: groupResult projects.
1✔
664
        groupResult projects do: [ :project |
1✔
665
                self completeImportedProject: project ].
1✔
666
        ^ groupResult
1✔
667
]
1✔
668

669
{ #category : #'import - users' }
670
GithubModelImporter >> importUser: userID [
1✔
671

1✔
672
        | result userResult |
1✔
673
        (glhModel allWithType: GLHUser)
1✔
674
                detect: [ :user | user id = userID ]
1✔
675
                ifFound: [ :user | ^ user ].
1✔
676
        ('Import user: ' , userID printString) recordInfo.
1✔
677
        result := self repoApi users getUserId: userID.
1✔
678
        userResult := self parseUserResult: result.
1✔
679
        ^ glhModel
1✔
680
                  add: userResult
1✔
681
                  unless: [ :current :new | current id = new id ]
1✔
682
]
1✔
683

684
{ #category : #'import - users' }
NEW
685
GithubModelImporter >> importUserByUsername: anUsername [
×
NEW
686

×
NEW
687
        | dicUsername resultUser |
×
NEW
688
        dicUsername := ((self glhModel allWithType: GLHUser) collect: [ :user |
×
NEW
689
                                user username -> user ]) asSet asDictionary.
×
NEW
690

×
NEW
691
        dicUsername addAll: self userCatalogue collectUsernames.
×
NEW
692

×
NEW
693

×
NEW
694
        resultUser := dicUsername
×
NEW
695
                              at: anUsername
×
NEW
696
                              ifAbsent: [ "thus we have to import this new user"
×
NEW
697
                                      | userId searchResult |
×
NEW
698
                                      ('Import user with username: '
×
NEW
699
                                       , anUsername printString) recordInfo.
×
NEW
700

×
NEW
701
                                      searchResult := self repoApi users getUsername: anUsername.
×
NEW
702

×
NEW
703
                                      (searchResult class = Dictionary and: [
×
NEW
704
                                               (searchResult at: #status) includesSubstring:
×
NEW
705
                                                       '404' ])
×
NEW
706
                                              ifTrue: [ "if the result is an 403 error we fake a new user"
×
NEW
707
                                                      self glhModel
×
NEW
708
                                                              add: (GLHUser new
×
NEW
709
                                                                               username: anUsername;
×
NEW
710
                                                                               name: anUsername;
×
NEW
711
                                                                               yourself)
×
NEW
712
                                                              unless: [ :nu :ou | nu username = ou username ] ]
×
NEW
713
                                              ifFalse: [
×
NEW
714
                                                      searchResult
×
NEW
715
                                                              ifEmpty: [ "results can be empty thus we force a new user with the info we have "
×
NEW
716
                                                                      self glhModel
×
NEW
717
                                                                              add: (GLHUser new
×
NEW
718
                                                                                               username: anUsername;
×
NEW
719
                                                                                               name: anUsername;
×
NEW
720
                                                                                               yourself)
×
NEW
721
                                                                              unless: [ :nu :ou | nu username = ou username ] ]
×
NEW
722
                                                              ifNotEmpty: [ "because we may already have the researched user, we look by ID in the model"
×
NEW
723
                                                                      userId := searchResult first at: #id.
×
NEW
724
                                                                      (self glhModel allWithType: GLHUser)
×
NEW
725
                                                                              detect: [ :user | user id = userId ]
×
NEW
726
                                                                              ifNone: [ self importUser: userId ] ] ] ].
×
NEW
727

×
NEW
728
        self userCatalogue addUser: resultUser withName: anUsername.
×
NEW
729

×
NEW
730
        ^ resultUser
×
NEW
731
]
×
732

733
{ #category : #initialization }
734
GithubModelImporter >> initReader [
1✔
735

1✔
736
        super initReader. 
1✔
737
]
1✔
738

739
{ #category : #initialization }
740
GithubModelImporter >> initialize [
1✔
741

1✔
742
        super initialize.
1✔
743
        self repoApi: GithubApi new.
1✔
744
        self repoApi output: 'json'.
1✔
745
        self withCommitDiffs: true.
1✔
746
        withFiles := false
1✔
747
]
1✔
748

749
{ #category : #parsing }
750
GithubModelImporter >> parseArrayOfProject: arrayOfProjects [
1✔
751

1✔
752
        | reader |
1✔
753
        " reader := NeoJSONReader on: arrayOfProjects readStream.
1✔
754
        
1✔
755
        reader
1✔
756
                for: #ArrayOfProjects
1✔
757
                customDo: [ :customMappting | 
1✔
758
                customMappting listOfElementSchema: GLHProject ].
1✔
759
        
1✔
760
        reader for: GLHProject do: [ :mapping | 
1✔
761
                mapping mapInstVar: #name to: #name.
1✔
762
                mapping mapInstVar: #description to: #description.
1✔
763
                mapping mapInstVar: #id to: #id.
1✔
764
                mapping mapInstVar: #archived to: #archived.
1✔
765
                mapping mapInstVar: #web_url to: #html_url.
1✔
766
                mapping mapInstVar: #topics to: #topics ].
1✔
767
        ^ reader nextAs: #ArrayOfProjects
1✔
768
        "
1✔
769
        reader := generalReader on: arrayOfProjects readStream.
1✔
770

1✔
771
        ^ reader nextAs: #ArrayOfProject
1✔
772
]
1✔
773

774
{ #category : #parsing }
775
GithubModelImporter >> parseBranchesResult: arrayOfBranch [
1✔
776

1✔
777
        | reader |
1✔
778
        reader := generalReader on: arrayOfBranch readStream.
1✔
779

1✔
780
        ^ reader nextAs: #ArrayOfBranch
1✔
781
]
1✔
782

783
{ #category : #parsing }
784
GithubModelImporter >> parseCommitResult: result [
1✔
785
        | reader |
1✔
786
        
1✔
787
        reader := generalReader on: result readStream.
1✔
788

1✔
789
        ^ reader nextAs: GLHCommit 
1✔
790
]
1✔
791

792
{ #category : #parsing }
793
GithubModelImporter >> parseCommitsResult: result [
1✔
794

1✔
795
        | reader |
1✔
796
        (result includesSubstring: '"status":"409"') ifTrue: [
1✔
797
                GHRepositoryEmptyError signal: 'Git Repository is empty' ].
1✔
798

1✔
799
        reader := generalReader on: result readStream.
1✔
800

1✔
801
        ^ reader nextAs: #ArrayOfCommit
1✔
802
]
1✔
803

804
{ #category : #parsing }
805
GithubModelImporter >> parseDiffresult: response [
×
806

×
807
        | result |
×
808
        result := (response at: #files) collect: [ :file |
×
809
                          GLHDiff new
×
810
                                  diffString: (file at: #patch);
×
811
                                  old_path: (file at: #filename);
×
812
                                  new_path: (file at: #filename) ].
×
813

×
814
        ^ result
×
815
]
×
816

817
{ #category : #parsing }
818
GithubModelImporter >> parseFileTreeResult: aResult [
×
819

×
820
        | reader |
×
821
        reader := NeoJSONReader on: aResult readStream.
×
822
        reader mapInstVarsFor: GHApiFile.
×
823
        reader
×
824
                for: #ArrayOfFile
×
825
                customDo: [ :customMappting | 
×
826
                customMappting listOfElementSchema: GHApiFile ].
×
827
        ^ reader nextAs: #ArrayOfFile
×
828
]
×
829

830
{ #category : #parsing }
831
GithubModelImporter >> parseGroupResult: aResult [
1✔
832

1✔
833
        | reader |
1✔
834
        reader := generalReader on: aResult readStream.
1✔
835
        
1✔
836
        ^ reader nextAs: GLHGroup
1✔
837
]
1✔
838

839
{ #category : #parsing }
840
GithubModelImporter >> parseMergeRequestsResult: response [
1✔
841

1✔
842
        | result json|
1✔
843
        self flag: 'temp version, must remade using NeoJsonReader'.
1✔
844
        json := NeoJSONReader fromString: response.
1✔
845
        
1✔
846
        result := json collect: [ :aPull |
1✔
847
                          GLHMergeRequest new
1✔
848
                                  id: (aPull at: #id);
1✔
849
                                  title: (aPull at: #title);
1✔
850
                                  state: (aPull at: #state);
1✔
851
                                  closed_at:
1✔
852
                                          ((aPull at: #closed_at) ifNotNil: #asDateAndTime);
1✔
853
                                  merged_at:
1✔
854
                                          ((aPull at: #merged_at) ifNotNil: #asDateAndTime);
1✔
855
                                  updated_at:
1✔
856
                                          ((aPull at: #updated_at) ifNotNil: #asDateAndTime);
1✔
857
                                  created_at:
1✔
858
                                          ((aPull at: #created_at) ifNotNil: #asDateAndTime);
1✔
859
                                  sha: (aPull at: #head at: #sha);
1✔
860
                                  merge_commit_sha: (aPull at: #merge_commit_sha) ].
1✔
861
        result := self glhModel addAll: result unless: self blockOnIdEquality.
1✔
862
        ^ result
1✔
863
]
1✔
864

865
{ #category : #parsing }
866
GithubModelImporter >> parsePipelinesResult: pipelineOverview [
1✔
867

1✔
868
        | reader |
1✔
869
        reader := generalReader on: pipelineOverview readStream.
1✔
870

1✔
871
        reader for: GHAPIPipelineOverview do: [ :mapping |
1✔
872
                mapping mapInstVar: #total_count to: #total_count.
1✔
873
                (mapping mapInstVar: #workflow_runs) valueSchema: #ArrayOfPipeline ].
1✔
874

1✔
875

1✔
876
        ^ reader nextAs: GHAPIPipelineOverview
1✔
877
]
1✔
878

879
{ #category : #parsing }
880
GithubModelImporter >> parseProjectResult: aResult [
×
881

×
882
        | reader |
×
NEW
883

×
NEW
884
        reader := generalReader on: aResult readStream.
×
NEW
885

×
886
        ^ reader nextAs: GLHProject
×
887
]
×
888

889
{ #category : #parsing }
890
GithubModelImporter >> parseUserResult: result [
1✔
891

1✔
892
        | reader |
1✔
893
        reader := generalReader on: result readStream.
1✔
894

1✔
895
        ^ reader nextAs: GLHUser
1✔
896
]
1✔
897

898
{ #category : #api }
899
GithubModelImporter >> privateToken [
×
900
        ^ self api privateToken
×
901
]
×
902

903
{ #category : #api }
904
GithubModelImporter >> privateToken: aTokenString [
×
905
        ^ self repoApi privateToken: aTokenString
×
906
]
×
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