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

moosetechnology / GitProjectHealth / 10870371582

15 Sep 2024 10:48AM UTC coverage: 35.962% (+2.3%) from 33.667%
10870371582

Pull #55

github

web-flow
Merge a5fe468b1 into 48c9c9c78
Pull Request #55: Agg generic importer and improve github importer

337 of 497 new or added lines in 8 files covered. (67.81%)

5 existing lines in 4 files now uncovered.

3060 of 8509 relevant lines covered (35.96%)

0.36 hits per line

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

54.84
/src/GitLabHealth-Model-Importer/GLHModelImporter.class.st
1
Class {
2
        #name : 'GLHModelImporter',
3
        #superclass : 'GPModelImporter',
4
        #instVars : [
5
                'glhApi',
6
                'withCommitDiffs',
7
                'withInitialCommits',
8
                'withInitialMergeRequest',
9
                'generalReader'
10
        ],
11
        #classVars : [
12
                'currentImporter'
13
        ],
14
        #category : 'GitLabHealth-Model-Importer',
15
        #package : 'GitLabHealth-Model-Importer'
16
}
17

18
{ #category : 'accessing' }
19
GLHModelImporter class >> current [
×
20

×
21
        ^ currentImporter
×
22
]
×
23

24
{ #category : 'private - api' }
25
GLHModelImporter >> addCommits: commitsList toRepository: aProjectRepository [
×
26
        "I take a list of GLHCommit. But some might have been parsed but are already on the model..."
×
27

×
28
        "I return the list of added commits"
×
29

×
30
        | existingCommits newlyFoundCommit |
×
31
        existingCommits := aProjectRepository mooseModel allWithType:
×
32
                                   GLHCommit.
×
33
        newlyFoundCommit := commitsList reject: [ :commitParsed |
×
34
                                    existingCommits anySatisfy: [ :existingCommit |
×
35
                                            existingCommit id = commitParsed id ] ].
×
36
        aProjectRepository mooseModel addAll: newlyFoundCommit.
×
37
        aProjectRepository commits addAll: newlyFoundCommit.
×
38
        ^ newlyFoundCommit
×
39
]
×
40

41
{ #category : 'private' }
42
GLHModelImporter >> addGroupResultToModel: groupResult [
1✔
43
        |group|
1✔
44
        group := self glhModel add: groupResult unless: self blockOnIdEquality.
1✔
45
        self glhModel
1✔
46
                addAll: group projects
1✔
47
                unless: self blockOnIdEquality.
1✔
48
        ^ group 
1✔
49
]
1✔
50

51
{ #category : 'as yet unclassified' }
52
GLHModelImporter >> blockEqualityOn: aSymbol [
1✔
53
        ^ [ :existing :new |
1✔
54
          (existing perform: aSymbol) = (new perform: aSymbol) ]
1✔
55
]
1✔
56

57
{ #category : 'equality' }
58
GLHModelImporter >> blockForDiffEquality [
1✔
59
        ^ [ :existing :new |
1✔
60
                        existing diffString size = new diffString size and: [
1✔
61
                                existing diffString = new diffString ] ]
1✔
62
]
1✔
63

64
{ #category : 'equality' }
65
GLHModelImporter >> blockOnIdEquality [
1✔
66

1✔
67
        ^ [ :existing :new |
1✔
68
          existing id = new id ]
1✔
69
]
1✔
70

71
{ #category : 'equality' }
72
GLHModelImporter >> blockOnNameEquality [
1✔
73

1✔
74
        ^ self blockEqualityOn: #name
1✔
75
]
1✔
76

77
{ #category : 'private - api' }
78
GLHModelImporter >> completeImportProject: aGLHProject [
1✔
79

1✔
80
        | importedProject |
1✔
81
        ('Complete import of project: ' , aGLHProject id printString)
1✔
82
                recordInfo.
1✔
83
        importedProject := self glhModel
1✔
84
                                   add: aGLHProject
1✔
85
                                   unless: self blockOnIdEquality.
1✔
86

1✔
87
        self importPipelinesOfProject: importedProject.
1✔
88

1✔
89
        "aGLHProject creator: (self importUser: aGLHProject creator_id)."
1✔
90

1✔
91
        (self importUser: importedProject creator_id) addCreatedProject:
1✔
92
                importedProject.
1✔
93

1✔
94

1✔
95
        importedProject repository: GLHRepository new.
1✔
96
        self glhModel add: importedProject repository.
1✔
97
        self importRepository: importedProject repository.
1✔
98

1✔
99
        ^ importedProject
1✔
100
]
1✔
101

102
{ #category : 'as yet unclassified' }
103
GLHModelImporter >> completeImportedCommit: aCommit [
1✔
104

1✔
105
        ('completing commit: ' , aCommit short_id printString) recordInfo.
1✔
106
        self importCreatorOfCommit: aCommit.
1✔
107

1✔
108
        self withCommitDiffs ifTrue: [
1✔
109
                | diffs |
1✔
110
                aCommit diffs ifEmpty: [
1✔
111
                        diffs := self importDiffOfCommit: aCommit.
1✔
112
                        self glhModel addAll: diffs unless: self blockForDiffEquality ] ].
1✔
113

1✔
114
        ^ aCommit
1✔
115
]
1✔
116

117
{ #category : 'private' }
118
GLHModelImporter >> configureReaderForCommit: reader [
1✔
119

1✔
120
          reader for: GLHCommit do: [ :mapping |
1✔
121
                mapping mapInstVars:
1✔
122
                        #( id short_id title author_name author_email committer_name
1✔
123
                           committer_email message web_url ).
1✔
124
                (mapping mapInstVar: #authored_date) valueSchema: DateAndTime.
1✔
125
                (mapping mapInstVar: #committed_date) valueSchema: DateAndTime.
1✔
126
                (mapping mapInstVar: #created_at) valueSchema: DateAndTime.
1✔
127
                (mapping mapInstVar: #parent_ids) valueSchema: #ArrayOfIds.
1✔
128
                mapping
1✔
129
                        mapProperty: 'stats'
1✔
130
                        getter: [ :el | "Not used" ]
1✔
131
                        setter: [ :commit :value |
1✔
132
                                commit deletions: (value at: #deletions).
1✔
133
                                commit additions: (value at: #additions) ] ].
1✔
134

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

1✔
138
        reader
1✔
139
                for: #ArrayOfIds
1✔
140
                customDo: [ :mapping | mapping decoder: [ :string | string ] ].
1✔
141
  
1✔
142
        reader
1✔
143
                for: #ArrayOfCommit
1✔
144
                customDo: [ :customMappting |
1✔
145
                customMappting listOfElementSchema: GLHCommit ].
1✔
146

1✔
147
]
1✔
148

149
{ #category : 'as yet unclassified' }
150
GLHModelImporter >> configureReaderForDiffs: reader [
1✔
151

1✔
152
        reader for: GLHDiff do: [ :mapping |
1✔
153
                mapping mapInstVars:
1✔
154
                        #( deleted_file new_file new_path old_path renamed_file ).
1✔
155
                mapping mapInstVar: #diffString to: #diff ].
1✔
156

1✔
157
        reader
1✔
158
                for: #ArrayOfDiffs
1✔
159
                customDo: [ :customMappting |
1✔
160
                customMappting listOfElementSchema: GLHDiff ].
1✔
161
        ^ reader
1✔
162
]
1✔
163

164
{ #category : 'private' }
165
GLHModelImporter >> configureReaderForGroup: reader [
1✔
166

1✔
167
        reader for: GLHGroup do: [ :mapping |
1✔
168
                mapping mapInstVars.
1✔
169
                (mapping mapInstVar: #projects) valueSchema: #ArrayOfProjects ].
1✔
170
        reader mapInstVarsFor: GLHProject.
1✔
171
        reader
1✔
172
                for: #ArrayOfProjects
1✔
173
                customDo: [ :customMappting |
1✔
174
                customMappting listOfElementSchema: GLHProject ].
1✔
175
        reader
1✔
176
                for: #ArrayOfGroups
1✔
177
                customDo: [ :customMappting |
1✔
178
                customMappting listOfElementSchema: GLHGroup ]
1✔
179
]
1✔
180

181
{ #category : 'private' }
182
GLHModelImporter >> convertApiFileAsFile: aAPIFile [
×
183

×
184
        aAPIFile type = 'tree' ifTrue: [ 
×
185
                ^ GLHFileDirectory new
×
186
                          name: aAPIFile name;
×
187
                          yourself ].
×
188
        ^ GLHFileBlob new
×
189
                  name: aAPIFile name;
×
190
                  yourself
×
191
]
×
192

193
{ #category : 'as yet unclassified' }
194
GLHModelImporter >> detectEntityType: aType overAttribut: aSelector equalTo: value [
1✔
195

1✔
196
        ^ (self glhModel allWithType: aType) detect: [ :entity |
1✔
197
                  (entity perform: aSelector) = value ] ifNone: [ nil ]. 
1✔
198
]
1✔
199

200
{ #category : 'as yet unclassified' }
201
GLHModelImporter >> filterCommitChanges: aCollection [
1✔
202

1✔
203
        ^ aCollection reject: [ :line |
1✔
204
                  | trimmedLine |
1✔
205
                  trimmedLine := line trimLeft.
1✔
206
                  (trimmedLine beginsWith: '---') or: [
1✔
207
                          (trimmedLine beginsWith: '+++') or: [
1✔
208
                                  trimmedLine beginsWith: '\ No newline at end of file' ] ] ]
1✔
209
]
1✔
210

211
{ #category : 'accessing' }
212
GLHModelImporter >> glhApi [
1✔
213

1✔
214
        ^ glhApi
1✔
215
]
1✔
216

217
{ #category : 'accessing' }
218
GLHModelImporter >> glhApi: anObject [
1✔
219

1✔
220
        glhApi := anObject
1✔
221
]
1✔
222

223
{ #category : 'api' }
UNCOV
224
GLHModelImporter >> importAllGroups [
×
225

×
226
        | page foundGroups newlyFoundGroups |
×
227
        page := 0.
×
228
        foundGroups := OrderedCollection new.
×
229
        newlyFoundGroups := { true }.
×
230
        [ newlyFoundGroups isNotEmpty ] whileTrue: [
×
231
                | results |
×
232
                page := page + 1.
×
233
                results := self glhApi listGroupsWithTopLevelOnly: true page: page.
×
234

×
235
                newlyFoundGroups := generalReader
×
236
                                            on: results readStream;
×
237
                                            nextAs: #ArrayOfGroups.
×
238
                foundGroups addAll: newlyFoundGroups ].
×
239
        ^ foundGroups
×
240
]
×
241

242
{ #category : 'private - api' }
243
GLHModelImporter >> importCommit: aCommitID ofProject: aGLHProject [
×
244

×
245
        | result parsedResult |
×
246
        (glhModel allWithType: GLHCommit) asOrderedCollection
×
247
                detect: [ :commit | commit id = aCommitID ]
×
248
                ifFound: [ :commit | ^ commit ].
×
249
        result := self glhApi
×
250
                          commit: aCommitID
×
251
                          ofProject: aGLHProject id
×
252
                          withStat: false.
×
253
        parsedResult := self parseCommitResult: result.
×
254
        self
×
255
                addCommits: { parsedResult }
×
256
                toRepository: aGLHProject repository.
×
257
        ^ parsedResult
×
258
]
×
259

260
{ #category : 'as yet unclassified' }
261
GLHModelImporter >> importCommitOfProject: anProject withId: anID [
1✔
262

1✔
263
        | commit result |
1✔
264
        anID ifNil: [ ^ nil ].
1✔
265

1✔
266
        ('looking for commit ' , anID printString , ' in project : '
1✔
267
         , anProject id printString) recordInfo.
1✔
268

1✔
269
        commit := (self
1✔
270
                           detectEntityType: GLHCommit
1✔
271
                           overAttribut: #id
1✔
272
                           equalTo: anID) ifNil: [
1✔
273
                          result := self glhApi commit: anID ofProject: anProject id.
1✔
274
                          commit := (self parseCommitsResult: '[' , result , ']')
1✔
275
                                            first.
1✔
276

1✔
277
                          self glhModel add: commit unless: self blockOnIdEquality.
1✔
278
                          commit repository: anProject repository.
1✔
279

1✔
280
                          commit ].
1✔
281

1✔
282
        self withCommitDiffs ifTrue: [ self importDiffOfCommit: commit ].
1✔
283

1✔
284
        ^ commit
1✔
285
]
1✔
286

287
{ #category : 'private - api' }
288
GLHModelImporter >> importCommits: aGLHProject [
1✔
289
        "limited to the last 20 commits"
1✔
290

1✔
291
        | results parsedResults |
1✔
292
        results := self glhApi
1✔
293
                           commitsOfProject: aGLHProject id
1✔
294
                           forRefName: nil
1✔
295
                           since: nil
1✔
296
                           until: nil
1✔
297
                           path: nil
1✔
298
                           author: nil
1✔
299
                           all: nil
1✔
300
                           with_stats: true
1✔
301
                           firstParent: nil
1✔
302
                           order: nil
1✔
303
                           trailers: nil
1✔
304
                           perPage: nil
1✔
305
                           page: nil.
1✔
306
        parsedResults := self parseCommitsResult: results.
1✔
307
        self glhModel addAll: parsedResults unless: self blockOnIdEquality.
1✔
308

1✔
309
        parsedResults do: [ :commit |
1✔
310
                commit repository: aGLHProject repository ].
1✔
311

1✔
312
        self withCommitDiffs ifTrue: [
1✔
313
                parsedResults do: [ :commit | self importDiffOfCommit: commit ] ].
1✔
314
        
1✔
315
        ^ parsedResults. 
1✔
316
]
1✔
317

318
{ #category : 'as yet unclassified' }
319
GLHModelImporter >> importCommitsFollowing: aCommit upToDays: aNumberOfDay [
×
320
        "import the 'n' commits of a project starting from an initial 'aCommit' commit. 
×
321
        Lazy import does not import the entities inside the model"
×
322

×
323
        | date |
×
324
        date := aCommit created_at asDateAndTime.
×
325

×
326
        ^ self
×
327
                  importCommitsOfBranch: aCommit branch
×
328
                  forRefName: aCommit branch name
×
329
                  since: date
×
330
                  until: (date + aNumberOfDay day)
×
331
]
×
332

333
{ #category : 'commit' }
334
GLHModelImporter >> importCommitsOProject: aProject since: fromDate until: toDate [
1✔
335

1✔
336
        | newlyFoundCommit page foundCommit |
1✔
337
        page := 0.
1✔
338
        foundCommit := OrderedCollection new.
1✔
339
        newlyFoundCommit := { true }.
1✔
340
        [ newlyFoundCommit isNotEmpty ] whileTrue: [
1✔
341
                | results |
1✔
342
                page := page + 1.
1✔
343
                ('import commit page ' , page printString) recordInfo.
1✔
344
                results := GLHApi current
1✔
345
                                   commitsOfProject: aProject id
1✔
346
                                   forRefName: nil
1✔
347
                                   since:
1✔
348
                                   (fromDate ifNotNil: [ fromDate asDateAndTime asString ])
1✔
349
                                   until:
1✔
350
                                   (toDate ifNotNil: [ toDate asDateAndTime asString ])
1✔
351
                                   path: nil
1✔
352
                                   author: nil
1✔
353
                                   all: true
1✔
354
                                   with_stats: true
1✔
355
                                   firstParent: nil
1✔
356
                                   order: nil
1✔
357
                                   trailers: nil
1✔
358
                                   perPage: 100
1✔
359
                                   page: page.
1✔
360

1✔
361
                newlyFoundCommit := self parseCommitsResult: results.
1✔
362
                "newlyFoundCommit do: [ :c | c repository: aProject repository ]."
1✔
363

1✔
364
                foundCommit addAll: (aProject repository commits
1✔
365
                        addAll: newlyFoundCommit
1✔
366
                        unless: self blockOnIdEquality). ].
1✔
367

1✔
368

1✔
369
        ^ self glhModel addAll: foundCommit unless: self blockOnIdEquality
1✔
370
]
1✔
371

372
{ #category : 'api' }
373
GLHModelImporter >> importCommitsOf: aGLHProject withStats: aBoolean until: toDate [
×
374

×
375
        | newlyFoundCommit page |
×
376
        
×
377
        self deprecated: [  ] .
×
378
        
×
379
        page := 0.
×
380
        newlyFoundCommit := { true }.
×
381
        [ newlyFoundCommit isNotEmpty ] whileTrue: [
×
382
                | results parsedResults existingCommits |
×
383
                page := page + 1.
×
384
                ('import commit page ' , page printString) recordInfo.
×
385
                results := self glhApi
×
386
                                   commitsOfProject: aGLHProject id
×
387
                                   forRefName: nil
×
388
                                   since: nil
×
389
                                   until: nil
×
390
                                   path: nil
×
391
                                   author: nil
×
392
                                   all: nil
×
393
                                   with_stats: aBoolean
×
394
                                   firstParent: nil
×
395
                                   order: nil
×
396
                                   trailers: nil
×
397
                                   perPage: 100
×
398
                                   page: page.
×
399
                parsedResults := self parseCommitsResult: results.
×
400
                existingCommits := aGLHProject mooseModel allWithType: GLHCommit.
×
401

×
402
                newlyFoundCommit := parsedResults reject: [ :commitParsed |
×
403
                                            (toDate isNil or: [
×
404
                                                     commitParsed committed_date
×
405
                                                     < toDate asDateAndTime ]) or: [
×
406
                                                    existingCommits anySatisfy: [ :existingCommit |
×
407
                                                            existingCommit id = commitParsed id ] ] ].
×
408
                aGLHProject mooseModel addAll: newlyFoundCommit.
×
409
                aGLHProject repository commits addAll: newlyFoundCommit ].
×
410

×
411

×
412
        self withCommitDiffs ifTrue: [
×
413
                aGLHProject repository commits do: [ :commit |
×
414
                        self importDiffOfCommit: commit ] ]
×
415
]
×
416

417
{ #category : 'commit' }
418
GLHModelImporter >> importCommitsOfBranch: aGLHBranch forRefName: refName since: fromDate [
×
419

×
420
        ^ self
×
421
                  importCommitsOfBranch: aGLHBranch
×
422
                  forRefName: aGLHBranch name
×
423
                  since: fromDate
×
424
                  until: nil
×
425
]
×
426

427
{ #category : 'commit' }
428
GLHModelImporter >> importCommitsOfBranch: aGLHBranch forRefName: refName since: fromDate until: toDate [
×
429

×
430
        | newlyFoundCommit page foundCommit|
×
431
        page := 0.
×
432
        foundCommit := OrderedCollection new. 
×
433
        newlyFoundCommit := { true }.
×
434
        [ newlyFoundCommit isNotEmpty ] whileTrue: [
×
435
                | results |
×
436
                page := page + 1.
×
437
                ('import commit page ' , page printString) recordInfo.
×
438
                results := self glhApi
×
439
                                   commitsOfProject: aGLHBranch repository project id
×
440
                                   forRefName: aGLHBranch name
×
441
                                   since:
×
442
                                   (fromDate ifNotNil: [ fromDate asDateAndTime asString ])
×
443
                                   until:
×
444
                                   (toDate ifNotNil: [ toDate asDateAndTime asString ])
×
445
                                   path: nil
×
446
                                   author: nil
×
447
                                   all: nil
×
448
                                   with_stats: nil
×
449
                                   firstParent: nil
×
450
                                   order: nil
×
451
                                   trailers: nil
×
452
                                   perPage: 100
×
453
                                   page: page.
×
454

×
455
                newlyFoundCommit := self parseCommitsResult: results.
×
456
        aGLHBranch commits
×
457
                        addAll: newlyFoundCommit
×
458
                        unless: self blockOnIdEquality.
×
459
        foundCommit addAll: newlyFoundCommit.  
×
460
                        ].
×
461

×
462
        self glhModel
×
463
                addAll: aGLHBranch commits
×
464
                unless: self blockOnIdEquality.
×
465

×
466
        "self withCommitDiffs ifTrue: [
×
467
                aGLHBranch commits: [ :commit | self importDiffOfCommit: commit ] ]."
×
468

×
469
        ^ foundCommit
×
470
]
×
471

472
{ #category : 'commit' }
473
GLHModelImporter >> importCommitsOfBranch: aGLHBranch forRefName: refName until: toDate [
×
474

×
475
        ^ self
×
476
                  importCommitsOfBranch: aGLHBranch
×
477
                  forRefName: aGLHBranch name
×
478
                  since: nil
×
479
                  until: toDate
×
480
]
×
481

482
{ #category : 'as yet unclassified' }
483
GLHModelImporter >> importCreatorOfCommit: aCommit [
1✔
484
        
1✔
485
        aCommit commitCreator ifNil: [
1✔
486
                aCommit commitCreator:
1✔
487
                        (self importUserByUsername: aCommit author_name) ]
1✔
488
]
1✔
489

490
{ #category : 'api' }
491
GLHModelImporter >> importDiffOfCommit: aCommit [
1✔
492

1✔
493
        | result diffsResult |
1✔
494
        aCommit diffs ifNotEmpty: [
1✔
495
                'Diff already importer: ' , aCommit short_id printString recordInfo.
1✔
496
                ^ aCommit diffs ].
1✔
497
        ('Import diff of commit: ' , aCommit short_id printString) recordInfo.
1✔
498
        result := self glhApi
1✔
499
                          commitDiff: aCommit id
1✔
500
                          ofProject: aCommit repository project id
1✔
501
                          unidiff: true.
1✔
502
        diffsResult := self newParseDiffResult: result.
1✔
503

1✔
504
        ^ aCommit diffs addAll: diffsResult unless: self blockForDiffEquality.
1✔
505

1✔
506
]
1✔
507

508
{ #category : 'private - api' }
509
GLHModelImporter >> importDirectoryFiles: aDirectoryFile OfBranch: aBranch [
×
510

×
511
        | result files apiFiles |
×
512
        result := self glhApi
×
513
                          treeOfRepository: aBranch repository project id
×
514
                          ofBranch: aBranch name
×
515
                          andPath: aDirectoryFile path , '/'.
×
516
        apiFiles := self parseFileTreeResult: result.
×
517
        files := apiFiles collect: [ :apiFile |
×
518
                         self convertApiFileAsFile: apiFile ].
×
519
        files do: [ :file |
×
520
                
×
521
                self glhModel add: file.
×
522
                aDirectoryFile addFile: file ].
×
523
        files
×
524
                select: [ :file | file isKindOf: GLHFileDirectory ]
×
525
                thenCollect: [ :file |
×
526
                self importDirectoryFiles: file OfBranch: aBranch ]
×
527
]
×
528

529
{ #category : 'private - api' }
530
GLHModelImporter >> importFilesOfBranch: aBranch [
×
531

×
532
        | result files apiFiles |
×
533
        result := self glhApi
×
534
                          treeOfRepository: aBranch repository project id
×
535
                          ofBranch: aBranch name
×
536
                          andPath: nil.
×
537
        apiFiles := self parseFileTreeResult: result.
×
538
        files := apiFiles collect: [ :apiFile | 
×
539
                         self convertApiFileAsFile: apiFile ].
×
540
        files do: [ :file | 
×
541
                self glhModel add: file.
×
542
                aBranch addFile: file ].
×
543
        files
×
544
                select: [ :file | file isKindOf: GLHFileDirectory ]
×
545
                thenCollect: [ :file | 
×
546
                self importDirectoryFiles: file OfBranch: aBranch ]
×
547
]
×
548

549
{ #category : 'api' }
550
GLHModelImporter >> importGroup: aGroupID [
1✔
551

1✔
552
        | result groupResult |
1✔
553
        ('Import group: ' , aGroupID printString) recordInfo.
1✔
554

1✔
555
        result := self glhApi group: aGroupID.
1✔
556
        groupResult := self parseGroupResult: result.
1✔
557
        groupResult := self addGroupResultToModel: groupResult.
1✔
558

1✔
559
        groupResult projects do: [ :project |
1✔
560
                self completeImportProject: project ].
1✔
561

1✔
562
        (self subGroupsOf: aGroupID) do: [ :subGroup |
1✔
563
                
1✔
564
                groupResult subGroups
1✔
565
                        add: (self importGroup: subGroup id)
1✔
566
                        unless: self blockOnIdEquality ].
1✔
567
        ^ groupResult
1✔
568
]
1✔
569

570
{ #category : 'api' }
571
GLHModelImporter >> importJobsOf: aPipeline [
×
572

×
573
        | result jobs |
×
574
        result := self glhApi
×
575
                          jobsOfProject: aPipeline project id
×
576
                          ofPipelines: aPipeline id.
×
577
        jobs := self parseJobsResult: result ofProject: aPipeline project.
×
578
        jobs do: [ :job | aPipeline addJob: job ].
×
579
        self glhModel addAll: jobs
×
580

×
581
]
×
582

583
{ #category : 'commit' }
584
GLHModelImporter >> importParentCommitsOfCommit: aGLHCommit forOnly: number [
×
585

×
586
        | parentsIds commits |
×
587
        commits := OrderedCollection new.
×
588
        number = 0 ifTrue: [
×
589
                ^ commits
×
590
                          add: aGLHCommit;
×
591
                          yourself ].
×
592

×
593
        parentsIds := aGLHCommit parent_ids.
×
594

×
595
        commits addAll: (parentsIds collect: [ :id |
×
596
                         self
×
597
                                 importCommitOfProject: aGLHCommit repository project
×
598
                                 withId: id.
×
599
                         (self selectEntityType: GLHCommit overAttribut: #id equalTo: id)
×
600
                                 first ]).
×
601

×
602

×
603
        ^ commits , (commits collect: [ :parentCommit |
×
604
                   self
×
605
                           importParentCommitsOfCommit: parentCommit
×
606
                           forOnly: number - 1 ]) flatten
×
607
]
×
608

609
{ #category : 'commit' }
610
GLHModelImporter >> importParentCommitsOfCommit: aGLHCommit since: aDate [
×
611

×
612
        | parentsIds commits |
×
613
        commits := OrderedCollection new.
×
614
        aGLHCommit created_at asDateAndTime < aDate asDateAndTime ifTrue: [
×
615
                 
×
616
                ^ commits
×
617
                          add: aGLHCommit;
×
618
                          yourself ].
×
619

×
620
        parentsIds := aGLHCommit parent_ids.
×
621

×
622
        commits addAll: (parentsIds collect: [ :id |
×
623
                         self
×
624
                                 importCommitOfProject: aGLHCommit repository project
×
625
                                 withId: id ]).
×
626

×
627

×
628
        ^ (commits collect: [ :parentCommit |
×
629
                   self importParentCommitsOfCommit: parentCommit since: aDate ])
×
630
                  flatten
×
631
]
×
632

633
{ #category : 'private - api' }
634
GLHModelImporter >> importPipelinesOfProject: aGLHProject [
1✔
635

1✔
636
        (self pipelinesOf: aGLHProject id) do: [ :pipeline |
1✔
637
                self glhModel add: pipeline unless: self blockOnIdEquality .
1✔
638
                aGLHProject pipelines add: pipeline unless: self blockOnIdEquality]
1✔
639
]
1✔
640

641
{ #category : 'imports' }
642
GLHModelImporter >> importProjects [
×
643

×
644
        ^ self importProjectsSince: nil
×
645
]
×
646

647
{ #category : 'projects' }
648
GLHModelImporter >> importProjects: aCollectionOfProjectID [
×
649
        
×
650
        ^ aCollectionOfProjectID collect: [ :id |
×
651
                self importProject: id.
×
652
                 ]
×
653
         
×
654
]
×
655

656
{ #category : 'imports' }
657
GLHModelImporter >> importProjectsSince: since [
×
658
        "heavy import of all projects"
×
659

×
660
        "copy import from commits"
×
661

×
662
        | newlyFoundProjects page foundProject amount |
×
663
        ('import all Projects since: ', since printString) recordInfo.
×
664

×
665
        "number of projects per page"
×
666
        amount := 100.
×
667
        page := 0.
×
668
        foundProject := OrderedCollection new.
×
669
        newlyFoundProjects := { true }.
×
670
        [ newlyFoundProjects isNotEmpty ] whileTrue: [
×
671
                | results |
×
672
                page := page + 1.
×
673
                ('import projects page #' , page printString) recordInfo.
×
674
                
×
675
                results := self glhApi projects: amount since: since page: page.
×
676

×
677
                newlyFoundProjects := glhModel
×
678
                                              addAll: (self parseArrayOfProject: results)
×
679
                                              unless: self blockOnIdEquality.
×
680
                foundProject addAll: newlyFoundProjects ].
×
681

×
682
        ^ foundProject
×
683
]
×
684

685
{ #category : 'private - api' }
686
GLHModelImporter >> importRepository: aGLHRepository [
1✔
687

1✔
688
        | resultBranches branches |
1✔
689
        [
1✔
690
        ('import the repository of project ' , aGLHRepository project name)
1✔
691
                recordInfo.
1✔
692

1✔
693
        resultBranches := self glhApi branchesOfRepository:
1✔
694
                                  aGLHRepository project id.
1✔
695
        branches := self parseBranchesResult: resultBranches.
1✔
696

1✔
697
        ('import the branches of project ') recordInfo.
1✔
698

1✔
699
        branches := aGLHRepository branches
1✔
700
                addAll: branches
1✔
701
                unless: self blockOnNameEquality.
1✔
702
        branches := self glhModel addAll: branches unless: self blockOnNameEquality.
1✔
703

1✔
704

1✔
705
        self withFiles ifTrue: [
1✔
706
                branches do: [ :branch | self importFilesOfBranch: branch ] ] ]
1✔
707
                on: NeoJSONParseError
1✔
708
                do: [
1✔
709
                self inform: aGLHRepository project name , ' has no repository' ]
1✔
710
]
1✔
711

712
{ #category : 'private - api' }
713
GLHModelImporter >> importUser: aUserID [
1✔
714

1✔
715
        | result userResult |
1✔
716
        (glhModel allWithType: GLHUser)
1✔
717
                detect: [ :user | user id = aUserID ]
1✔
718
                ifFound: [ :user | ^ user ].
1✔
719
        ('Import user: ' , aUserID printString) recordInfo.
1✔
720
        result := self glhApi user: aUserID.
1✔
721
        userResult := self parseUserResult: result.
1✔
722
        ^ glhModel add: userResult unless: self blockOnIdEquality
1✔
723
]
1✔
724

725
{ #category : 'user' }
726
GLHModelImporter >> importUserByUsername: anUsername [
1✔
727

1✔
728
        | dicUsername |
1✔
729
        dicUsername := ((self glhModel allWithType: GLHUser) collect: [ :user |
1✔
730
                                user username -> user ]) asSet asDictionary.
1✔
731

1✔
732
        ^ dicUsername at: anUsername ifPresent: [ :user | user ] ifAbsent: [
1✔
733
                  | result userId searchResult |
1✔
734
                  ('Import user with username: ' , anUsername printString)
1✔
735
                          recordInfo.
1✔
736
                  result := self glhApi usersSearchByUsername: anUsername.
1✔
737
                  searchResult := NeoJSONReader fromString: result.
1✔
738

1✔
739
                  (searchResult class = Dictionary and: [
1✔
740
                           (searchResult at: #message) includesSubstring: '403 Forbidden' ])
1✔
741
                          ifTrue: [
1✔
742
                                  glhModel
1✔
743
                                          add: (GLHUser new username: anUsername; name: anUsername; yourself )
1✔
744
                                          unless: [ :nu :ou | nu username = ou username ] ]
1✔
745
                          ifFalse: [
1✔
746
                                  searchResult
1✔
747
                                          ifEmpty: [
1✔
748
                                                  GLHUser new
1✔
749
                                                          username: anUsername;
1✔
750
                                                          yourself ]
1✔
751
                                          ifNotEmpty: [
1✔
752
                                                  userId := searchResult first at: #id.
1✔
753
                                                  (self glhModel allWithType: GLHUser)
1✔
754
                                                          detect: [ :user | user id = userId ]
1✔
755
                                                          ifNone: [ self importUser: userId ] ] ] ]
1✔
756
]
1✔
757

758
{ #category : 'initialization' }
759
GLHModelImporter >> initReader [
1✔
760

1✔
761
        generalReader := NeoJSONReader new.
1✔
762
        self configureReaderForCommit: generalReader.
1✔
763
        self configureReaderForGroup: generalReader.
1✔
764
        self configureReaderForDiffs: generalReader. 
1✔
765
]
1✔
766

767
{ #category : 'initialization' }
768
GLHModelImporter >> initialize [
1✔
769

1✔
770
        super initialize.
1✔
771
        withCommitDiffs := false.
1✔
772
        withInitialCommits := false.
1✔
773
        withInitialMergeRequest := false.
1✔
774
        self initReader.
1✔
775
        currentImporter := self
1✔
776
]
1✔
777

778
{ #category : 'importer' }
779
GLHModelImporter >> loadAllProjectsFromRepositorySoftware [
×
780
        "heavy import that load all the active project inside the model. Only import the project entities"
×
781
        |projects|
×
782
        
×
783
        projects := self glhApi projects. 
×
784
]
×
785

786
{ #category : 'private' }
787
GLHModelImporter >> newParseCommitResult: result [
×
788

×
789
        generalReader  on: result readStream.
×
790

×
791
        ^ generalReader nextAs: GLHCommit
×
792
]
×
793

794
{ #category : 'private' }
795
GLHModelImporter >> newParseDiffResult: result [
1✔
796

1✔
797
        generalReader on: result readStream.
1✔
798
        ^ generalReader nextAs: #ArrayOfDiffs
1✔
799
]
1✔
800

801
{ #category : 'parsing' }
802
GLHModelImporter >> parseArrayOfProject: arrayOfProjects [
×
803

×
804
        | reader |
×
805
        reader := NeoJSONReader on: arrayOfProjects readStream.
×
806
        reader
×
807
                for: #ArrayOfProjects
×
808
                customDo: [ :customMappting |
×
809
                customMappting listOfElementSchema: GLHProject ].
×
810
        reader for: GLHProject do: [ :mapping |
×
811
                mapping mapInstVar: #name to: #name.
×
812
                mapping mapInstVar: #description to: #description.
×
813
                mapping mapInstVar: #id to: #id.
×
814
                mapping mapInstVar: #archived to: #archived.
×
815
                mapping mapInstVar: #web_url to: #html_url.
×
816
                mapping mapInstVar: #topics to: #topics ].
×
817
        ^ reader nextAs: #ArrayOfProjects
×
818
]
×
819

820
{ #category : 'private' }
821
GLHModelImporter >> parseBranchesResult: result [
1✔
822

1✔
823
        | reader |
1✔
824
        reader := NeoJSONReader on: result readStream.
1✔
825
        reader mapInstVarsFor: GLHBranch.
1✔
826
        reader
1✔
827
                for: #ArrayOfBranch
1✔
828
                customDo: [ :customMappting | 
1✔
829
                customMappting listOfElementSchema: GLHBranch ].
1✔
830
        ^ reader nextAs: #ArrayOfBranch
1✔
831
]
1✔
832

833
{ #category : 'private' }
834
GLHModelImporter >> parseCommitResult: result [
×
835

×
836
        | reader |
×
837
        reader := NeoJSONReader on: result readStream.
×
838

×
839
        reader for: GLHCommit do: [ :mapping |
×
840
                mapping mapInstVars:
×
841
                        #( id short_id title author_name author_email committer_name
×
842
                           committer_email message web_url ).
×
843
                (mapping mapInstVar: #authored_date) valueSchema: DateAndTime.
×
844
                (mapping mapInstVar: #committed_date) valueSchema: DateAndTime.
×
845
                (mapping mapInstVar: #created_at) valueSchema: DateAndTime.
×
846
                (mapping mapInstVar: #parent_ids) valueSchema: #ArrayOfIds.
×
847
                mapping
×
848
                        mapProperty: 'stats'
×
849
                        getter: [ :el | "Not used" ]
×
850
                        setter: [ :commit :value |
×
851
                                commit deletions: (value at: #deletions).
×
852
                                commit additions: (value at: #additions) ] ].
×
853

×
854
        reader for: DateAndTime customDo: [ :mapping |
×
855
                mapping decoder: [ :string | DateAndTime fromString: string ] ].
×
856

×
857
        reader
×
858
                for: #ArrayOfIds
×
859
                customDo: [ :mapping | mapping decoder: [ :string | string ] ].
×
860

×
861

×
862
        ^ reader nextAs: GLHCommit
×
863
]
×
864

865
{ #category : 'private' }
866
GLHModelImporter >> parseCommitsResult: result [
1✔
867

1✔
868
        | reader |
1✔
869
        reader := NeoJSONReader on: result readStream.
1✔
870

1✔
871
          reader for: GLHCommit do: [ :mapping |
1✔
872
                mapping mapInstVars:
1✔
873
                        #( id short_id title author_name author_email committer_name
1✔
874
                           committer_email message web_url ).
1✔
875
                (mapping mapInstVar: #authored_date) valueSchema: DateAndTime.
1✔
876
                (mapping mapInstVar: #committed_date) valueSchema: DateAndTime.
1✔
877
                (mapping mapInstVar: #created_at) valueSchema: DateAndTime.
1✔
878
                (mapping mapInstVar: #parent_ids) valueSchema: #ArrayOfIds.
1✔
879
                mapping
1✔
880
                        mapProperty: 'stats'
1✔
881
                        getter: [ :el | "Not used" ]
1✔
882
                        setter: [ :commit :value |
1✔
883
                                commit deletions: (value at: #deletions).
1✔
884
                                commit additions: (value at: #additions) ] ].
1✔
885

1✔
886
        reader for: DateAndTime customDo: [ :mapping |
1✔
887
                mapping decoder: [ :string | DateAndTime fromString: string ] ].
1✔
888

1✔
889
        reader
1✔
890
                for: #ArrayOfIds
1✔
891
                customDo: [ :mapping | mapping decoder: [ :string | string ] ].
1✔
892
  
1✔
893
        reader
1✔
894
                for: #ArrayOfCommit
1✔
895
                customDo: [ :customMappting |
1✔
896
                customMappting listOfElementSchema: GLHCommit ].
1✔
897

1✔
898
        ^ reader nextAs: #ArrayOfCommit
1✔
899
]
1✔
900

901
{ #category : 'private' }
902
GLHModelImporter >> parseDiffResult: result [
1✔
903

1✔
904
        | reader |
1✔
905
        self
1✔
906
                deprecated: 'Use #newParseDiffResult: instead'
1✔
907
                on: '28 June 2024'
1✔
908
                in:
1✔
909
                'Pharo-11.0.0+build.726.sha.aece1b5473acf3830a0e082c1bc3a15d4ff3522b (64 Bit)'.
1✔
910
        reader := NeoJSONReader on: result readStream.
1✔
911
        reader for: GLHDiff do: [ :mapping |
1✔
912
                mapping mapInstVars:
1✔
913
                        #( deleted_file new_file new_path old_path renamed_file ).
1✔
914
                mapping mapInstVar: #diffString to: #diff ].
1✔
915

1✔
916
        reader
1✔
917
                for: #ArrayOfDiffs
1✔
918
                customDo: [ :customMappting |
1✔
919
                customMappting listOfElementSchema: GLHDiff ].
1✔
920
        ^ reader nextAs: #ArrayOfDiffs
1✔
921
]
1✔
922

923
{ #category : 'private' }
924
GLHModelImporter >> parseFileTreeResult: aResult [
×
925

×
926
        | reader |
×
927
        reader := NeoJSONReader on: aResult readStream.
×
928
        reader mapInstVarsFor: GLHApiFile.
×
929
        reader
×
930
                for: #ArrayOfFile
×
931
                customDo: [ :customMappting | 
×
932
                customMappting listOfElementSchema: GLHApiFile ].
×
933
        ^ reader nextAs: #ArrayOfFile
×
934
]
×
935

936
{ #category : 'private' }
937
GLHModelImporter >> parseGroupResult: aResult [
1✔
938

1✔
939
        | reader |
1✔
940

1✔
941
        reader := NeoJSONReader on: aResult readStream.
1✔
942
        reader for: GLHGroup do: [ :mapping |
1✔
943
                mapping mapInstVars.
1✔
944
                (mapping mapInstVar: #projects) valueSchema: #ArrayOfProjects ].
1✔
945
        reader mapInstVarsFor: GLHProject.
1✔
946
        reader
1✔
947
                for: #ArrayOfProjects
1✔
948
                customDo: [ :customMappting |
1✔
949
                customMappting listOfElementSchema: GLHProject ].
1✔
950
        ^ reader nextAs: GLHGroup
1✔
951
]
1✔
952

953
{ #category : 'private' }
954
GLHModelImporter >> parseJobsResult: result ofProject: aProject [
×
955

×
956
        | reader |
×
957
        reader := NeoJSONReader on: result readStream.
×
958
        reader for: GLHJob do: [ :mapping |
×
959
                mapping mapInstVars: #( id allow_failure web_url name ).
×
960

×
961
                mapping
×
962
                        mapProperty: #user
×
963
                        getter: [ :object | #ignore ]
×
964
                        setter: [ :object :value |
×
965
                        object user: (self importUser: (value at: #id)) ].
×
966

×
967
                mapping
×
968
                        mapProperty: #commit
×
969
                        getter: [ :object | #ignore ]
×
970
                        setter: [ :object :value |
×
971
                                value ifNotNil: [
×
972
                                        object commit:
×
973
                                                (self importCommit: (value at: #id) ofProject: aProject) ] ].
×
974

×
975
                mapping
×
976
                        mapProperty: #duration
×
977
                        getter: [ :object | #ignore ]
×
978
                        setter: [ :object :value |
×
979
                        value ifNotNil: [ object duration: value seconds ] ] ].
×
980

×
981
        reader
×
982
                for: #ArrayOfGLHJob
×
983
                customDo: [ :customMappting |
×
984
                customMappting listOfElementSchema: GLHJob ].
×
985
        ^ reader nextAs: #ArrayOfGLHJob
×
986
]
×
987

988
{ #category : 'private' }
989
GLHModelImporter >> parsePipelinesResult: result [
1✔
990

1✔
991
        | reader |
1✔
992
        reader := NeoJSONReader on: result readStream.
1✔
993
        reader mapInstVarsFor: GLHPipeline.
1✔
994
        reader for: GLHPipeline do: [ :mapping |
1✔
995
                mapping
1✔
996
                        mapProperty: #created_at
1✔
997
                        getter: [ :object | #ignore ]
1✔
998
                        setter: [ :object :value |
1✔
999
                        object runDate: (DateAndTime fromString: value) ] ].
1✔
1000
        reader
1✔
1001
                for: #ArrayOfPipelines
1✔
1002
                customDo: [ :customMappting |
1✔
1003
                customMappting listOfElementSchema: GLHPipeline ].
1✔
1004
        ^ reader nextAs: #ArrayOfPipelines
1✔
1005
]
1✔
1006

1007
{ #category : 'private' }
1008
GLHModelImporter >> parseSubGroupResult: aResult [
1✔
1009

1✔
1010
        | reader |
1✔
1011
        reader := NeoJSONReader on: aResult readStream.
1✔
1012
        self configureReaderForGroup: reader.
1✔
1013
        ^ reader nextAs: #ArrayOfGroups
1✔
1014
]
1✔
1015

1016
{ #category : 'private' }
1017
GLHModelImporter >> parseUserResult: result [
1✔
1018

1✔
1019
        | reader |
1✔
1020
        reader := NeoJSONReader on: result readStream.
1✔
1021
        reader mapInstVarsFor: GLHUser.
1✔
1022
        ^ reader nextAs: GLHUser
1✔
1023
]
1✔
1024

1025
{ #category : 'private - api' }
1026
GLHModelImporter >> pipelinesOf: aProjectID [
1✔
1027

1✔
1028
        | result |
1✔
1029
        ('Search pipelines of: ' , aProjectID printString) recordInfo.
1✔
1030
        result := self glhApi pipelinesOfProject: aProjectID.
1✔
1031
        ^ self parsePipelinesResult: result
1✔
1032
]
1✔
1033

1034
{ #category : 'as yet unclassified' }
1035
GLHModelImporter >> selectEntityType: aType overAttribut: aSelector equalTo: value [
×
1036

×
1037
        ^ (self glhModel allWithType: aType)
×
1038
                select: [ :entity | (entity perform: aSelector) = value ]
×
1039
]
×
1040

1041
{ #category : 'private - api' }
1042
GLHModelImporter >> subGroupsOf: aGroupID [
1✔
1043

1✔
1044
        | results parsedResult result page |
1✔
1045
        ('Search subgroup of: ' , aGroupID printString) recordInfo.
1✔
1046
        results := OrderedCollection new.
1✔
1047
        page := 0.
1✔
1048
        
1✔
1049
        parsedResult := { true }.
1✔
1050
        [ parsedResult size > 0 ] whileTrue: [ 
1✔
1051
                result := self glhApi subgroupsOfGroup: aGroupID page: page.
1✔
1052
                parsedResult := self parseSubGroupResult: result.
1✔
1053
                results addAll: parsedResult.
1✔
1054
                                page := page + 1. ].
1✔
1055
        
1✔
1056
        ^ results
1✔
1057
]
1✔
1058

1059
{ #category : 'accessing' }
1060
GLHModelImporter >> withCommitDiffs [
1✔
1061

1✔
1062
        ^ withCommitDiffs
1✔
1063
]
1✔
1064

1065
{ #category : 'accessing' }
1066
GLHModelImporter >> withCommitDiffs: anObject [
1✔
1067

1✔
1068
        withCommitDiffs := anObject
1✔
1069
]
1✔
1070

1071
{ #category : 'accessing' }
UNCOV
1072
GLHModelImporter >> withInitialCommits: boolean [
×
1073
        withInitialCommits := boolean 
×
1074
]
×
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