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

moosetechnology / GitProjectHealth / 10869973365

15 Sep 2024 09:42AM UTC coverage: 36.283% (+2.6%) from 33.667%
10869973365

Pull #55

github

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

355 of 461 new or added lines in 7 files covered. (77.01%)

224 existing lines in 3 files now uncovered.

3063 of 8442 relevant lines covered (36.28%)

0.36 hits per line

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

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

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

×
22
        ^ currentImporter
×
UNCOV
23
]
×
24

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

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

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

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

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

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

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

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

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

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

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

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

1✔
88
        self importPipelinesOfProject: importedProject.
1✔
89

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

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

1✔
95

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

1✔
100
        ^ importedProject
1✔
101
]
1✔
102

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

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

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

1✔
115
        ^ aCommit
1✔
116
]
1✔
117

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

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

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

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

1✔
148
]
1✔
149

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

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

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

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

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

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

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

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

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

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

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

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

1✔
215
        ^ glhApi
1✔
216
]
1✔
217

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

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

224
{ #category : 'accessing' }
225
GLHModelImporter >> glhModel [
1✔
226

1✔
227
        ^ glhModel
1✔
228
]
1✔
229

230
{ #category : 'accessing' }
231
GLHModelImporter >> glhModel: anObject [
1✔
232

1✔
233
        glhModel := anObject
1✔
234
]
1✔
235

236
{ #category : 'api' }
237
GLHModelImporter >> importAllGroups [
×
238

×
239
        | page foundGroups newlyFoundGroups |
×
240
        page := 0.
×
UNCOV
241
        foundGroups := OrderedCollection new.
×
NEW
242
        newlyFoundGroups := { true }.
×
243
        [ newlyFoundGroups isNotEmpty ] whileTrue: [
×
244
                | results |
×
245
                page := page + 1.
×
246
                results := self glhApi listGroupsWithTopLevelOnly: true page: page.
×
247

×
248
                newlyFoundGroups := generalReader
×
249
                                            on: results readStream;
×
250
                                            nextAs: #ArrayOfGroups.
×
251
                foundGroups addAll: newlyFoundGroups ].
×
252
        ^ foundGroups
×
253
]
×
254

255
{ #category : 'private - api' }
256
GLHModelImporter >> importCommit: aCommitID ofProject: aGLHProject [
×
257

×
258
        | result parsedResult |
×
UNCOV
259
        (glhModel allWithType: GLHCommit) asOrderedCollection
×
NEW
260
                detect: [ :commit | commit id = aCommitID ]
×
UNCOV
261
                ifFound: [ :commit | ^ commit ].
×
UNCOV
262
        result := self glhApi
×
UNCOV
263
                          commit: aCommitID
×
UNCOV
264
                          ofProject: aGLHProject id
×
UNCOV
265
                          withStat: false.
×
UNCOV
266
        parsedResult := self parseCommitResult: result.
×
UNCOV
267
        self
×
UNCOV
268
                addCommits: { parsedResult }
×
UNCOV
269
                toRepository: aGLHProject repository.
×
UNCOV
270
        ^ parsedResult
×
UNCOV
271
]
×
272

273
{ #category : 'as yet unclassified' }
274
GLHModelImporter >> importCommitOfProject: anProject withId: anID [
1✔
275

1✔
276
        | commit result |
1✔
277
        anID ifNil: [ ^ nil ].
1✔
278

1✔
279
        ('looking for commit ' , anID printString , ' in project : '
1✔
280
         , anProject id printString) recordInfo.
1✔
281

1✔
282
        commit := (self
1✔
283
                           detectEntityType: GLHCommit
1✔
284
                           overAttribut: #id
1✔
285
                           equalTo: anID) ifNil: [
1✔
286
                          result := self glhApi commit: anID ofProject: anProject id.
1✔
287
                          commit := (self parseCommitsResult: '[' , result , ']')
1✔
288
                                            first.
1✔
289

1✔
290
                          self glhModel add: commit unless: self blockOnIdEquality.
1✔
291
                          commit repository: anProject repository.
1✔
292

1✔
293
                          commit ].
1✔
294

1✔
295
        self withCommitDiffs ifTrue: [ self importDiffOfCommit: commit ].
1✔
296

1✔
297
        ^ commit
1✔
298
]
1✔
299

300
{ #category : 'private - api' }
301
GLHModelImporter >> importCommits: aGLHProject [
1✔
302
        "limited to the last 20 commits"
1✔
303

1✔
304
        | results parsedResults |
1✔
305
        results := self glhApi
1✔
306
                           commitsOfProject: aGLHProject id
1✔
307
                           forRefName: nil
1✔
308
                           since: nil
1✔
309
                           until: nil
1✔
310
                           path: nil
1✔
311
                           author: nil
1✔
312
                           all: nil
1✔
313
                           with_stats: true
1✔
314
                           firstParent: nil
1✔
315
                           order: nil
1✔
316
                           trailers: nil
1✔
317
                           perPage: nil
1✔
318
                           page: nil.
1✔
319
        parsedResults := self parseCommitsResult: results.
1✔
320
        self glhModel addAll: parsedResults unless: self blockOnIdEquality.
1✔
321

1✔
322
        parsedResults do: [ :commit |
1✔
323
                commit repository: aGLHProject repository ].
1✔
324

1✔
325
        self withCommitDiffs ifTrue: [
1✔
326
                parsedResults do: [ :commit | self importDiffOfCommit: commit ] ].
1✔
327
        
1✔
328
        ^ parsedResults. 
1✔
329
]
1✔
330

331
{ #category : 'as yet unclassified' }
UNCOV
332
GLHModelImporter >> importCommitsFollowing: aCommit upToDays: aNumberOfDay [
×
NEW
333
        "import the 'n' commits of a project starting from an initial 'aCommit' commit. 
×
UNCOV
334
        Lazy import does not import the entities inside the model"
×
UNCOV
335

×
UNCOV
336
        | date |
×
UNCOV
337
        date := aCommit created_at asDateAndTime.
×
UNCOV
338

×
UNCOV
339
        ^ self
×
UNCOV
340
                  importCommitsOfBranch: aCommit branch
×
UNCOV
341
                  forRefName: aCommit branch name
×
UNCOV
342
                  since: date
×
UNCOV
343
                  until: (date + aNumberOfDay day)
×
UNCOV
344
]
×
345

346
{ #category : 'commit' }
347
GLHModelImporter >> importCommitsOProject: aProject since: fromDate until: toDate [
1✔
348

1✔
349
        | newlyFoundCommit page foundCommit |
1✔
350
        page := 0.
1✔
351
        foundCommit := OrderedCollection new.
1✔
352
        newlyFoundCommit := { true }.
1✔
353
        [ newlyFoundCommit isNotEmpty ] whileTrue: [
1✔
354
                | results |
1✔
355
                page := page + 1.
1✔
356
                ('import commit page ' , page printString) recordInfo.
1✔
357
                results := GLHApi current
1✔
358
                                   commitsOfProject: aProject id
1✔
359
                                   forRefName: nil
1✔
360
                                   since:
1✔
361
                                   (fromDate ifNotNil: [ fromDate asDateAndTime asString ])
1✔
362
                                   until:
1✔
363
                                   (toDate ifNotNil: [ toDate asDateAndTime asString ])
1✔
364
                                   path: nil
1✔
365
                                   author: nil
1✔
366
                                   all: true
1✔
367
                                   with_stats: true
1✔
368
                                   firstParent: nil
1✔
369
                                   order: nil
1✔
370
                                   trailers: nil
1✔
371
                                   perPage: 100
1✔
372
                                   page: page.
1✔
373

1✔
374
                newlyFoundCommit := self parseCommitsResult: results.
1✔
375
                "newlyFoundCommit do: [ :c | c repository: aProject repository ]."
1✔
376

1✔
377
                foundCommit addAll: (aProject repository commits
1✔
378
                        addAll: newlyFoundCommit
1✔
379
                        unless: self blockOnIdEquality). ].
1✔
380

1✔
381

1✔
382
        ^ self glhModel addAll: foundCommit unless: self blockOnIdEquality
1✔
383
]
1✔
384

385
{ #category : 'api' }
386
GLHModelImporter >> importCommitsOf: aGLHProject withStats: aBoolean until: toDate [
×
387

×
388
        | newlyFoundCommit page |
×
389
        
×
390
        self deprecated: [  ] .
×
391
        
×
392
        page := 0.
×
393
        newlyFoundCommit := { true }.
×
394
        [ newlyFoundCommit isNotEmpty ] whileTrue: [
×
395
                | results parsedResults existingCommits |
×
396
                page := page + 1.
×
397
                ('import commit page ' , page printString) recordInfo.
×
398
                results := self glhApi
×
399
                                   commitsOfProject: aGLHProject id
×
400
                                   forRefName: nil
×
401
                                   since: nil
×
402
                                   until: nil
×
403
                                   path: nil
×
404
                                   author: nil
×
405
                                   all: nil
×
406
                                   with_stats: aBoolean
×
407
                                   firstParent: nil
×
408
                                   order: nil
×
409
                                   trailers: nil
×
410
                                   perPage: 100
×
411
                                   page: page.
×
412
                parsedResults := self parseCommitsResult: results.
×
413
                existingCommits := aGLHProject mooseModel allWithType: GLHCommit.
×
414

×
415
                newlyFoundCommit := parsedResults reject: [ :commitParsed |
×
UNCOV
416
                                            (toDate isNil or: [
×
NEW
417
                                                     commitParsed committed_date
×
418
                                                     < toDate asDateAndTime ]) or: [
×
419
                                                    existingCommits anySatisfy: [ :existingCommit |
×
420
                                                            existingCommit id = commitParsed id ] ] ].
×
421
                aGLHProject mooseModel addAll: newlyFoundCommit.
×
422
                aGLHProject repository commits addAll: newlyFoundCommit ].
×
423

×
424

×
425
        self withCommitDiffs ifTrue: [
×
UNCOV
426
                aGLHProject repository commits do: [ :commit |
×
NEW
427
                        self importDiffOfCommit: commit ] ]
×
428
]
×
429

430
{ #category : 'commit' }
431
GLHModelImporter >> importCommitsOfBranch: aGLHBranch forRefName: refName since: fromDate [
×
432

×
433
        ^ self
×
434
                  importCommitsOfBranch: aGLHBranch
×
435
                  forRefName: aGLHBranch name
×
436
                  since: fromDate
×
437
                  until: nil
×
438
]
×
439

440
{ #category : 'commit' }
441
GLHModelImporter >> importCommitsOfBranch: aGLHBranch forRefName: refName since: fromDate until: toDate [
×
442

×
443
        | newlyFoundCommit page foundCommit|
×
444
        page := 0.
×
445
        foundCommit := OrderedCollection new. 
×
446
        newlyFoundCommit := { true }.
×
447
        [ newlyFoundCommit isNotEmpty ] whileTrue: [
×
448
                | results |
×
449
                page := page + 1.
×
450
                ('import commit page ' , page printString) recordInfo.
×
451
                results := self glhApi
×
452
                                   commitsOfProject: aGLHBranch repository project id
×
453
                                   forRefName: aGLHBranch name
×
454
                                   since:
×
455
                                   (fromDate ifNotNil: [ fromDate asDateAndTime asString ])
×
456
                                   until:
×
457
                                   (toDate ifNotNil: [ toDate asDateAndTime asString ])
×
458
                                   path: nil
×
459
                                   author: nil
×
460
                                   all: nil
×
461
                                   with_stats: nil
×
462
                                   firstParent: nil
×
463
                                   order: nil
×
464
                                   trailers: nil
×
465
                                   perPage: 100
×
466
                                   page: page.
×
467

×
468
                newlyFoundCommit := self parseCommitsResult: results.
×
469
        aGLHBranch commits
×
470
                        addAll: newlyFoundCommit
×
UNCOV
471
                        unless: self blockOnIdEquality.
×
NEW
472
        foundCommit addAll: newlyFoundCommit.  
×
473
                        ].
×
474

×
475
        self glhModel
×
476
                addAll: aGLHBranch commits
×
477
                unless: self blockOnIdEquality.
×
478

×
479
        "self withCommitDiffs ifTrue: [
×
480
                aGLHBranch commits: [ :commit | self importDiffOfCommit: commit ] ]."
×
UNCOV
481

×
NEW
482
        ^ foundCommit
×
UNCOV
483
]
×
484

485
{ #category : 'commit' }
UNCOV
486
GLHModelImporter >> importCommitsOfBranch: aGLHBranch forRefName: refName until: toDate [
×
UNCOV
487

×
UNCOV
488
        ^ self
×
UNCOV
489
                  importCommitsOfBranch: aGLHBranch
×
NEW
490
                  forRefName: aGLHBranch name
×
UNCOV
491
                  since: nil
×
UNCOV
492
                  until: toDate
×
UNCOV
493
]
×
494

495
{ #category : 'as yet unclassified' }
496
GLHModelImporter >> importCreatorOfCommit: aCommit [
1✔
497
        
1✔
498
        aCommit commitCreator ifNil: [
1✔
499
                aCommit commitCreator:
1✔
500
                        (self importUserByUsername: aCommit author_name) ]
1✔
501
]
1✔
502

503
{ #category : 'api' }
504
GLHModelImporter >> importDiffOfCommit: aCommit [
1✔
505

1✔
506
        | result diffsResult |
1✔
507
        aCommit diffs ifNotEmpty: [
1✔
508
                'Diff already importer: ' , aCommit short_id printString recordInfo.
1✔
509
                ^ aCommit diffs ].
1✔
510
        ('Import diff of commit: ' , aCommit short_id printString) recordInfo.
1✔
511
        result := self glhApi
1✔
512
                          commitDiff: aCommit id
1✔
513
                          ofProject: aCommit repository project id
1✔
514
                          unidiff: true.
1✔
515
        diffsResult := self newParseDiffResult: result.
1✔
516

1✔
517
        ^ aCommit diffs addAll: diffsResult unless: self blockForDiffEquality.
1✔
518

1✔
519
]
1✔
520

521
{ #category : 'private - api' }
522
GLHModelImporter >> importDirectoryFiles: aDirectoryFile OfBranch: aBranch [
×
523

×
524
        | result files apiFiles |
×
525
        result := self glhApi
×
526
                          treeOfRepository: aBranch repository project id
×
527
                          ofBranch: aBranch name
×
UNCOV
528
                          andPath: aDirectoryFile path , '/'.
×
NEW
529
        apiFiles := self parseFileTreeResult: result.
×
530
        files := apiFiles collect: [ :apiFile |
×
531
                         self convertApiFileAsFile: apiFile ].
×
532
        files do: [ :file |
×
533
                
×
534
                self glhModel add: file.
×
535
                aDirectoryFile addFile: file ].
×
536
        files
×
537
                select: [ :file | file isKindOf: GLHFileDirectory ]
×
538
                thenCollect: [ :file |
×
539
                self importDirectoryFiles: file OfBranch: aBranch ]
×
540
]
×
541

542
{ #category : 'private - api' }
543
GLHModelImporter >> importFilesOfBranch: aBranch [
×
544

×
545
        | result files apiFiles |
×
546
        result := self glhApi
×
547
                          treeOfRepository: aBranch repository project id
×
UNCOV
548
                          ofBranch: aBranch name
×
NEW
549
                          andPath: nil.
×
UNCOV
550
        apiFiles := self parseFileTreeResult: result.
×
UNCOV
551
        files := apiFiles collect: [ :apiFile | 
×
UNCOV
552
                         self convertApiFileAsFile: apiFile ].
×
UNCOV
553
        files do: [ :file | 
×
UNCOV
554
                self glhModel add: file.
×
UNCOV
555
                aBranch addFile: file ].
×
UNCOV
556
        files
×
UNCOV
557
                select: [ :file | file isKindOf: GLHFileDirectory ]
×
UNCOV
558
                thenCollect: [ :file | 
×
UNCOV
559
                self importDirectoryFiles: file OfBranch: aBranch ]
×
UNCOV
560
]
×
561

562
{ #category : 'api' }
563
GLHModelImporter >> importGroup: aGroupID [
1✔
564

1✔
565
        | result groupResult |
1✔
566
        ('Import group: ' , aGroupID printString) recordInfo.
1✔
567

1✔
568
        result := self glhApi group: aGroupID.
1✔
569
        groupResult := self parseGroupResult: result.
1✔
570
        groupResult := self addGroupResultToModel: groupResult.
1✔
571

1✔
572
        groupResult projects do: [ :project |
1✔
573
                self completeImportProject: project ].
1✔
574

1✔
575
        (self subGroupsOf: aGroupID) do: [ :subGroup |
1✔
576
                
1✔
577
                groupResult subGroups
1✔
578
                        add: (self importGroup: subGroup id)
1✔
579
                        unless: self blockOnIdEquality ].
1✔
580
        ^ groupResult
1✔
581
]
1✔
582

583
{ #category : 'api' }
584
GLHModelImporter >> importJobsOf: aPipeline [
×
585

×
586
        | result jobs |
×
587
        result := self glhApi
×
588
                          jobsOfProject: aPipeline project id
×
589
                          ofPipelines: aPipeline id.
×
590
        jobs := self parseJobsResult: result ofProject: aPipeline project.
×
591
        jobs do: [ :job | aPipeline addJob: job ].
×
592
        self glhModel addAll: jobs
×
593

×
594
]
×
595

596
{ #category : 'commit' }
597
GLHModelImporter >> importParentCommitsOfCommit: aGLHCommit forOnly: number [
×
598

×
599
        | parentsIds commits |
×
600
        commits := OrderedCollection new.
×
601
        number = 0 ifTrue: [
×
602
                ^ commits
×
603
                          add: aGLHCommit;
×
604
                          yourself ].
×
605

×
606
        parentsIds := aGLHCommit parent_ids.
×
607

×
UNCOV
608
        commits addAll: (parentsIds collect: [ :id |
×
NEW
609
                         self
×
610
                                 importCommitOfProject: aGLHCommit repository project
×
611
                                 withId: id.
×
612
                         (self selectEntityType: GLHCommit overAttribut: #id equalTo: id)
×
613
                                 first ]).
×
614

×
615

×
616
        ^ commits , (commits collect: [ :parentCommit |
×
617
                   self
×
618
                           importParentCommitsOfCommit: parentCommit
×
619
                           forOnly: number - 1 ]) flatten
×
620
]
×
621

622
{ #category : 'commit' }
623
GLHModelImporter >> importParentCommitsOfCommit: aGLHCommit since: aDate [
×
624

×
625
        | parentsIds commits |
×
626
        commits := OrderedCollection new.
×
627
        aGLHCommit created_at asDateAndTime < aDate asDateAndTime ifTrue: [
×
628
                 
×
629
                ^ commits
×
630
                          add: aGLHCommit;
×
631
                          yourself ].
×
UNCOV
632

×
NEW
633
        parentsIds := aGLHCommit parent_ids.
×
UNCOV
634

×
UNCOV
635
        commits addAll: (parentsIds collect: [ :id |
×
UNCOV
636
                         self
×
UNCOV
637
                                 importCommitOfProject: aGLHCommit repository project
×
UNCOV
638
                                 withId: id ]).
×
UNCOV
639

×
UNCOV
640

×
NEW
641
        ^ (commits collect: [ :parentCommit |
×
642
                   self importParentCommitsOfCommit: parentCommit since: aDate ])
×
643
                  flatten
×
644
]
×
645

646
{ #category : 'private - api' }
647
GLHModelImporter >> importPipelinesOfProject: aGLHProject [
1✔
648

1✔
649
        (self pipelinesOf: aGLHProject id) do: [ :pipeline |
1✔
650
                self glhModel add: pipeline unless: self blockOnIdEquality .
1✔
651
                aGLHProject pipelines add: pipeline unless: self blockOnIdEquality]
1✔
652
]
1✔
653

654
{ #category : 'imports' }
UNCOV
655
GLHModelImporter >> importProjects [
×
NEW
656

×
657
        ^ self importProjectsSince: nil
×
658
]
×
659

660
{ #category : 'projects' }
661
GLHModelImporter >> importProjects: aCollectionOfProjectID [
×
662
        
×
663
        ^ aCollectionOfProjectID collect: [ :id |
×
664
                self importProject: id.
×
665
                 ]
×
666
         
×
667
]
×
668

669
{ #category : 'imports' }
670
GLHModelImporter >> importProjectsSince: since [
×
671
        "heavy import of all projects"
×
672

×
673
        "copy import from commits"
×
674

×
675
        | newlyFoundProjects page foundProject amount |
×
676
        ('import all Projects since: ', since printString) recordInfo.
×
677

×
678
        "number of projects per page"
×
679
        amount := 100.
×
680
        page := 0.
×
681
        foundProject := OrderedCollection new.
×
682
        newlyFoundProjects := { true }.
×
683
        [ newlyFoundProjects isNotEmpty ] whileTrue: [
×
UNCOV
684
                | results |
×
NEW
685
                page := page + 1.
×
UNCOV
686
                ('import projects page #' , page printString) recordInfo.
×
UNCOV
687
                
×
UNCOV
688
                results := self glhApi projects: amount since: since page: page.
×
UNCOV
689

×
UNCOV
690
                newlyFoundProjects := glhModel
×
UNCOV
691
                                              addAll: (self parseArrayOfProject: results)
×
UNCOV
692
                                              unless: self blockOnIdEquality.
×
UNCOV
693
                foundProject addAll: newlyFoundProjects ].
×
UNCOV
694

×
UNCOV
695
        ^ foundProject
×
UNCOV
696
]
×
697

698
{ #category : 'private - api' }
699
GLHModelImporter >> importRepository: aGLHRepository [
1✔
700

1✔
701
        | resultBranches branches |
1✔
702
        [
1✔
703
        ('import the repository of project ' , aGLHRepository project name)
1✔
704
                recordInfo.
1✔
705

1✔
706
        resultBranches := self glhApi branchesOfRepository:
1✔
707
                                  aGLHRepository project id.
1✔
708
        branches := self parseBranchesResult: resultBranches.
1✔
709

1✔
710
        ('import the branches of project ') recordInfo.
1✔
711

1✔
712
        branches := aGLHRepository branches
1✔
713
                addAll: branches
1✔
714
                unless: self blockOnNameEquality.
1✔
715
        branches := self glhModel addAll: branches unless: self blockOnNameEquality.
1✔
716

1✔
717

1✔
718
        self withFiles ifTrue: [
1✔
719
                branches do: [ :branch | self importFilesOfBranch: branch ] ] ]
1✔
720
                on: NeoJSONParseError
1✔
721
                do: [
1✔
722
                self inform: aGLHRepository project name , ' has no repository' ]
1✔
723
]
1✔
724

725
{ #category : 'private - api' }
726
GLHModelImporter >> importUser: aUserID [
1✔
727

1✔
728
        | result userResult |
1✔
729
        (glhModel allWithType: GLHUser)
1✔
730
                detect: [ :user | user id = aUserID ]
1✔
731
                ifFound: [ :user | ^ user ].
1✔
732
        ('Import user: ' , aUserID printString) recordInfo.
1✔
733
        result := self glhApi user: aUserID.
1✔
734
        userResult := self parseUserResult: result.
1✔
735
        ^ glhModel add: userResult unless: self blockOnIdEquality
1✔
736
]
1✔
737

738
{ #category : 'user' }
739
GLHModelImporter >> importUserByUsername: anUsername [
1✔
740

1✔
741
        | dicUsername |
1✔
742
        dicUsername := ((self glhModel allWithType: GLHUser) collect: [ :user |
1✔
743
                                user username -> user ]) asSet asDictionary.
1✔
744

1✔
745
        ^ dicUsername at: anUsername ifPresent: [ :user | user ] ifAbsent: [
1✔
746
                  | result userId searchResult |
1✔
747
                  ('Import user with username: ' , anUsername printString)
1✔
748
                          recordInfo.
1✔
749
                  result := self glhApi usersSearchByUsername: anUsername.
1✔
750
                  searchResult := NeoJSONReader fromString: result.
1✔
751

1✔
752
                  (searchResult class = Dictionary and: [
1✔
753
                           (searchResult at: #message) includesSubstring: '403 Forbidden' ])
1✔
754
                          ifTrue: [
1✔
755
                                  glhModel
1✔
756
                                          add: (GLHUser new username: anUsername; name: anUsername; yourself )
1✔
757
                                          unless: [ :nu :ou | nu username = ou username ] ]
1✔
758
                          ifFalse: [
1✔
759
                                  searchResult
1✔
760
                                          ifEmpty: [
1✔
761
                                                  GLHUser new
1✔
762
                                                          username: anUsername;
1✔
763
                                                          yourself ]
1✔
764
                                          ifNotEmpty: [
1✔
765
                                                  userId := searchResult first at: #id.
1✔
766
                                                  (self glhModel allWithType: GLHUser)
1✔
767
                                                          detect: [ :user | user id = userId ]
1✔
768
                                                          ifNone: [ self importUser: userId ] ] ] ]
1✔
769
]
1✔
770

771
{ #category : 'initialization' }
772
GLHModelImporter >> initReader [
1✔
773

1✔
774
        generalReader := NeoJSONReader new.
1✔
775
        self configureReaderForCommit: generalReader.
1✔
776
        self configureReaderForGroup: generalReader.
1✔
777
        self configureReaderForDiffs: generalReader. 
1✔
778
]
1✔
779

780
{ #category : 'initialization' }
781
GLHModelImporter >> initialize [
1✔
782

1✔
783
        super initialize.
1✔
784
        withCommitDiffs := false.
1✔
785
        withInitialCommits := false.
1✔
786
        withInitialMergeRequest := false.
1✔
787
        self initReader.
1✔
788
        currentImporter := self
1✔
789
]
1✔
790

791
{ #category : 'importer' }
792
GLHModelImporter >> loadAllProjectsFromRepositorySoftware [
×
UNCOV
793
        "heavy import that load all the active project inside the model. Only import the project entities"
×
NEW
794
        |projects|
×
UNCOV
795
        
×
UNCOV
796
        projects := self glhApi projects. 
×
UNCOV
797
]
×
798

799
{ #category : 'private' }
UNCOV
800
GLHModelImporter >> newParseCommitResult: result [
×
NEW
801

×
802
        generalReader  on: result readStream.
×
803

×
804
        ^ generalReader nextAs: GLHCommit
×
805
]
×
806

807
{ #category : 'private' }
808
GLHModelImporter >> newParseDiffResult: result [
1✔
809

1✔
810
        generalReader on: result readStream.
1✔
811
        ^ generalReader nextAs: #ArrayOfDiffs
1✔
812
]
1✔
813

814
{ #category : 'parsing' }
815
GLHModelImporter >> parseArrayOfProject: arrayOfProjects [
×
816

×
817
        | reader |
×
818
        reader := NeoJSONReader on: arrayOfProjects readStream.
×
UNCOV
819
        reader
×
NEW
820
                for: #ArrayOfProjects
×
UNCOV
821
                customDo: [ :customMappting |
×
UNCOV
822
                customMappting listOfElementSchema: GLHProject ].
×
UNCOV
823
        reader for: GLHProject do: [ :mapping |
×
UNCOV
824
                mapping mapInstVar: #name to: #name.
×
UNCOV
825
                mapping mapInstVar: #description to: #description.
×
UNCOV
826
                mapping mapInstVar: #id to: #id.
×
UNCOV
827
                mapping mapInstVar: #archived to: #archived.
×
UNCOV
828
                mapping mapInstVar: #web_url to: #html_url.
×
UNCOV
829
                mapping mapInstVar: #topics to: #topics ].
×
UNCOV
830
        ^ reader nextAs: #ArrayOfProjects
×
UNCOV
831
]
×
832

833
{ #category : 'private' }
834
GLHModelImporter >> parseBranchesResult: result [
1✔
835

1✔
836
        | reader |
1✔
837
        reader := NeoJSONReader on: result readStream.
1✔
838
        reader mapInstVarsFor: GLHBranch.
1✔
839
        reader
1✔
840
                for: #ArrayOfBranch
1✔
841
                customDo: [ :customMappting | 
1✔
842
                customMappting listOfElementSchema: GLHBranch ].
1✔
843
        ^ reader nextAs: #ArrayOfBranch
1✔
844
]
1✔
845

846
{ #category : 'private' }
847
GLHModelImporter >> parseCommitResult: result [
×
848

×
849
        | reader |
×
850
        reader := NeoJSONReader on: result readStream.
×
851

×
852
        reader for: GLHCommit do: [ :mapping |
×
853
                mapping mapInstVars:
×
854
                        #( id short_id title author_name author_email committer_name
×
855
                           committer_email message web_url ).
×
856
                (mapping mapInstVar: #authored_date) valueSchema: DateAndTime.
×
857
                (mapping mapInstVar: #committed_date) valueSchema: DateAndTime.
×
858
                (mapping mapInstVar: #created_at) valueSchema: DateAndTime.
×
859
                (mapping mapInstVar: #parent_ids) valueSchema: #ArrayOfIds.
×
860
                mapping
×
861
                        mapProperty: 'stats'
×
862
                        getter: [ :el | "Not used" ]
×
863
                        setter: [ :commit :value |
×
UNCOV
864
                                commit deletions: (value at: #deletions).
×
NEW
865
                                commit additions: (value at: #additions) ] ].
×
UNCOV
866

×
UNCOV
867
        reader for: DateAndTime customDo: [ :mapping |
×
UNCOV
868
                mapping decoder: [ :string | DateAndTime fromString: string ] ].
×
UNCOV
869

×
UNCOV
870
        reader
×
UNCOV
871
                for: #ArrayOfIds
×
UNCOV
872
                customDo: [ :mapping | mapping decoder: [ :string | string ] ].
×
UNCOV
873

×
UNCOV
874

×
UNCOV
875
        ^ reader nextAs: GLHCommit
×
UNCOV
876
]
×
877

878
{ #category : 'private' }
879
GLHModelImporter >> parseCommitsResult: result [
1✔
880

1✔
881
        | reader |
1✔
882
        reader := NeoJSONReader on: result readStream.
1✔
883

1✔
884
          reader for: GLHCommit do: [ :mapping |
1✔
885
                mapping mapInstVars:
1✔
886
                        #( id short_id title author_name author_email committer_name
1✔
887
                           committer_email message web_url ).
1✔
888
                (mapping mapInstVar: #authored_date) valueSchema: DateAndTime.
1✔
889
                (mapping mapInstVar: #committed_date) valueSchema: DateAndTime.
1✔
890
                (mapping mapInstVar: #created_at) valueSchema: DateAndTime.
1✔
891
                (mapping mapInstVar: #parent_ids) valueSchema: #ArrayOfIds.
1✔
892
                mapping
1✔
893
                        mapProperty: 'stats'
1✔
894
                        getter: [ :el | "Not used" ]
1✔
895
                        setter: [ :commit :value |
1✔
896
                                commit deletions: (value at: #deletions).
1✔
897
                                commit additions: (value at: #additions) ] ].
1✔
898

1✔
899
        reader for: DateAndTime customDo: [ :mapping |
1✔
900
                mapping decoder: [ :string | DateAndTime fromString: string ] ].
1✔
901

1✔
902
        reader
1✔
903
                for: #ArrayOfIds
1✔
904
                customDo: [ :mapping | mapping decoder: [ :string | string ] ].
1✔
905
  
1✔
906
        reader
1✔
907
                for: #ArrayOfCommit
1✔
908
                customDo: [ :customMappting |
1✔
909
                customMappting listOfElementSchema: GLHCommit ].
1✔
910

1✔
911
        ^ reader nextAs: #ArrayOfCommit
1✔
912
]
1✔
913

914
{ #category : 'private' }
915
GLHModelImporter >> parseDiffResult: result [
1✔
916

1✔
917
        | reader |
1✔
918
        self
1✔
919
                deprecated: 'Use #newParseDiffResult: instead'
1✔
920
                on: '28 June 2024'
1✔
921
                in:
1✔
922
                'Pharo-11.0.0+build.726.sha.aece1b5473acf3830a0e082c1bc3a15d4ff3522b (64 Bit)'.
1✔
923
        reader := NeoJSONReader on: result readStream.
1✔
924
        reader for: GLHDiff do: [ :mapping |
1✔
925
                mapping mapInstVars:
1✔
926
                        #( deleted_file new_file new_path old_path renamed_file ).
1✔
927
                mapping mapInstVar: #diffString to: #diff ].
1✔
928

1✔
929
        reader
1✔
930
                for: #ArrayOfDiffs
1✔
931
                customDo: [ :customMappting |
1✔
932
                customMappting listOfElementSchema: GLHDiff ].
1✔
933
        ^ reader nextAs: #ArrayOfDiffs
1✔
934
]
1✔
935

936
{ #category : 'private' }
UNCOV
937
GLHModelImporter >> parseFileTreeResult: aResult [
×
UNCOV
938

×
UNCOV
939
        | reader |
×
UNCOV
940
        reader := NeoJSONReader on: aResult readStream.
×
UNCOV
941
        reader mapInstVarsFor: GLHApiFile.
×
UNCOV
942
        reader
×
UNCOV
943
                for: #ArrayOfFile
×
UNCOV
944
                customDo: [ :customMappting | 
×
UNCOV
945
                customMappting listOfElementSchema: GLHApiFile ].
×
UNCOV
946
        ^ reader nextAs: #ArrayOfFile
×
UNCOV
947
]
×
948

949
{ #category : 'private' }
950
GLHModelImporter >> parseGroupResult: aResult [
1✔
951

1✔
952
        | reader |
1✔
953

1✔
954
        reader := NeoJSONReader on: aResult readStream.
1✔
955
        reader for: GLHGroup do: [ :mapping |
1✔
956
                mapping mapInstVars.
1✔
957
                (mapping mapInstVar: #projects) valueSchema: #ArrayOfProjects ].
1✔
958
        reader mapInstVarsFor: GLHProject.
1✔
959
        reader
1✔
960
                for: #ArrayOfProjects
1✔
961
                customDo: [ :customMappting |
1✔
962
                customMappting listOfElementSchema: GLHProject ].
1✔
963
        ^ reader nextAs: GLHGroup
1✔
964
]
1✔
965

966
{ #category : 'private' }
967
GLHModelImporter >> parseJobsResult: result ofProject: aProject [
×
968

×
969
        | reader |
×
970
        reader := NeoJSONReader on: result readStream.
×
971
        reader for: GLHJob do: [ :mapping |
×
972
                mapping mapInstVars: #( id allow_failure web_url name ).
×
973

×
974
                mapping
×
975
                        mapProperty: #user
×
976
                        getter: [ :object | #ignore ]
×
977
                        setter: [ :object :value |
×
978
                        object user: (self importUser: (value at: #id)) ].
×
979

×
980
                mapping
×
981
                        mapProperty: #commit
×
982
                        getter: [ :object | #ignore ]
×
983
                        setter: [ :object :value |
×
984
                                value ifNotNil: [
×
985
                                        object commit:
×
986
                                                (self importCommit: (value at: #id) ofProject: aProject) ] ].
×
UNCOV
987

×
NEW
988
                mapping
×
UNCOV
989
                        mapProperty: #duration
×
UNCOV
990
                        getter: [ :object | #ignore ]
×
UNCOV
991
                        setter: [ :object :value |
×
UNCOV
992
                        value ifNotNil: [ object duration: value seconds ] ] ].
×
UNCOV
993

×
UNCOV
994
        reader
×
UNCOV
995
                for: #ArrayOfGLHJob
×
UNCOV
996
                customDo: [ :customMappting |
×
UNCOV
997
                customMappting listOfElementSchema: GLHJob ].
×
UNCOV
998
        ^ reader nextAs: #ArrayOfGLHJob
×
UNCOV
999
]
×
1000

1001
{ #category : 'private' }
1002
GLHModelImporter >> parsePipelinesResult: result [
1✔
1003

1✔
1004
        | reader |
1✔
1005
        reader := NeoJSONReader on: result readStream.
1✔
1006
        reader mapInstVarsFor: GLHPipeline.
1✔
1007
        reader for: GLHPipeline do: [ :mapping |
1✔
1008
                mapping
1✔
1009
                        mapProperty: #created_at
1✔
1010
                        getter: [ :object | #ignore ]
1✔
1011
                        setter: [ :object :value |
1✔
1012
                        object runDate: (DateAndTime fromString: value) ] ].
1✔
1013
        reader
1✔
1014
                for: #ArrayOfPipelines
1✔
1015
                customDo: [ :customMappting |
1✔
1016
                customMappting listOfElementSchema: GLHPipeline ].
1✔
1017
        ^ reader nextAs: #ArrayOfPipelines
1✔
1018
]
1✔
1019

1020
{ #category : 'private' }
1021
GLHModelImporter >> parseSubGroupResult: aResult [
1✔
1022

1✔
1023
        | reader |
1✔
1024
        reader := NeoJSONReader on: aResult readStream.
1✔
1025
        self configureReaderForGroup: reader.
1✔
1026
        ^ reader nextAs: #ArrayOfGroups
1✔
1027
]
1✔
1028

1029
{ #category : 'private' }
1030
GLHModelImporter >> parseUserResult: result [
1✔
1031

1✔
1032
        | reader |
1✔
1033
        reader := NeoJSONReader on: result readStream.
1✔
1034
        reader mapInstVarsFor: GLHUser.
1✔
1035
        ^ reader nextAs: GLHUser
1✔
1036
]
1✔
1037

1038
{ #category : 'private - api' }
1039
GLHModelImporter >> pipelinesOf: aProjectID [
1✔
1040

1✔
1041
        | result |
1✔
1042
        ('Search pipelines of: ' , aProjectID printString) recordInfo.
1✔
1043
        result := self glhApi pipelinesOfProject: aProjectID.
1✔
1044
        ^ self parsePipelinesResult: result
1✔
1045
]
1✔
1046

1047
{ #category : 'as yet unclassified' }
UNCOV
1048
GLHModelImporter >> selectEntityType: aType overAttribut: aSelector equalTo: value [
×
UNCOV
1049

×
UNCOV
1050
        ^ (self glhModel allWithType: aType)
×
UNCOV
1051
                select: [ :entity | (entity perform: aSelector) = value ]
×
UNCOV
1052
]
×
1053

1054
{ #category : 'private - api' }
1055
GLHModelImporter >> subGroupsOf: aGroupID [
1✔
1056

1✔
1057
        | results parsedResult result page |
1✔
1058
        ('Search subgroup of: ' , aGroupID printString) recordInfo.
1✔
1059
        results := OrderedCollection new.
1✔
1060
        page := 0.
1✔
1061
        
1✔
1062
        parsedResult := { true }.
1✔
1063
        [ parsedResult size > 0 ] whileTrue: [ 
1✔
1064
                result := self glhApi subgroupsOfGroup: aGroupID page: page.
1✔
1065
                parsedResult := self parseSubGroupResult: result.
1✔
1066
                results addAll: parsedResult.
1✔
1067
                                page := page + 1. ].
1✔
1068
        
1✔
1069
        ^ results
1✔
1070
]
1✔
1071

1072
{ #category : 'accessing' }
1073
GLHModelImporter >> withCommitDiffs [
1✔
1074

1✔
1075
        ^ withCommitDiffs
1✔
1076
]
1✔
1077

1078
{ #category : 'accessing' }
1079
GLHModelImporter >> withCommitDiffs: anObject [
1✔
1080

1✔
1081
        withCommitDiffs := anObject
1✔
1082
]
1✔
1083

1084
{ #category : 'accessing' }
UNCOV
1085
GLHModelImporter >> withInitialCommits: boolean [
×
UNCOV
1086
        withInitialCommits := boolean 
×
UNCOV
1087
]
×
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