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

moosetechnology / GitProjectHealth / 10662325514

02 Sep 2024 06:59AM UTC coverage: 17.281%. First build
10662325514

Pull #45

github

web-flow
Merge 3be43eb61 into 012a80f9f
Pull Request #45: Feature levenshtein

4 of 78 new or added lines in 5 files covered. (5.13%)

1590 of 9201 relevant lines covered (17.28%)

0.17 hits per line

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

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

21
{ #category : #accessing }
22
GLHModelImporter class >> current [
×
23

×
24
        ^ currentImporter
×
25
]
×
26

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

×
31
        "I return the list of added commits"
×
32

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

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

54
{ #category : #accessing }
55
GLHModelImporter >> beWithFiles [
×
56
        withFiles := true
×
57
]
×
58

59
{ #category : #accessing }
60
GLHModelImporter >> beWithouFiles [
×
61
        withFiles := false
×
62
]
×
63

64
{ #category : #'as yet unclassified' }
65
GLHModelImporter >> blockEqualityOn: aSymbol [
1✔
66
        ^ [ :existing :new |
1✔
67
          (existing perform: aSymbol) = (new perform: aSymbol) ]
1✔
68
]
1✔
69

70
{ #category : #equality }
71
GLHModelImporter >> blockForDiffEquality [
1✔
72
        ^ [ :existing :new |
1✔
73
                        existing diffString size = new diffString size and: [
1✔
74
                                existing diffString = new diffString ] ]
1✔
75
]
1✔
76

77
{ #category : #equality }
78
GLHModelImporter >> blockOnIdEquality [
1✔
79

1✔
80
        ^ [ :existing :new |
1✔
81
          existing id = new id ]
1✔
82
]
1✔
83

84
{ #category : #equality }
85
GLHModelImporter >> blockOnNameEquality [
1✔
86

1✔
87
        ^ self blockEqualityOn: #name
1✔
88
]
1✔
89

90
{ #category : #commit }
91
GLHModelImporter >> chainsCommitsFrom: commitsCollection [
×
92

×
93
        | dic |
×
94
        
×
95
        ('Chains ', commitsCollection size printString , ' commits') recordInfo.
×
96
        
×
97
        dic := ((self glhModel allWithType: GLHCommit) collect: [ :commit |
×
98
                        commit id -> commit ]) asSet asDictionary.
×
99

×
100
        commitsCollection do: [ :commit |
×
101
                commit parent_ids do: [ :parentId | 
×
102
                        dic
×
103
                                at: parentId
×
104
                                ifPresent: [ :parentCommit |
×
105
                                        parentCommit childCommits
×
106
                                                add: commit
×
107
                                                unless: self blockOnIdEquality ]
×
108
                                ifAbsent: [  ] ] ].
×
109
        ^ commitsCollection
×
110
]
×
111

112
{ #category : #'private - api' }
113
GLHModelImporter >> completeImportProject: aGLHProject [
1✔
114

1✔
115
        | importedProject |
1✔
116
        ('Complete import of project: ' , aGLHProject id printString)
1✔
117
                recordInfo.
1✔
118
        aGLHProject repository ifNotNil: [ ^ aGLHProject ].
1✔
119
        
1✔
120
        importedProject := self glhModel
1✔
121
                                   add: aGLHProject
1✔
122
                                   unless: self blockOnIdEquality.
1✔
123

1✔
124
        self importPipelinesOfProject: importedProject.
1✔
125

1✔
126
        "aGLHProject creator: (self importUser: aGLHProject creator_id)."
1✔
127

1✔
128
        (self importUser: importedProject creator_id) addCreatedProject:
1✔
129
                importedProject.
1✔
130

1✔
131

1✔
132
        importedProject repository: GLHRepository new.
1✔
133
        self glhModel add: importedProject repository.
1✔
134
        self importRepository: importedProject repository.
1✔
135

1✔
136
        ^ importedProject
1✔
137
]
1✔
138

139
{ #category : #'as yet unclassified' }
140
GLHModelImporter >> completeImportedCommit: aCommit [
×
141

×
142
        ('completing commit: ' , aCommit short_id printString) recordInfo.
×
143
        self importCreatorOfCommit: aCommit.
×
144

×
145
        self withCommitDiffs ifTrue: [
×
146
                | diffs |
×
147
                aCommit diffs ifEmpty: [
×
148
                        diffs := self importDiffOfCommit: aCommit.
×
149
                        self glhModel addAll: diffs unless: self blockForDiffEquality ] ].
×
150

×
151
        ^ aCommit
×
152
]
×
153

154
{ #category : #'private - configure reader' }
155
GLHModelImporter >> configureReaderForCommit: reader [
1✔
156

1✔
157
          reader for: GLHCommit do: [ :mapping |
1✔
158
                mapping mapInstVars:
1✔
159
                        #( id short_id title author_name author_email committer_name
1✔
160
                           committer_email message web_url ).
1✔
161
                (mapping mapInstVar: #authored_date) valueSchema: DateAndTime.
1✔
162
                (mapping mapInstVar: #committed_date) valueSchema: DateAndTime.
1✔
163
                (mapping mapInstVar: #created_at) valueSchema: DateAndTime.
1✔
164
                (mapping mapInstVar: #parent_ids) valueSchema: #ArrayOfIds.
1✔
165
                mapping
1✔
166
                        mapProperty: 'stats'
1✔
167
                        getter: [ :el | "Not used" ]
1✔
168
                        setter: [ :commit :value |
1✔
169
                                commit deletions: (value at: #deletions).
1✔
170
                                commit additions: (value at: #additions) ] ].
1✔
171

1✔
172
        reader for: DateAndTime customDo: [ :mapping |
1✔
173
                mapping decoder: [ :string | DateAndTime fromString: string ] ].
1✔
174

1✔
175
        reader
1✔
176
                for: #ArrayOfIds
1✔
177
                customDo: [ :mapping | mapping decoder: [ :string | string ] ].
1✔
178
  
1✔
179
        reader
1✔
180
                for: #ArrayOfCommit
1✔
181
                customDo: [ :customMappting |
1✔
182
                customMappting listOfElementSchema: GLHCommit ].
1✔
183

1✔
184
]
1✔
185

186
{ #category : #'private - configure reader' }
187
GLHModelImporter >> configureReaderForDiffs: reader [
1✔
188

1✔
189
        reader for: GLHDiff do: [ :mapping |
1✔
190
                mapping mapInstVars:
1✔
191
                        #( deleted_file new_file new_path old_path renamed_file ).
1✔
192
                mapping mapInstVar: #diffString to: #diff ].
1✔
193

1✔
194
        reader
1✔
195
                for: #ArrayOfDiffs
1✔
196
                customDo: [ :customMappting |
1✔
197
                customMappting listOfElementSchema: GLHDiff ].
1✔
198
        ^ reader
1✔
199
]
1✔
200

201
{ #category : #'private - configure reader' }
202
GLHModelImporter >> configureReaderForGroup: reader [
1✔
203

1✔
204
        reader for: GLHGroup do: [ :mapping |
1✔
205
                mapping mapInstVars.
1✔
206
                (mapping mapInstVar: #projects) valueSchema: #ArrayOfProjects ].
1✔
207
        reader mapInstVarsFor: GLHProject.
1✔
208
        reader
1✔
209
                for: #ArrayOfProjects
1✔
210
                customDo: [ :customMappting |
1✔
211
                customMappting listOfElementSchema: GLHProject ].
1✔
212
        reader
1✔
213
                for: #ArrayOfGroups
1✔
214
                customDo: [ :customMappting |
1✔
215
                customMappting listOfElementSchema: GLHGroup ]
1✔
216
]
1✔
217

218
{ #category : #private }
219
GLHModelImporter >> convertApiFileAsFile: aAPIFile [
×
220

×
221
        aAPIFile type = 'tree' ifTrue: [ 
×
222
                ^ GLHFileDirectory new
×
223
                          name: aAPIFile name;
×
224
                          yourself ].
×
225
        ^ GLHFileBlob new
×
226
                  name: aAPIFile name;
×
227
                  yourself
×
228
]
×
229

230
{ #category : #'as yet unclassified' }
231
GLHModelImporter >> detectEntityType: aType overAttribut: aSelector equalTo: value [
×
232

×
233
        ^ (self glhModel allWithType: aType) detect: [ :entity |
×
234
                  (entity perform: aSelector) = value ] ifNone: [ nil ]. 
×
235
]
×
236

237
{ #category : #'as yet unclassified' }
238
GLHModelImporter >> filterCommitChanges: aCollection [
1✔
239

1✔
240
        ^ aCollection reject: [ :line |
1✔
241
                  | trimmedLine |
1✔
242
                  trimmedLine := line trimLeft.
1✔
243
                  (trimmedLine beginsWith: '---') or: [
1✔
244
                          (trimmedLine beginsWith: '+++') or: [
1✔
245
                                  trimmedLine beginsWith: '\ No newline at end of file' ] ] ]
1✔
246
]
1✔
247

248
{ #category : #accessing }
249
GLHModelImporter >> glhApi [
1✔
250

1✔
251
        ^ glhApi
1✔
252
]
1✔
253

254
{ #category : #accessing }
255
GLHModelImporter >> glhApi: anObject [
1✔
256

1✔
257
        glhApi := anObject
1✔
258
]
1✔
259

260
{ #category : #accessing }
261
GLHModelImporter >> glhModel [
1✔
262

1✔
263
        ^ glhModel
1✔
264
]
1✔
265

266
{ #category : #accessing }
267
GLHModelImporter >> glhModel: anObject [
1✔
268

1✔
269
        glhModel := anObject
1✔
270
]
1✔
271

272
{ #category : #'as yet unclassified' }
273
GLHModelImporter >> importActiveHumanUsers [
×
274

×
275
        | newlyFoundUser page foundUsers |
×
276
        page := 0.
×
277
        foundUsers := OrderedCollection new.
×
278
        newlyFoundUser := { true }.
×
279
        [ newlyFoundUser isNotEmpty ] whileTrue: [
×
280
                | results |
×
281
                page := page + 1.
×
282
                ('import users page ' , page printString) recordInfo.
×
283
                results := self glhApi
×
284
                                   usersHuman: true
×
285
                                   active: true
×
286
                                   withoutProjectBots: true
×
287
                                   perPage: 100
×
288
                                   page: page.
×
289

×
290
                newlyFoundUser := self parseUsersResult: results.
×
291
                "newlyFoundCommit do: [ :c | c repository: aProject repository ]."
×
292

×
293
                foundUsers addAll:
×
294
                        (self glhModel
×
295
                                 addAll: newlyFoundUser
×
296
                                 unless: self blockOnIdEquality) ].
×
297

×
298

×
299
        ^ foundUsers
×
300
]
×
301

302
{ #category : #api }
303
GLHModelImporter >> importAllGroups [
×
304

×
305
        | page foundGroups newlyFoundGroups |
×
306
        page := 0.
×
307
        foundGroups := OrderedCollection new.
×
308
        newlyFoundGroups := { true }.
×
309
        [ newlyFoundGroups isNotEmpty ] whileTrue: [
×
310
                | results |
×
311
                page := page + 1.
×
312
                results := self glhApi listGroupsWithTopLevelOnly: true page: page.
×
313

×
314
                newlyFoundGroups := generalReader
×
315
                                            on: results readStream;
×
316
                                            nextAs: #ArrayOfGroups.
×
317
                foundGroups addAll: newlyFoundGroups ].
×
318
        ^ foundGroups
×
319
]
×
320

321
{ #category : #'as yet unclassified' }
322
GLHModelImporter >> importAndLoadLatestsCommitsOfProject: aGLHProject [
×
323

×
324
        | commits |
×
325
        self completeImportProject: aGLHProject.
×
326
        commits := self importLastestCommitsOfProject: aGLHProject.
×
327
        commits do: [ :commit | self completeImportedCommit: commit ].
×
328
        self chainsCommitsFrom: commits.
×
329
        ^ commits
×
330
]
×
331

332
{ #category : #'private - api' }
333
GLHModelImporter >> importCommit: aCommitID ofProject: aGLHProject [
×
334

×
335
        | result parsedResult |
×
336
        (self glhModel allWithType: GLHCommit) asOrderedCollection
×
337
                detect: [ :commit | commit id = aCommitID ]
×
338
                ifFound: [ :commit | ^ commit ].
×
339
        result := self glhApi
×
340
                          commit: aCommitID
×
341
                          ofProject: aGLHProject id
×
342
                          withStat: false.
×
343
        parsedResult := self parseCommitResult: result.
×
344
        self
×
345
                addCommits: { parsedResult }
×
346
                toRepository: aGLHProject repository.
×
347
        ^ parsedResult
×
348
]
×
349

350
{ #category : #'as yet unclassified' }
351
GLHModelImporter >> importCommitOfProject: anProject withId: anID [
×
352

×
353
        | commit result |
×
354
        anID ifNil: [ ^ nil ].
×
355

×
356
        ('looking for commit ' , anID printString , ' in project : '
×
357
         , anProject id printString) recordInfo.
×
358

×
359
        commit := (self
×
360
                           detectEntityType: GLHCommit
×
361
                           overAttribut: #id
×
362
                           equalTo: anID) ifNil: [
×
363
                          result := self glhApi commit: anID ofProject: anProject id.
×
364
                          commit := (self parseCommitsResult: '[' , result , ']')
×
365
                                            first.
×
366

×
367
                          self glhModel add: commit unless: self blockOnIdEquality.
×
368
                          commit repository: anProject repository.
×
369

×
370
                          commit ].
×
371

×
372
        self withCommitDiffs ifTrue: [ self importDiffOfCommit: commit ].
×
373

×
374
        ^ commit
×
375
]
×
376

377
{ #category : #'as yet unclassified' }
378
GLHModelImporter >> importCommitsFollowing: aCommit upToDays: aNumberOfDay [
×
379
        "import the 'n' commits of a project starting from an initial 'aCommit' commit. 
×
380
        Lazy import does not import the entities inside the model"
×
381

×
382
        | date |
×
383
        date := aCommit created_at asDateAndTime.
×
384

×
385
        ^ self
×
386
                  importCommitsOfBranch: aCommit branch
×
387
                  forRefName: aCommit branch name
×
388
                  since: date
×
389
                  until: (date + aNumberOfDay day)
×
390
]
×
391

392
{ #category : #commit }
393
GLHModelImporter >> importCommitsOProject: aProject since: fromDate until: toDate [
×
394

×
395
        | newlyFoundCommit page foundCommit |
×
396
        page := 0.
×
397
        foundCommit := OrderedCollection new.
×
398
        newlyFoundCommit := { true }.
×
399
        [ newlyFoundCommit isNotEmpty ] whileTrue: [
×
400
                | results |
×
401
                page := page + 1.
×
402
                ('import commit page ' , page printString) recordInfo.
×
403
                results := self glhApi
×
404
                                   commitsOfProject: aProject id
×
405
                                   forRefName: nil
×
406
                                   since:
×
407
                                   (fromDate ifNotNil: [ fromDate asDateAndTime asString ])
×
408
                                   until:
×
409
                                   (toDate ifNotNil: [ toDate asDateAndTime asString ])
×
410
                                   path: nil
×
411
                                   author: nil
×
412
                                   all: true
×
413
                                   with_stats: true
×
414
                                   firstParent: nil
×
415
                                   order: nil
×
416
                                   trailers: nil
×
417
                                   perPage: 100
×
418
                                   page: page.
×
419

×
420
                newlyFoundCommit := self parseCommitsResult: results.
×
421
                "newlyFoundCommit do: [ :c | c repository: aProject repository ]."
×
422

×
423
                foundCommit addAll: (aProject repository commits
×
424
                        addAll: newlyFoundCommit
×
425
                        unless: self blockOnIdEquality). ].
×
426

×
427

×
428
        ^ self glhModel addAll: foundCommit unless: self blockOnIdEquality
×
429
]
×
430

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

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

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

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

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

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

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

×
483
        ^ foundCommit
×
484
]
×
485

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

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

496
{ #category : #'as yet unclassified' }
497
GLHModelImporter >> importContributedProjectsOfUser: aGLHUser [
×
498

×
499
        | newlyFoundElmts page foundElmts |
×
500
        page := 0.
×
501
        foundElmts := OrderedCollection new.
×
502
        newlyFoundElmts := { true }.
×
503
        [ newlyFoundElmts isNotEmpty ] whileTrue: [
×
504
                | results |
×
505
                page := page + 1.
×
506
                ('import contributed project of user ' , aGLHUser name , ' page '
×
507
                 , page printString) recordInfo.
×
508
                results := self glhApi 
×
509
                                   contributedProjectsOfUserId: aGLHUser id
×
510
                                   orderBy: 'last_activity_at'
×
511
                                   simple: true
×
512
                                   sort: 'desc'
×
513
                                   perPage: 100
×
514
                                   page: page.
×
515

×
516
                newlyFoundElmts := self parseArrayOfProject: results.
×
517

×
518
                foundElmts addAll:
×
519
                        (self glhModel
×
520
                                 addAll: newlyFoundElmts
×
521
                                 unless: self blockOnIdEquality) ].
×
522

×
523

×
524
        aGLHUser contributedProjects
×
525
                addAll: foundElmts
×
526
                unless: self blockOnIdEquality.
×
527

×
528
        ^ foundElmts
×
529
]
×
530

531
{ #category : #'as yet unclassified' }
532
GLHModelImporter >> importCreatorOfCommit: aCommit [
×
533

×
534
        aCommit commitCreator ifNil: [
×
535
                                
×
536
                aCommit commitCreator:
×
537
                
×
538
                        (self importUserByUsername: aCommit author_name) ]
×
539
]
×
540

541
{ #category : #api }
542
GLHModelImporter >> importDiffOfCommit: aCommit [
1✔
543

1✔
544
        | result diffsResult |
1✔
545
        aCommit diffs ifNotEmpty: [
1✔
546
                'Diff already importer: ' , aCommit short_id printString recordInfo.
1✔
547
                ^ aCommit diffs ].
1✔
548
        ('Import diff of commit: ' , aCommit short_id printString) recordInfo.
1✔
549
        result := self glhApi
1✔
550
                          commitDiff: aCommit id
1✔
551
                          ofProject: aCommit repository project id
1✔
552
                          unidiff: true.
1✔
553
        diffsResult := self newParseDiffResult: result.
1✔
554

1✔
555
        ^ aCommit diffs addAll: diffsResult unless: self blockForDiffEquality.
1✔
556

1✔
557
]
1✔
558

559
{ #category : #'private - api' }
560
GLHModelImporter >> importDirectoryFiles: aDirectoryFile OfBranch: aBranch [
×
561

×
562
        | result files apiFiles |
×
563
        result := self glhApi
×
564
                          treeOfRepository: aBranch repository project id
×
565
                          ofBranch: aBranch name
×
566
                          andPath: aDirectoryFile path , '/'.
×
567
        apiFiles := self parseFileTreeResult: result.
×
568
        files := apiFiles collect: [ :apiFile |
×
569
                         self convertApiFileAsFile: apiFile ].
×
570
        files do: [ :file |
×
571
                
×
572
                self glhModel add: file.
×
573
                aDirectoryFile addFile: file ].
×
574
        files
×
575
                select: [ :file | file isKindOf: GLHFileDirectory ]
×
576
                thenCollect: [ :file |
×
577
                self importDirectoryFiles: file OfBranch: aBranch ]
×
578
]
×
579

580
{ #category : #'private - api' }
581
GLHModelImporter >> importFilesOfBranch: aBranch [
×
582

×
583
        | result files apiFiles |
×
584
        result := self glhApi
×
585
                          treeOfRepository: aBranch repository project id
×
586
                          ofBranch: aBranch name
×
587
                          andPath: nil.
×
588
        apiFiles := self parseFileTreeResult: result.
×
589
        files := apiFiles collect: [ :apiFile | 
×
590
                         self convertApiFileAsFile: apiFile ].
×
591
        files do: [ :file | 
×
592
                self glhModel add: file.
×
593
                aBranch addFile: file ].
×
594
        files
×
595
                select: [ :file | file isKindOf: GLHFileDirectory ]
×
596
                thenCollect: [ :file | 
×
597
                self importDirectoryFiles: file OfBranch: aBranch ]
×
598
]
×
599

600
{ #category : #api }
601
GLHModelImporter >> importGroup: aGroupID [
1✔
602

1✔
603
        | result groupResult |
1✔
604
        ('Import group: ' , aGroupID printString) recordInfo.
1✔
605

1✔
606
        result := self glhApi group: aGroupID.
1✔
607
        groupResult := self parseGroupResult: result.
1✔
608
        groupResult := self addGroupResultToModel: groupResult.
1✔
609

1✔
610
        groupResult projects do: [ :project |
1✔
611
                self completeImportProject: project ].
1✔
612

1✔
613
        (self subGroupsOf: aGroupID) do: [ :subGroup |
1✔
614
                
1✔
615
                groupResult subGroups
1✔
616
                        add: (self importGroup: subGroup id)
1✔
617
                        unless: self blockOnIdEquality ].
1✔
618
        ^ groupResult
1✔
619
]
1✔
620

621
{ #category : #api }
622
GLHModelImporter >> importJobsOf: aPipeline [
×
623

×
624
        | result jobs |
×
625
        result := self glhApi
×
626
                          jobsOfProject: aPipeline project id
×
627
                          ofPipelines: aPipeline id.
×
628
        jobs := self parseJobsResult: result ofProject: aPipeline project.
×
629
        jobs do: [ :job | aPipeline addJob: job ].
×
630
        self glhModel addAll: jobs
×
631

×
632
]
×
633

634
{ #category : #'private - api' }
635
GLHModelImporter >> importLastestCommitsOfProject: aGLHProject [
1✔
636
        "limited to the last 50 commits"
1✔
637

1✔
638
        | results parsedResults |
1✔
639
        results := self glhApi
1✔
640
                           commitsOfProject: aGLHProject id
1✔
641
                           forRefName: nil
1✔
642
                           since: nil
1✔
643
                           until: nil
1✔
644
                           path: nil
1✔
645
                           author: nil
1✔
646
                           all: nil
1✔
647
                           with_stats: true
1✔
648
                           firstParent: nil
1✔
649
                           order: nil
1✔
650
                           trailers: nil
1✔
651
                           perPage: 50
1✔
652
                           page: nil.
1✔
653
        parsedResults := self parseCommitsResult: results.
1✔
654
        parsedResults := self glhModel addAll: parsedResults unless: self blockOnIdEquality.
1✔
655

1✔
656
        aGLHProject repository commits addAll: parsedResults unless: self blockOnIdEquality.
1✔
657
        "parsedResults do: [ :commit |
1✔
658
                commit repository: aGLHProject repository ]."
1✔
659

1✔
660
        self withCommitDiffs ifTrue: [
1✔
661
                parsedResults do: [ :commit | self importDiffOfCommit: commit ] ].
1✔
662

1✔
663
        ^ parsedResults
1✔
664
]
1✔
665

666
{ #category : #commit }
667
GLHModelImporter >> importParentCommitsOfCommit: aGLHCommit since: aDate [
×
668

×
669
        | parentsIds commits |
×
670
        commits := OrderedCollection new.
×
671
        aGLHCommit created_at asDateAndTime < aDate asDateAndTime ifTrue: [
×
672
                 
×
673
                ^ commits
×
674
                          add: aGLHCommit;
×
675
                          yourself ].
×
676

×
677
        parentsIds := aGLHCommit parent_ids.
×
678

×
679
        commits addAll: (parentsIds collect: [ :id |
×
680
                         self
×
681
                                 importCommitOfProject: aGLHCommit repository project
×
682
                                 withId: id ]).
×
683

×
684

×
685
        ^ (commits collect: [ :parentCommit |
×
686
                   self importParentCommitsOfCommit: parentCommit since: aDate ])
×
687
                  flatten
×
688
]
×
689

690
{ #category : #'private - api' }
691
GLHModelImporter >> importPipelinesOfProject: aGLHProject [
1✔
692

1✔
693
        (self pipelinesOf: aGLHProject id) do: [ :pipeline |
1✔
694
                self glhModel add: pipeline unless: self blockOnIdEquality .
1✔
695
                aGLHProject pipelines add: pipeline unless: self blockOnIdEquality]
1✔
696
]
1✔
697

698
{ #category : #projects }
699
GLHModelImporter >> importProject: aProjectID [
×
700

×
701
        | result projectResult |
×
702
        ('Import project with id: ' , aProjectID printString) recordInfo.
×
703

×
704
        result := self glhApi project: aProjectID.
×
705
        projectResult := self parseProjectResult: result.
×
706

×
707
        ^ self completeImportProject: projectResult
×
708
]
×
709

710
{ #category : #imports }
711
GLHModelImporter >> importProjects [
×
712

×
713
        ^ self importProjectsSince: nil
×
714
]
×
715

716
{ #category : #projects }
717
GLHModelImporter >> importProjects: aCollectionOfProjectID [
×
718

×
719
        ^ aCollectionOfProjectID collect: [ :id | self importProject: id ]
×
720
]
×
721

722
{ #category : #imports }
723
GLHModelImporter >> importProjectsSince: since [
×
724
        "heavy import of all projects"
×
725

×
726
        "copy import from commits"
×
727

×
728
        | newlyFoundProjects page foundProject amount |
×
729
        ('import all Projects since: ' , since printString) recordInfo.
×
730

×
731
        "number of projects per page"
×
732
        amount := 100.
×
733
        page := 0.
×
734
        foundProject := OrderedCollection new.
×
735
        newlyFoundProjects := { true }.
×
736
        [ newlyFoundProjects isNotEmpty ] whileTrue: [
×
737
                | results |
×
738
                page := page + 1.
×
739
                ('import projects page #' , page printString) recordInfo.
×
740

×
741
                results := self glhApi projects: amount since: since page: page.
×
742

×
743
                newlyFoundProjects := self glhModel
×
744
                                              addAll: (self parseArrayOfProject: results)
×
745
                                              unless: self blockOnIdEquality.
×
746
                foundProject addAll: newlyFoundProjects ].
×
747

×
748
        ^ foundProject
×
749
]
×
750

751
{ #category : #'private - api' }
752
GLHModelImporter >> importRepository: aGLHRepository [
1✔
753

1✔
754
        | resultBranches branches |
1✔
755
        [
1✔
756
        ('import the repository of project ' , aGLHRepository project name)
1✔
757
                recordInfo.
1✔
758

1✔
759
        resultBranches := self glhApi branchesOfRepository:
1✔
760
                                  aGLHRepository project id.
1✔
761
        branches := self parseBranchesResult: resultBranches.
1✔
762

1✔
763
        'import the branches of project ' recordInfo.
1✔
764

1✔
765
        branches := aGLHRepository branches
1✔
766
                            addAll: branches
1✔
767
                            unless: self blockOnNameEquality.
1✔
768
        branches := self glhModel
1✔
769
                            addAll: branches
1✔
770
                            unless: self blockOnNameEquality.
1✔
771

1✔
772

1✔
773
        self withFiles ifTrue: [
1✔
774
                branches do: [ :branch | self importFilesOfBranch: branch ] ] ]
1✔
775
                on: NeoJSONParseError
1✔
776
                do: [
1✔
777
                self inform: aGLHRepository project name , ' has no repository' ]
1✔
778
]
1✔
779

780
{ #category : #'private - api' }
781
GLHModelImporter >> importUser: aUserID [
1✔
782

1✔
783
        | result userResult |
1✔
784
        (self glhModel allWithType: GLHUser)
1✔
785
                detect: [ :user | user id = aUserID ]
1✔
786
                ifFound: [ :user | ^ user ].
1✔
787
        ('Import user: ' , aUserID printString) recordInfo.
1✔
788
        result := self glhApi user: aUserID.
1✔
789
        userResult := self parseUserResult: result.
1✔
790
        ^ self glhModel add: userResult unless: self blockOnIdEquality
1✔
791
]
1✔
792

793
{ #category : #user }
794
GLHModelImporter >> importUserByUsername: anUsername [
×
795

×
796
        | dicUsername resultUser |
×
797
        dicUsername := ((self glhModel allWithType: GLHUser) collect: [ :user |
×
798
                                user username -> user ]) asSet asDictionary.
×
799

×
800
        dicUsername addAll: self userCatalogue collectUsernames.
×
801

×
802

×
803
        resultUser := dicUsername
×
804
                              at: anUsername
×
805
                              ifAbsent: [ "thus we have to import this new user"
×
806
                                      | result userId searchResult |
×
807
                                      ('Import user with username: '
×
808
                                       , anUsername printString) recordInfo.
×
809
                                      result := self glhApi usersSearchByUsername:
×
810
                                                        anUsername.
×
811
                                      searchResult := NeoJSONReader fromString: result.
×
812

×
813
                                      (searchResult class = Dictionary and: [
×
814
                                               (searchResult at: #message) includesSubstring:
×
815
                                                       '403 Forbidden' ])
×
816
                                              ifTrue: [ "if the result is an 403 error we fake a new user"
×
817
                                                      self glhModel
×
818
                                                              add: (GLHUser new
×
819
                                                                               username: anUsername;
×
820
                                                                               name: anUsername;
×
821
                                                                               yourself)
×
822
                                                              unless: [ :nu :ou | nu username = ou username ] ]
×
823
                                              ifFalse: [
×
824
                                                      searchResult
×
825
                                                              ifEmpty: [ "results can be empty thus we force a new user with the info we have "
×
826
                                                                      self glhModel
×
827
                                                                              add: (GLHUser new
×
828
                                                                                               username: anUsername;
×
829
                                                                                               name: anUsername;
×
830
                                                                                               yourself)
×
831
                                                                              unless: [ :nu :ou | nu username = ou username ] ]
×
832
                                                              ifNotEmpty: [ "because we may already have the researched user, we look by ID in the model"
×
833
                                                                      userId := searchResult first at: #id.
×
834
                                                                      (self glhModel allWithType: GLHUser)
×
835
                                                                              detect: [ :user | user id = userId ]
×
836
                                                                              ifNone: [ self importUser: userId ] ] ] ].
×
837

×
838
        self userCatalogue addUser: resultUser withName: anUsername.
×
839

×
840
        ^ resultUser
×
841
]
×
842

843
{ #category : #initialization }
844
GLHModelImporter >> initReader [
1✔
845

1✔
846
        generalReader := NeoJSONReader new.
1✔
847
        self configureReaderForCommit: generalReader.
1✔
848
        self configureReaderForGroup: generalReader.
1✔
849
        self configureReaderForDiffs: generalReader. 
1✔
850
]
1✔
851

852
{ #category : #initialization }
853
GLHModelImporter >> initialize [
1✔
854

1✔
855
        withFiles := false.
1✔
856
        withCommitDiffs := false.
1✔
857
        withInitialCommits := false.
1✔
858
        withInitialMergeRequest := false.
1✔
859
        withCommitsSince := (Date today - 1 week) asDateAndTime.
1✔
860
        userCatalogue := GLHUserCatalogueV2 new
1✔
861
                                 anImporter: self;
1✔
862
                                 yourself.
1✔
863
        self initReader
1✔
864
]
1✔
865

866
{ #category : #importer }
867
GLHModelImporter >> loadAllProjectsFromRepositorySoftware [
×
868
        "heavy import that load all the active project inside the model. Only import the project entities"
×
869
        |projects|
×
870
        
×
871
        projects := self glhApi projects. 
×
872
]
×
873

874
{ #category : #'as yet unclassified' }
875
GLHModelImporter >> makeGlobal [
×
876
        currentImporter := self
×
877
]
×
878

879
{ #category : #private }
880
GLHModelImporter >> newParseCommitResult: result [
×
881

×
882
        generalReader  on: result readStream.
×
883

×
884
        ^ generalReader nextAs: GLHCommit
×
885
]
×
886

887
{ #category : #private }
888
GLHModelImporter >> newParseDiffResult: result [
1✔
889

1✔
890
        generalReader on: result readStream.
1✔
891
        ^ generalReader nextAs: #ArrayOfDiffs
1✔
892
]
1✔
893

894
{ #category : #parsing }
895
GLHModelImporter >> parseArrayOfProject: arrayOfProjects [
×
896

×
897
        | reader |
×
898
        reader := NeoJSONReader on: arrayOfProjects readStream.
×
899
        reader
×
900
                for: #ArrayOfProjects
×
901
                customDo: [ :customMappting |
×
902
                customMappting listOfElementSchema: GLHProject ].
×
903
        reader for: GLHProject do: [ :mapping |
×
904
                mapping mapInstVar: #name to: #name.
×
905
                mapping mapInstVar: #description to: #description.
×
906
                mapping mapInstVar: #id to: #id.
×
907
                mapping mapInstVar: #archived to: #archived.
×
908
                mapping mapInstVar: #web_url to: #html_url.
×
909
                mapping mapInstVar: #topics to: #topics ].
×
910
        ^ reader nextAs: #ArrayOfProjects
×
911
]
×
912

913
{ #category : #private }
914
GLHModelImporter >> parseBranchesResult: result [
1✔
915

1✔
916
        | reader |
1✔
917
        reader := NeoJSONReader on: result readStream.
1✔
918
        reader mapInstVarsFor: GLHBranch.
1✔
919
        reader
1✔
920
                for: #ArrayOfBranch
1✔
921
                customDo: [ :customMappting | 
1✔
922
                customMappting listOfElementSchema: GLHBranch ].
1✔
923
        ^ reader nextAs: #ArrayOfBranch
1✔
924
]
1✔
925

926
{ #category : #private }
927
GLHModelImporter >> parseCommitResult: result [
×
928

×
929
        | reader |
×
930
        reader := NeoJSONReader on: result readStream.
×
931

×
932
        reader for: GLHCommit do: [ :mapping |
×
933
                mapping mapInstVars:
×
934
                        #( id short_id title author_name author_email committer_name
×
935
                           committer_email message web_url ).
×
936
                (mapping mapInstVar: #authored_date) valueSchema: DateAndTime.
×
937
                (mapping mapInstVar: #committed_date) valueSchema: DateAndTime.
×
938
                (mapping mapInstVar: #created_at) valueSchema: DateAndTime.
×
939
                (mapping mapInstVar: #parent_ids) valueSchema: #ArrayOfIds.
×
940
                mapping
×
941
                        mapProperty: 'stats'
×
942
                        getter: [ :el | "Not used" ]
×
943
                        setter: [ :commit :value |
×
944
                                commit deletions: (value at: #deletions).
×
945
                                commit additions: (value at: #additions) ] ].
×
946

×
947
        reader for: DateAndTime customDo: [ :mapping |
×
948
                mapping decoder: [ :string | DateAndTime fromString: string ] ].
×
949

×
950
        reader
×
951
                for: #ArrayOfIds
×
952
                customDo: [ :mapping | mapping decoder: [ :string | string ] ].
×
953

×
954

×
955
        ^ reader nextAs: GLHCommit
×
956
]
×
957

958
{ #category : #private }
959
GLHModelImporter >> parseCommitsResult: result [
1✔
960

1✔
961
        | reader |
1✔
962
        reader := NeoJSONReader on: result readStream.
1✔
963

1✔
964
          reader for: GLHCommit do: [ :mapping |
1✔
965
                mapping mapInstVars:
1✔
966
                        #( id short_id title author_name author_email committer_name
1✔
967
                           committer_email message web_url ).
1✔
968
                (mapping mapInstVar: #authored_date) valueSchema: DateAndTime.
1✔
969
                (mapping mapInstVar: #committed_date) valueSchema: DateAndTime.
1✔
970
                (mapping mapInstVar: #created_at) valueSchema: DateAndTime.
1✔
971
                (mapping mapInstVar: #parent_ids) valueSchema: #ArrayOfIds.
1✔
972
                mapping
1✔
973
                        mapProperty: 'stats'
1✔
974
                        getter: [ :el | "Not used" ]
1✔
975
                        setter: [ :commit :value |
1✔
976
                                commit deletions: (value at: #deletions).
1✔
977
                                commit additions: (value at: #additions) ] ].
1✔
978

1✔
979
        reader for: DateAndTime customDo: [ :mapping |
1✔
980
                mapping decoder: [ :string | DateAndTime fromString: string ] ].
1✔
981

1✔
982
        reader
1✔
983
                for: #ArrayOfIds
1✔
984
                customDo: [ :mapping | mapping decoder: [ :string | string ] ].
1✔
985
  
1✔
986
        reader
1✔
987
                for: #ArrayOfCommit
1✔
988
                customDo: [ :customMappting |
1✔
989
                customMappting listOfElementSchema: GLHCommit ].
1✔
990

1✔
991
        ^ reader nextAs: #ArrayOfCommit
1✔
992
]
1✔
993

994
{ #category : #private }
995
GLHModelImporter >> parseFileTreeResult: aResult [
×
996

×
997
        | reader |
×
998
        reader := NeoJSONReader on: aResult readStream.
×
999
        reader mapInstVarsFor: GLHApiFile.
×
1000
        reader
×
1001
                for: #ArrayOfFile
×
1002
                customDo: [ :customMappting | 
×
1003
                customMappting listOfElementSchema: GLHApiFile ].
×
1004
        ^ reader nextAs: #ArrayOfFile
×
1005
]
×
1006

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

1✔
1010
        | reader |
1✔
1011

1✔
1012
        reader := NeoJSONReader on: aResult readStream.
1✔
1013
        reader for: GLHGroup do: [ :mapping |
1✔
1014
                mapping mapInstVars.
1✔
1015
                (mapping mapInstVar: #projects) valueSchema: #ArrayOfProjects ].
1✔
1016
        reader mapInstVarsFor: GLHProject.
1✔
1017
        reader
1✔
1018
                for: #ArrayOfProjects
1✔
1019
                customDo: [ :customMappting |
1✔
1020
                customMappting listOfElementSchema: GLHProject ].
1✔
1021
        ^ reader nextAs: GLHGroup
1✔
1022
]
1✔
1023

1024
{ #category : #private }
1025
GLHModelImporter >> parseJobsResult: result ofProject: aProject [
×
1026

×
1027
        | reader |
×
1028
        reader := NeoJSONReader on: result readStream.
×
1029
        reader for: GLHJob do: [ :mapping |
×
1030
                mapping mapInstVars: #( id allow_failure web_url name ).
×
1031

×
1032
                mapping
×
1033
                        mapProperty: #user
×
1034
                        getter: [ :object | #ignore ]
×
1035
                        setter: [ :object :value |
×
1036
                        object user: (self importUser: (value at: #id)) ].
×
1037

×
1038
                mapping
×
1039
                        mapProperty: #commit
×
1040
                        getter: [ :object | #ignore ]
×
1041
                        setter: [ :object :value |
×
1042
                                value ifNotNil: [
×
1043
                                        object commit:
×
1044
                                                (self importCommit: (value at: #id) ofProject: aProject) ] ].
×
1045

×
1046
                mapping
×
1047
                        mapProperty: #duration
×
1048
                        getter: [ :object | #ignore ]
×
1049
                        setter: [ :object :value |
×
1050
                        value ifNotNil: [ object duration: value seconds ] ] ].
×
1051

×
1052
        reader
×
1053
                for: #ArrayOfGLHJob
×
1054
                customDo: [ :customMappting |
×
1055
                customMappting listOfElementSchema: GLHJob ].
×
1056
        ^ reader nextAs: #ArrayOfGLHJob
×
1057
]
×
1058

1059
{ #category : #private }
1060
GLHModelImporter >> parsePipelinesResult: result [
1✔
1061

1✔
1062
        | reader |
1✔
1063
        
1✔
1064
        result = '{"message":"403 Forbidden"}' ifTrue: [ ^ {  } ].
1✔
1065
        
1✔
1066
        reader := NeoJSONReader on: result readStream.
1✔
1067
        reader mapInstVarsFor: GLHPipeline.
1✔
1068
        reader for: GLHPipeline do: [ :mapping |
1✔
1069
                mapping
1✔
1070
                        mapProperty: #created_at
1✔
1071
                        getter: [ :object | #ignore ]
1✔
1072
                        setter: [ :object :value |
1✔
1073
                        object runDate: (DateAndTime fromString: value) ] ].
1✔
1074
        reader
1✔
1075
                for: #ArrayOfPipelines
1✔
1076
                customDo: [ :customMappting |
1✔
1077
                customMappting listOfElementSchema: GLHPipeline ].
1✔
1078
        ^ reader nextAs: #ArrayOfPipelines
1✔
1079
]
1✔
1080

1081
{ #category : #parsing }
1082
GLHModelImporter >> parseProjectResult: aResult [ 
×
1083
                | reader |
×
1084
        reader := NeoJSONReader on: aResult readStream.
×
1085
        reader for: GLHProject do: [ :mapping |
×
1086
                mapping mapInstVars. ].
×
1087
"        reader mapInstVarsFor: GLHProject."
×
1088

×
1089
        ^ reader nextAs: GLHProject
×
1090
]
×
1091

×
1092
{ #category : #private }
×
1093
GLHModelImporter >> parseSubGroupResult: aResult [
×
1094

×
1095
        | reader |
×
1096
        reader := NeoJSONReader on: aResult readStream.
×
1097
        self configureReaderForGroup: reader.
×
1098
        ^ reader nextAs: #ArrayOfGroups
×
1099
]
×
1100

×
1101
{ #category : #private }
×
1102
GLHModelImporter >> parseUserResult: result [
×
1103

×
1104
        | reader |
×
1105
        reader := NeoJSONReader on: result readStream.
×
1106
        reader mapInstVarsFor: GLHUser.
×
1107
        ^ reader nextAs: GLHUser
×
1108
]
×
1109

×
1110
{ #category : #private }
×
1111
GLHModelImporter >> parseUsersResult: result [
×
1112

×
1113
        | reader |
×
1114
        reader := NeoJSONReader on: result readStream.
×
1115

×
1116
        reader mapInstVarsFor: GLHUser.
×
1117

×
1118
        reader
×
1119
                for: #ArrayOfUser
×
1120
                customDo: [ :customMappting |
×
1121
                customMappting listOfElementSchema: GLHUser ].
×
1122

×
1123
        ^ reader nextAs: #ArrayOfUser
×
1124
]
×
1125

×
1126
{ #category : #'private - api' }
×
1127
GLHModelImporter >> pipelinesOf: aProjectID [
×
1128

×
1129
        | result |
×
1130
        ('Search pipelines of: ' , aProjectID printString) recordInfo.
×
1131
        result := self glhApi pipelinesOfProject: aProjectID.
×
NEW
1132
        ^ self parsePipelinesResult: result .
×
1133
]
×
1134

×
1135
{ #category : #'private - api' }
×
1136
GLHModelImporter >> subGroupsOf: aGroupID [
×
1137

×
1138
        | results parsedResult result page |
×
1139
        ('Search subgroup of: ' , aGroupID printString) recordInfo.
×
1140
        results := OrderedCollection new.
×
1141
        page := 0.
×
1142
        
×
1143
        parsedResult := { true }.
×
1144
        [ parsedResult size > 0 ] whileTrue: [ 
×
1145
                result := self glhApi subgroupsOfGroup: aGroupID page: page.
×
1146
                parsedResult := self parseSubGroupResult: result.
×
1147
                results addAll: parsedResult.
×
1148
                                page := page + 1. ].
×
1149
        
×
1150
        ^ results
×
1151
]
×
1152

×
1153
{ #category : #accessing }
×
1154
GLHModelImporter >> userCatalogue [
×
1155
        ^ userCatalogue 
×
1156
]
×
1157

×
1158
{ #category : #accessing }
×
1159
GLHModelImporter >> userCatalogue: aGLHUserCatalogue [
×
1160

×
1161
        userCatalogue := aGLHUserCatalogue.
×
1162
        aGLHUserCatalogue anImporter: self. 
×
1163
]
×
1164

×
1165
{ #category : #accessing }
×
1166
GLHModelImporter >> withCommitDiffs [
×
1167

×
1168
        ^ withCommitDiffs
×
1169
]
×
1170

×
1171
{ #category : #accessing }
×
1172
GLHModelImporter >> withCommitDiffs: anObject [
×
1173

×
1174
        withCommitDiffs := anObject
×
1175
]
×
1176

×
1177
{ #category : #accessing }
×
1178
GLHModelImporter >> withFiles [
×
1179
        ^ withFiles
×
1180
]
×
1181

×
1182
{ #category : #accessing }
×
1183
GLHModelImporter >> withFiles: aBoolean [
×
1184
        withFiles := aBoolean
×
1185
]
×
1186

×
1187
{ #category : #accessing }
×
1188
GLHModelImporter >> withInitialCommits: boolean [
×
1189
        withInitialCommits := boolean 
×
1190
]
×
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