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

moosetechnology / GitProjectHealth / 10317227213

09 Aug 2024 09:48AM UTC coverage: 33.305%. First build
10317227213

Pull #21

github

web-flow
Merge 90adcab17 into ff6cec92d
Pull Request #21: fix import project location

20 of 22 new or added lines in 1 file covered. (90.91%)

2746 of 8245 relevant lines covered (33.31%)

0.33 hits per line

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

57.83
/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
        ],
14
        #classVars : [
15
                'currentImporter'
16
        ],
17
        #category : #'GitLabHealth-Model-Importer'
18
}
19

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

×
23
        ^ currentImporter
×
24
]
×
25

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

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

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

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

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

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

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

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

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

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

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

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

89
{ #category : #'private - api' }
90
GLHModelImporter >> completeImportProject: aGLHProject [
1✔
91
        |importedProject|
1✔
92
        ('Complete import of project: ' , aGLHProject id printString)
1✔
93
                recordInfo.
1✔
94
        importedProject := self glhModel add: aGLHProject unless: (self blockOnIdEquality ).
1✔
95

1✔
96
        self importPipelinesOfProject: importedProject.
1✔
97

1✔
98
        "aGLHProject creator: (self importUser: aGLHProject creator_id)."
1✔
99

1✔
100
        (self importUser: importedProject creator_id) addCreatedProject:
1✔
101
                importedProject.
1✔
102

1✔
103

1✔
104
        importedProject repository: GLHRepository new.
1✔
105
        self glhModel add: importedProject repository.
1✔
106
        self importRepository: importedProject repository.
1✔
107

1✔
108
        ^ importedProject
1✔
109
]
1✔
110

111
{ #category : #'as yet unclassified' }
112
GLHModelImporter >> completeImportedCommit: aCommit [
1✔
113

1✔
114
        ('completing commit: ' , aCommit short_id printString) recordInfo.
1✔
115
        self importCreatorOfCommit: aCommit.
1✔
116

1✔
117
        self withCommitDiffs ifTrue: [
1✔
118
                | diffs |
1✔
119
                aCommit diffs ifEmpty: [
1✔
120
                        diffs := self importDiffOfCommit: aCommit.
1✔
121
                        self glhModel addAll: diffs unless: self blockForDiffEquality ] ].
1✔
122

1✔
123
        ^ aCommit
1✔
124
]
1✔
125

126
{ #category : #private }
127
GLHModelImporter >> configureReaderForCommit: reader [
1✔
128

1✔
129
          reader for: GLHCommit do: [ :mapping |
1✔
130
                mapping mapInstVars:
1✔
131
                        #( id short_id title author_name author_email committer_name
1✔
132
                           committer_email message web_url ).
1✔
133
                (mapping mapInstVar: #authored_date) valueSchema: DateAndTime.
1✔
134
                (mapping mapInstVar: #committed_date) valueSchema: DateAndTime.
1✔
135
                (mapping mapInstVar: #created_at) valueSchema: DateAndTime.
1✔
136
                (mapping mapInstVar: #parent_ids) valueSchema: #ArrayOfIds.
1✔
137
                mapping
1✔
138
                        mapProperty: 'stats'
1✔
139
                        getter: [ :el | "Not used" ]
1✔
140
                        setter: [ :commit :value |
1✔
141
                                commit deletions: (value at: #deletions).
1✔
142
                                commit additions: (value at: #additions) ] ].
1✔
143

1✔
144
        reader for: DateAndTime customDo: [ :mapping |
1✔
145
                mapping decoder: [ :string | DateAndTime fromString: string ] ].
1✔
146

1✔
147
        reader
1✔
148
                for: #ArrayOfIds
1✔
149
                customDo: [ :mapping | mapping decoder: [ :string | string ] ].
1✔
150
  
1✔
151
        reader
1✔
152
                for: #ArrayOfCommit
1✔
153
                customDo: [ :customMappting |
1✔
154
                customMappting listOfElementSchema: GLHCommit ].
1✔
155

1✔
156
]
1✔
157

158
{ #category : #'as yet unclassified' }
159
GLHModelImporter >> configureReaderForDiffs: reader [
1✔
160

1✔
161
        reader for: GLHDiff do: [ :mapping |
1✔
162
                mapping mapInstVars:
1✔
163
                        #( deleted_file new_file new_path old_path renamed_file ).
1✔
164
                mapping mapInstVar: #diffString to: #diff ].
1✔
165

1✔
166
        reader
1✔
167
                for: #ArrayOfDiffs
1✔
168
                customDo: [ :customMappting |
1✔
169
                customMappting listOfElementSchema: GLHDiff ].
1✔
170
        ^ reader
1✔
171
]
1✔
172

173
{ #category : #private }
174
GLHModelImporter >> configureReaderForGroup: reader [
1✔
175

1✔
176
        reader for: GLHGroup do: [ :mapping |
1✔
177
                mapping mapInstVars.
1✔
178
                (mapping mapInstVar: #projects) valueSchema: #ArrayOfProjects ].
1✔
179
        reader mapInstVarsFor: GLHProject.
1✔
180
        reader
1✔
181
                for: #ArrayOfProjects
1✔
182
                customDo: [ :customMappting |
1✔
183
                customMappting listOfElementSchema: GLHProject ].
1✔
184
        reader
1✔
185
                for: #ArrayOfGroups
1✔
186
                customDo: [ :customMappting |
1✔
187
                customMappting listOfElementSchema: GLHGroup ]
1✔
188
]
1✔
189

190
{ #category : #private }
191
GLHModelImporter >> convertApiFileAsFile: aAPIFile [
×
192

×
193
        aAPIFile type = 'tree' ifTrue: [ 
×
194
                ^ GLHFileDirectory new
×
195
                          name: aAPIFile name;
×
196
                          yourself ].
×
197
        ^ GLHFileBlob new
×
198
                  name: aAPIFile name;
×
199
                  yourself
×
200
]
×
201

202
{ #category : #'as yet unclassified' }
203
GLHModelImporter >> detectEntityType: aType overAttribut: aSelector equalTo: value [
1✔
204

1✔
205
        ^ (self glhModel allWithType: aType) detect: [ :entity |
1✔
206
                  (entity perform: aSelector) = value ] ifNone: [ nil ]. 
1✔
207
]
1✔
208

209
{ #category : #'as yet unclassified' }
210
GLHModelImporter >> filterCommitChanges: aCollection [
1✔
211

1✔
212
        ^ aCollection reject: [ :line |
1✔
213
                  | trimmedLine |
1✔
214
                  trimmedLine := line trimLeft.
1✔
215
                  (trimmedLine beginsWith: '---') or: [
1✔
216
                          (trimmedLine beginsWith: '+++') or: [
1✔
217
                                  trimmedLine beginsWith: '\ No newline at end of file' ] ] ]
1✔
218
]
1✔
219

220
{ #category : #accessing }
221
GLHModelImporter >> glhApi [
1✔
222

1✔
223
        ^ glhApi
1✔
224
]
1✔
225

226
{ #category : #accessing }
227
GLHModelImporter >> glhApi: anObject [
1✔
228

1✔
229
        glhApi := anObject
1✔
230
]
1✔
231

232
{ #category : #accessing }
233
GLHModelImporter >> glhModel [
1✔
234

1✔
235
        ^ glhModel
1✔
236
]
1✔
237

238
{ #category : #accessing }
239
GLHModelImporter >> glhModel: anObject [
1✔
240

1✔
241
        glhModel := anObject
1✔
242
]
1✔
243

244
{ #category : #api }
245
GLHModelImporter >> importAllGroups [
×
246

×
247
        | page foundGroups newlyFoundGroups |
×
248
        page := 0.
×
249
        foundGroups := OrderedCollection new.
×
250
        newlyFoundGroups := { true }.
×
251
        [ newlyFoundGroups isNotEmpty ] whileTrue: [
×
252
                | results |
×
253
                page := page + 1.
×
254
                results := self glhApi listGroupsWithTopLevelOnly: true page: page.
×
255

×
256
                newlyFoundGroups := generalReader
×
257
                                            on: results readStream;
×
258
                                            nextAs: #ArrayOfGroups.
×
259
                foundGroups addAll: newlyFoundGroups ].
×
260
        ^ foundGroups
×
261
]
×
262

263
{ #category : #'private - api' }
264
GLHModelImporter >> importCommit: aCommitID ofProject: aGLHProject [
×
265

×
266
        | result parsedResult |
×
267
        (glhModel allWithType: GLHCommit) asOrderedCollection
×
268
                detect: [ :commit | commit id = aCommitID ]
×
269
                ifFound: [ :commit | ^ commit ].
×
270
        result := self glhApi
×
271
                          commit: aCommitID
×
272
                          ofProject: aGLHProject id
×
273
                          withStat: false.
×
274
        parsedResult := self parseCommitResult: result.
×
275
        self
×
276
                addCommits: { parsedResult }
×
277
                toRepository: aGLHProject repository.
×
278
        ^ parsedResult
×
279
]
×
280

281
{ #category : #'as yet unclassified' }
282
GLHModelImporter >> importCommitOfProject: anProject withId: anID [
1✔
283

1✔
284
        | commit result |
1✔
285
        anID ifNil: [ ^ nil ].
1✔
286

1✔
287
        ('looking for commit ' , anID printString , ' in project : '
1✔
288
         , anProject id printString) recordInfo.
1✔
289

1✔
290
        commit := (self
1✔
291
                           detectEntityType: GLHCommit
1✔
292
                           overAttribut: #id
1✔
293
                           equalTo: anID) ifNil: [
1✔
294
                          result := self glhApi commit: anID ofProject: anProject id.
1✔
295
                          commit := (self parseCommitsResult: '[' , result , ']')
1✔
296
                                            first.
1✔
297

1✔
298
                          self glhModel add: commit unless: self blockOnIdEquality.
1✔
299
                          commit repository: anProject repository.
1✔
300

1✔
301
                          commit ].
1✔
302

1✔
303
        self withCommitDiffs ifTrue: [ self importDiffOfCommit: commit ].
1✔
304

1✔
305
        ^ commit
1✔
306
]
1✔
307

308
{ #category : #'private - api' }
309
GLHModelImporter >> importCommits: aGLHProject [
1✔
310
        "limited to the last 20 commits"
1✔
311

1✔
312
        | results parsedResults |
1✔
313
        results := self glhApi
1✔
314
                           commitsOfProject: aGLHProject id
1✔
315
                           forRefName: nil
1✔
316
                           since: nil
1✔
317
                           until: nil
1✔
318
                           path: nil
1✔
319
                           author: nil
1✔
320
                           all: nil
1✔
321
                           with_stats: true
1✔
322
                           firstParent: nil
1✔
323
                           order: nil
1✔
324
                           trailers: nil
1✔
325
                           perPage: nil
1✔
326
                           page: nil.
1✔
327
        parsedResults := self parseCommitsResult: results.
1✔
328
        self glhModel addAll: parsedResults unless: self blockOnIdEquality.
1✔
329

1✔
330
        parsedResults do: [ :commit |
1✔
331
                commit repository: aGLHProject repository ].
1✔
332

1✔
333
        self withCommitDiffs ifTrue: [
1✔
334
                parsedResults do: [ :commit | self importDiffOfCommit: commit ] ].
1✔
335
        
1✔
336
        ^ parsedResults. 
1✔
337
]
1✔
338

339
{ #category : #'as yet unclassified' }
340
GLHModelImporter >> importCommitsFollowing: aCommit upToDays: aNumberOfDay [
×
341
        "import the 'n' commits of a project starting from an initial 'aCommit' commit. 
×
342
        Lazy import does not import the entities inside the model"
×
343

×
344
        | date |
×
345
        date := aCommit created_at asDateAndTime.
×
346

×
347
        ^ self
×
348
                  importCommitsOfBranch: aCommit branch
×
349
                  forRefName: aCommit branch name
×
350
                  since: date
×
351
                  until: (date + aNumberOfDay day)
×
352
]
×
353

354
{ #category : #commit }
355
GLHModelImporter >> importCommitsOProject: aProject since: fromDate until: toDate [
1✔
356

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

1✔
382
                newlyFoundCommit := self parseCommitsResult: results.
1✔
383
                "newlyFoundCommit do: [ :c | c repository: aProject repository ]."
1✔
384

1✔
385
                foundCommit addAll: (aProject repository commits
1✔
386
                        addAll: newlyFoundCommit
1✔
387
                        unless: self blockOnIdEquality). ].
1✔
388

1✔
389

1✔
390
        ^ self glhModel addAll: foundCommit unless: self blockOnIdEquality
1✔
391
]
1✔
392

393
{ #category : #api }
394
GLHModelImporter >> importCommitsOf: aGLHProject withStats: aBoolean until: toDate [
×
395

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

×
423
                newlyFoundCommit := parsedResults reject: [ :commitParsed |
×
424
                                            (toDate isNil or: [
×
425
                                                     commitParsed committed_date
×
426
                                                     < toDate asDateAndTime ]) or: [
×
427
                                                    existingCommits anySatisfy: [ :existingCommit |
×
428
                                                            existingCommit id = commitParsed id ] ] ].
×
429
                aGLHProject mooseModel addAll: newlyFoundCommit.
×
430
                aGLHProject repository commits addAll: newlyFoundCommit ].
×
431

×
432

×
433
        self withCommitDiffs ifTrue: [
×
434
                aGLHProject repository commits do: [ :commit |
×
435
                        self importDiffOfCommit: commit ] ]
×
436
]
×
437

438
{ #category : #commit }
439
GLHModelImporter >> importCommitsOfBranch: aGLHBranch forRefName: refName since: fromDate [
×
440

×
441
        ^ self
×
442
                  importCommitsOfBranch: aGLHBranch
×
443
                  forRefName: aGLHBranch name
×
444
                  since: fromDate
×
445
                  until: nil
×
446
]
×
447

448
{ #category : #commit }
449
GLHModelImporter >> importCommitsOfBranch: aGLHBranch forRefName: refName since: fromDate until: toDate [
×
450

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

×
476
                newlyFoundCommit := self parseCommitsResult: results.
×
477
        aGLHBranch commits
×
478
                        addAll: newlyFoundCommit
×
479
                        unless: self blockOnIdEquality.
×
480
        foundCommit addAll: newlyFoundCommit.  
×
481
                        ].
×
482

×
483
        self glhModel
×
484
                addAll: aGLHBranch commits
×
485
                unless: self blockOnIdEquality.
×
486

×
487
        "self withCommitDiffs ifTrue: [
×
488
                aGLHBranch commits: [ :commit | self importDiffOfCommit: commit ] ]."
×
489

×
490
        ^ foundCommit
×
491
]
×
492

493
{ #category : #commit }
494
GLHModelImporter >> importCommitsOfBranch: aGLHBranch forRefName: refName until: toDate [
×
495

×
496
        ^ self
×
497
                  importCommitsOfBranch: aGLHBranch
×
498
                  forRefName: aGLHBranch name
×
499
                  since: nil
×
500
                  until: toDate
×
501
]
×
502

503
{ #category : #'as yet unclassified' }
504
GLHModelImporter >> importCreatorOfCommit: aCommit [
1✔
505
        
1✔
506
        aCommit commitCreator ifNil: [
1✔
507
                aCommit commitCreator:
1✔
508
                        (self importUserByUsername: aCommit author_name) ]
1✔
509
]
1✔
510

511
{ #category : #api }
512
GLHModelImporter >> importDiffOfCommit: aCommit [
1✔
513

1✔
514
        | result diffsResult |
1✔
515
        aCommit diffs ifNotEmpty: [
1✔
516
                'Diff already importer: ' , aCommit short_id printString recordInfo.
1✔
517
                ^ aCommit diffs ].
1✔
518
        ('Import diff of commit: ' , aCommit short_id printString) recordInfo.
1✔
519
        result := self glhApi
1✔
520
                          commitDiff: aCommit id
1✔
521
                          ofProject: aCommit repository project id
1✔
522
                          unidiff: true.
1✔
523
        diffsResult := self newParseDiffResult: result.
1✔
524

1✔
525
        ^ aCommit diffs addAll: diffsResult unless: self blockForDiffEquality.
1✔
526

1✔
527
]
1✔
528

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

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

550
{ #category : #'private - api' }
551
GLHModelImporter >> importFilesOfBranch: aBranch [
×
552

×
553
        | result files apiFiles |
×
554
        result := self glhApi
×
555
                          treeOfRepository: aBranch repository project id
×
556
                          ofBranch: aBranch name
×
557
                          andPath: nil.
×
558
        apiFiles := self parseFileTreeResult: result.
×
559
        files := apiFiles collect: [ :apiFile | 
×
560
                         self convertApiFileAsFile: apiFile ].
×
561
        files do: [ :file | 
×
562
                self glhModel add: file.
×
563
                aBranch addFile: file ].
×
564
        files
×
565
                select: [ :file | file isKindOf: GLHFileDirectory ]
×
566
                thenCollect: [ :file | 
×
567
                self importDirectoryFiles: file OfBranch: aBranch ]
×
568
]
×
569

570
{ #category : #api }
571
GLHModelImporter >> importGroup: aGroupID [
1✔
572

1✔
573
        | result groupResult |
1✔
574
        ('Import group: ' , aGroupID printString) recordInfo.
1✔
575

1✔
576
        result := self glhApi group: aGroupID.
1✔
577
        groupResult := self parseGroupResult: result.
1✔
578
        groupResult := self addGroupResultToModel: groupResult.
1✔
579

1✔
580
        groupResult projects do: [ :project |
1✔
581
                self completeImportProject: project ].
1✔
582

1✔
583
        (self subGroupsOf: aGroupID) do: [ :subGroup |
1✔
584
                
1✔
585
                groupResult subGroups
1✔
586
                        add: (self importGroup: subGroup id)
1✔
587
                        unless: self blockOnIdEquality ].
1✔
588
        ^ groupResult
1✔
589
]
1✔
590

591
{ #category : #api }
592
GLHModelImporter >> importJobsOf: aPipeline [
×
593

×
594
        | result jobs |
×
595
        result := self glhApi
×
596
                          jobsOfProject: aPipeline project id
×
597
                          ofPipelines: aPipeline id.
×
598
        jobs := self parseJobsResult: result ofProject: aPipeline project.
×
599
        jobs do: [ :job | aPipeline addJob: job ].
×
600
        self glhModel addAll: jobs
×
601

×
602
]
×
603

604
{ #category : #commit }
605
GLHModelImporter >> importParentCommitsOfCommit: aGLHCommit forOnly: number [
×
606

×
607
        | parentsIds commits |
×
608
        commits := OrderedCollection new.
×
609
        number = 0 ifTrue: [
×
610
                ^ commits
×
611
                          add: aGLHCommit;
×
612
                          yourself ].
×
613

×
614
        parentsIds := aGLHCommit parent_ids.
×
615

×
616
        commits addAll: (parentsIds collect: [ :id |
×
617
                         self
×
618
                                 importCommitOfProject: aGLHCommit repository project
×
619
                                 withId: id.
×
620
                         (self selectEntityType: GLHCommit overAttribut: #id equalTo: id)
×
621
                                 first ]).
×
622

×
623

×
624
        ^ commits , (commits collect: [ :parentCommit |
×
625
                   self
×
626
                           importParentCommitsOfCommit: parentCommit
×
627
                           forOnly: number - 1 ]) flatten
×
628
]
×
629

630
{ #category : #commit }
631
GLHModelImporter >> importParentCommitsOfCommit: aGLHCommit since: aDate [
×
632

×
633
        | parentsIds commits |
×
634
        commits := OrderedCollection new.
×
635
        aGLHCommit created_at asDateAndTime < aDate asDateAndTime ifTrue: [
×
636
                 
×
637
                ^ commits
×
638
                          add: aGLHCommit;
×
639
                          yourself ].
×
640

×
641
        parentsIds := aGLHCommit parent_ids.
×
642

×
643
        commits addAll: (parentsIds collect: [ :id |
×
644
                         self
×
645
                                 importCommitOfProject: aGLHCommit repository project
×
646
                                 withId: id ]).
×
647

×
648

×
649
        ^ (commits collect: [ :parentCommit |
×
650
                   self importParentCommitsOfCommit: parentCommit since: aDate ])
×
651
                  flatten
×
652
]
×
653

654
{ #category : #'private - api' }
655
GLHModelImporter >> importPipelinesOfProject: aGLHProject [
1✔
656

1✔
657
        (self pipelinesOf: aGLHProject id) do: [ :pipeline |
1✔
658
                self glhModel add: pipeline unless: self blockOnIdEquality .
1✔
659
                aGLHProject pipelines add: pipeline unless: self blockOnIdEquality]
1✔
660
]
1✔
661

662
{ #category : #projects }
663
GLHModelImporter >> importProject: aProjectID [
1✔
664

1✔
665
        | result projectResult |
1✔
666
        ('Import project with id: ' , aProjectID printString) recordInfo.
1✔
667

1✔
668
        result := self glhApi project: aProjectID.
1✔
669
        projectResult := self parseProjectResult: result.
1✔
670

1✔
671
        ^ self completeImportProject: projectResult
1✔
672
]
1✔
673

674
{ #category : #imports }
675
GLHModelImporter >> importProjects [
×
676

×
677
        ^ self importProjectsSince: nil
×
678
]
×
679

680
{ #category : #projects }
681
GLHModelImporter >> importProjects: aCollectionOfProjectID [
×
NEW
682

×
NEW
683
        ^ aCollectionOfProjectID collect: [ :id | self importProject: id ]
×
684
]
×
685

686
{ #category : #imports }
687
GLHModelImporter >> importProjectsSince: since [
×
688
        "heavy import of all projects"
×
689

×
690
        "copy import from commits"
×
691

×
692
        | newlyFoundProjects page foundProject amount |
×
693
        ('import all Projects since: ', since printString) recordInfo.
×
694

×
695
        "number of projects per page"
×
696
        amount := 100.
×
697
        page := 0.
×
698
        foundProject := OrderedCollection new.
×
699
        newlyFoundProjects := { true }.
×
700
        [ newlyFoundProjects isNotEmpty ] whileTrue: [
×
701
                | results |
×
702
                page := page + 1.
×
703
                ('import projects page #' , page printString) recordInfo.
×
704
                
×
705
                results := self glhApi projects: amount since: since page: page.
×
706

×
707
                newlyFoundProjects := glhModel
×
708
                                              addAll: (self parseArrayOfProject: results)
×
709
                                              unless: self blockOnIdEquality.
×
710
                foundProject addAll: newlyFoundProjects ].
×
711

×
712
        ^ foundProject
×
713
]
×
714

715
{ #category : #'private - api' }
716
GLHModelImporter >> importRepository: aGLHRepository [
1✔
717

1✔
718
        | resultBranches branches |
1✔
719
        [
1✔
720
        ('import the repository of project ' , aGLHRepository project name)
1✔
721
                recordInfo.
1✔
722

1✔
723
        resultBranches := self glhApi branchesOfRepository:
1✔
724
                                  aGLHRepository project id.
1✔
725
        branches := self parseBranchesResult: resultBranches.
1✔
726

1✔
727
        ('import the branches of project ') recordInfo.
1✔
728

1✔
729
        branches := aGLHRepository branches
1✔
730
                addAll: branches
1✔
731
                unless: self blockOnNameEquality.
1✔
732
        branches := self glhModel addAll: branches unless: self blockOnNameEquality.
1✔
733

1✔
734

1✔
735
        self withFiles ifTrue: [
1✔
736
                branches do: [ :branch | self importFilesOfBranch: branch ] ] ]
1✔
737
                on: NeoJSONParseError
1✔
738
                do: [
1✔
739
                self inform: aGLHRepository project name , ' has no repository' ]
1✔
740
]
1✔
741

742
{ #category : #'private - api' }
743
GLHModelImporter >> importUser: aUserID [
1✔
744

1✔
745
        | result userResult |
1✔
746
        (glhModel allWithType: GLHUser)
1✔
747
                detect: [ :user | user id = aUserID ]
1✔
748
                ifFound: [ :user | ^ user ].
1✔
749
        ('Import user: ' , aUserID printString) recordInfo.
1✔
750
        result := self glhApi user: aUserID.
1✔
751
        userResult := self parseUserResult: result.
1✔
752
        ^ glhModel add: userResult unless: self blockOnIdEquality
1✔
753
]
1✔
754

755
{ #category : #user }
756
GLHModelImporter >> importUserByUsername: anUsername [
1✔
757

1✔
758
        | dicUsername |
1✔
759
        dicUsername := ((self glhModel allWithType: GLHUser) collect: [ :user |
1✔
760
                                user username -> user ]) asSet asDictionary.
1✔
761

1✔
762
        ^ dicUsername at: anUsername ifPresent: [ :user | user ] ifAbsent: [
1✔
763
                  | result userId searchResult |
1✔
764
                  ('Import user with username: ' , anUsername printString)
1✔
765
                          recordInfo.
1✔
766
                  result := self glhApi usersSearchByUsername: anUsername.
1✔
767
                  searchResult := NeoJSONReader fromString: result.
1✔
768

1✔
769
                  (searchResult class = Dictionary and: [
1✔
770
                           (searchResult at: #message) includesSubstring: '403 Forbidden' ])
1✔
771
                          ifTrue: [
1✔
772
                                  glhModel
1✔
773
                                          add: (GLHUser new username: anUsername; name: anUsername; yourself )
1✔
774
                                          unless: [ :nu :ou | nu username = ou username ] ]
1✔
775
                          ifFalse: [
1✔
776
                                  searchResult
1✔
777
                                          ifEmpty: [
1✔
778
                                                  GLHUser new
1✔
779
                                                          username: anUsername;
1✔
780
                                                          yourself ]
1✔
781
                                          ifNotEmpty: [
1✔
782
                                                  userId := searchResult first at: #id.
1✔
783
                                                  (self glhModel allWithType: GLHUser)
1✔
784
                                                          detect: [ :user | user id = userId ]
1✔
785
                                                          ifNone: [ self importUser: userId ] ] ] ]
1✔
786
]
1✔
787

788
{ #category : #initialization }
789
GLHModelImporter >> initReader [
1✔
790

1✔
791
        generalReader := NeoJSONReader new.
1✔
792
        self configureReaderForCommit: generalReader.
1✔
793
        self configureReaderForGroup: generalReader.
1✔
794
        self configureReaderForDiffs: generalReader. 
1✔
795
]
1✔
796

797
{ #category : #initialization }
798
GLHModelImporter >> initialize [
1✔
799

1✔
800
        withFiles := false.
1✔
801
        withCommitDiffs := false.
1✔
802
        withInitialCommits := false.
1✔
803
        withInitialMergeRequest := false.
1✔
804
        withCommitsSince := (Date today - 1 week) asDateAndTime.
1✔
805
        self initReader.
1✔
806
        currentImporter := self. 
1✔
807
]
1✔
808

809
{ #category : #importer }
810
GLHModelImporter >> loadAllProjectsFromRepositorySoftware [
×
811
        "heavy import that load all the active project inside the model. Only import the project entities"
×
812
        |projects|
×
813
        
×
814
        projects := self glhApi projects. 
×
815
]
×
816

817
{ #category : #private }
818
GLHModelImporter >> newParseCommitResult: result [
×
819

×
820
        generalReader  on: result readStream.
×
821

×
822
        ^ generalReader nextAs: GLHCommit
×
823
]
×
824

825
{ #category : #private }
826
GLHModelImporter >> newParseDiffResult: result [
1✔
827

1✔
828
        generalReader on: result readStream.
1✔
829
        ^ generalReader nextAs: #ArrayOfDiffs
1✔
830
]
1✔
831

832
{ #category : #parsing }
833
GLHModelImporter >> parseArrayOfProject: arrayOfProjects [
×
834

×
835
        | reader |
×
836
        reader := NeoJSONReader on: arrayOfProjects readStream.
×
837
        reader
×
838
                for: #ArrayOfProjects
×
839
                customDo: [ :customMappting |
×
840
                customMappting listOfElementSchema: GLHProject ].
×
841
        reader for: GLHProject do: [ :mapping |
×
842
                mapping mapInstVar: #name to: #name.
×
843
                mapping mapInstVar: #description to: #description.
×
844
                mapping mapInstVar: #id to: #id.
×
845
                mapping mapInstVar: #archived to: #archived.
×
846
                mapping mapInstVar: #web_url to: #html_url.
×
847
                mapping mapInstVar: #topics to: #topics ].
×
848
        ^ reader nextAs: #ArrayOfProjects
×
849
]
×
850

851
{ #category : #private }
852
GLHModelImporter >> parseBranchesResult: result [
1✔
853

1✔
854
        | reader |
1✔
855
        reader := NeoJSONReader on: result readStream.
1✔
856
        reader mapInstVarsFor: GLHBranch.
1✔
857
        reader
1✔
858
                for: #ArrayOfBranch
1✔
859
                customDo: [ :customMappting | 
1✔
860
                customMappting listOfElementSchema: GLHBranch ].
1✔
861
        ^ reader nextAs: #ArrayOfBranch
1✔
862
]
1✔
863

864
{ #category : #private }
865
GLHModelImporter >> parseCommitResult: result [
×
866

×
867
        | reader |
×
868
        reader := NeoJSONReader on: result readStream.
×
869

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

×
885
        reader for: DateAndTime customDo: [ :mapping |
×
886
                mapping decoder: [ :string | DateAndTime fromString: string ] ].
×
887

×
888
        reader
×
889
                for: #ArrayOfIds
×
890
                customDo: [ :mapping | mapping decoder: [ :string | string ] ].
×
891

×
892

×
893
        ^ reader nextAs: GLHCommit
×
894
]
×
895

896
{ #category : #private }
897
GLHModelImporter >> parseCommitsResult: result [
1✔
898

1✔
899
        | reader |
1✔
900
        reader := NeoJSONReader on: result readStream.
1✔
901

1✔
902
          reader for: GLHCommit do: [ :mapping |
1✔
903
                mapping mapInstVars:
1✔
904
                        #( id short_id title author_name author_email committer_name
1✔
905
                           committer_email message web_url ).
1✔
906
                (mapping mapInstVar: #authored_date) valueSchema: DateAndTime.
1✔
907
                (mapping mapInstVar: #committed_date) valueSchema: DateAndTime.
1✔
908
                (mapping mapInstVar: #created_at) valueSchema: DateAndTime.
1✔
909
                (mapping mapInstVar: #parent_ids) valueSchema: #ArrayOfIds.
1✔
910
                mapping
1✔
911
                        mapProperty: 'stats'
1✔
912
                        getter: [ :el | "Not used" ]
1✔
913
                        setter: [ :commit :value |
1✔
914
                                commit deletions: (value at: #deletions).
1✔
915
                                commit additions: (value at: #additions) ] ].
1✔
916

1✔
917
        reader for: DateAndTime customDo: [ :mapping |
1✔
918
                mapping decoder: [ :string | DateAndTime fromString: string ] ].
1✔
919

1✔
920
        reader
1✔
921
                for: #ArrayOfIds
1✔
922
                customDo: [ :mapping | mapping decoder: [ :string | string ] ].
1✔
923
  
1✔
924
        reader
1✔
925
                for: #ArrayOfCommit
1✔
926
                customDo: [ :customMappting |
1✔
927
                customMappting listOfElementSchema: GLHCommit ].
1✔
928

1✔
929
        ^ reader nextAs: #ArrayOfCommit
1✔
930
]
1✔
931

932
{ #category : #private }
933
GLHModelImporter >> parseDiffResult: result [
1✔
934

1✔
935
        | reader |
1✔
936
        self
1✔
937
                deprecated: 'Use #newParseDiffResult: instead'
1✔
938
                on: '28 June 2024'
1✔
939
                in:
1✔
940
                'Pharo-11.0.0+build.726.sha.aece1b5473acf3830a0e082c1bc3a15d4ff3522b (64 Bit)'.
1✔
941
        reader := NeoJSONReader on: result readStream.
1✔
942
        reader for: GLHDiff do: [ :mapping |
1✔
943
                mapping mapInstVars:
1✔
944
                        #( deleted_file new_file new_path old_path renamed_file ).
1✔
945
                mapping mapInstVar: #diffString to: #diff ].
1✔
946

1✔
947
        reader
1✔
948
                for: #ArrayOfDiffs
1✔
949
                customDo: [ :customMappting |
1✔
950
                customMappting listOfElementSchema: GLHDiff ].
1✔
951
        ^ reader nextAs: #ArrayOfDiffs
1✔
952
]
1✔
953

954
{ #category : #private }
955
GLHModelImporter >> parseFileTreeResult: aResult [
×
956

×
957
        | reader |
×
958
        reader := NeoJSONReader on: aResult readStream.
×
959
        reader mapInstVarsFor: GLHApiFile.
×
960
        reader
×
961
                for: #ArrayOfFile
×
962
                customDo: [ :customMappting | 
×
963
                customMappting listOfElementSchema: GLHApiFile ].
×
964
        ^ reader nextAs: #ArrayOfFile
×
965
]
×
966

967
{ #category : #private }
968
GLHModelImporter >> parseGroupResult: aResult [
1✔
969

1✔
970
        | reader |
1✔
971

1✔
972
        reader := NeoJSONReader on: aResult readStream.
1✔
973
        reader for: GLHGroup do: [ :mapping |
1✔
974
                mapping mapInstVars.
1✔
975
                (mapping mapInstVar: #projects) valueSchema: #ArrayOfProjects ].
1✔
976
        reader mapInstVarsFor: GLHProject.
1✔
977
        reader
1✔
978
                for: #ArrayOfProjects
1✔
979
                customDo: [ :customMappting |
1✔
980
                customMappting listOfElementSchema: GLHProject ].
1✔
981
        ^ reader nextAs: GLHGroup
1✔
982
]
1✔
983

984
{ #category : #private }
985
GLHModelImporter >> parseJobsResult: result ofProject: aProject [
×
986

×
987
        | reader |
×
988
        reader := NeoJSONReader on: result readStream.
×
989
        reader for: GLHJob do: [ :mapping |
×
990
                mapping mapInstVars: #( id allow_failure web_url name ).
×
991

×
992
                mapping
×
993
                        mapProperty: #user
×
994
                        getter: [ :object | #ignore ]
×
995
                        setter: [ :object :value |
×
996
                        object user: (self importUser: (value at: #id)) ].
×
997

×
998
                mapping
×
999
                        mapProperty: #commit
×
1000
                        getter: [ :object | #ignore ]
×
1001
                        setter: [ :object :value |
×
1002
                                value ifNotNil: [
×
1003
                                        object commit:
×
1004
                                                (self importCommit: (value at: #id) ofProject: aProject) ] ].
×
1005

×
1006
                mapping
×
1007
                        mapProperty: #duration
×
1008
                        getter: [ :object | #ignore ]
×
1009
                        setter: [ :object :value |
×
1010
                        value ifNotNil: [ object duration: value seconds ] ] ].
×
1011

×
1012
        reader
×
1013
                for: #ArrayOfGLHJob
×
1014
                customDo: [ :customMappting |
×
1015
                customMappting listOfElementSchema: GLHJob ].
×
1016
        ^ reader nextAs: #ArrayOfGLHJob
×
1017
]
×
1018

1019
{ #category : #private }
1020
GLHModelImporter >> parsePipelinesResult: result [
1✔
1021

1✔
1022
        | reader |
1✔
1023
        reader := NeoJSONReader on: result readStream.
1✔
1024
        reader mapInstVarsFor: GLHPipeline.
1✔
1025
        reader for: GLHPipeline do: [ :mapping |
1✔
1026
                mapping
1✔
1027
                        mapProperty: #created_at
1✔
1028
                        getter: [ :object | #ignore ]
1✔
1029
                        setter: [ :object :value |
1✔
1030
                        object runDate: (DateAndTime fromString: value) ] ].
1✔
1031
        reader
1✔
1032
                for: #ArrayOfPipelines
1✔
1033
                customDo: [ :customMappting |
1✔
1034
                customMappting listOfElementSchema: GLHPipeline ].
1✔
1035
        ^ reader nextAs: #ArrayOfPipelines
1✔
1036
]
1✔
1037

1038
{ #category : #parsing }
1039
GLHModelImporter >> parseProjectResult: aResult [ 
1✔
1040
                | reader |
1✔
1041
        reader := NeoJSONReader on: aResult readStream.
1✔
1042
        reader for: GLHProject do: [ :mapping |
1✔
1043
                mapping mapInstVars. ].
1✔
1044
"        reader mapInstVarsFor: GLHProject."
1✔
1045

1✔
1046
        ^ reader nextAs: GLHProject
1✔
1047
]
1✔
1048

1✔
1049
{ #category : #private }
1✔
1050
GLHModelImporter >> parseSubGroupResult: aResult [
1✔
1051

1✔
1052
        | reader |
1✔
1053
        reader := NeoJSONReader on: aResult readStream.
1✔
1054
        self configureReaderForGroup: reader.
1✔
1055
        ^ reader nextAs: #ArrayOfGroups
1✔
1056
]
1✔
1057

1✔
1058
{ #category : #private }
1✔
1059
GLHModelImporter >> parseUserResult: result [
1✔
1060

1✔
1061
        | reader |
1✔
1062
        reader := NeoJSONReader on: result readStream.
1✔
1063
        reader mapInstVarsFor: GLHUser.
1✔
1064
        ^ reader nextAs: GLHUser
1✔
1065
]
1✔
1066

1✔
1067
{ #category : #'private - api' }
1✔
1068
GLHModelImporter >> pipelinesOf: aProjectID [
1✔
1069

1✔
1070
        | result |
1✔
1071
        ('Search pipelines of: ' , aProjectID printString) recordInfo.
1✔
1072
        result := self glhApi pipelinesOfProject: aProjectID.
1✔
1073
        ^ self parsePipelinesResult: result
1✔
1074
]
1✔
1075

1✔
1076
{ #category : #'as yet unclassified' }
1✔
1077
GLHModelImporter >> selectEntityType: aType overAttribut: aSelector equalTo: value [
1✔
1078

1✔
1079
        ^ (self glhModel allWithType: aType)
1✔
1080
                select: [ :entity | (entity perform: aSelector) = value ]
1✔
1081
]
1✔
1082

1✔
1083
{ #category : #'private - api' }
1✔
1084
GLHModelImporter >> subGroupsOf: aGroupID [
1✔
1085

1✔
1086
        | results parsedResult result page |
1✔
1087
        ('Search subgroup of: ' , aGroupID printString) recordInfo.
1✔
1088
        results := OrderedCollection new.
1✔
1089
        page := 0.
1✔
1090
        
1✔
1091
        parsedResult := { true }.
1✔
1092
        [ parsedResult size > 0 ] whileTrue: [ 
1✔
1093
                result := self glhApi subgroupsOfGroup: aGroupID page: page.
1✔
1094
                parsedResult := self parseSubGroupResult: result.
1✔
1095
                results addAll: parsedResult.
1✔
1096
                                page := page + 1. ].
1✔
1097
        
1✔
1098
        ^ results
1✔
1099
]
1✔
1100

1✔
1101
{ #category : #accessing }
1✔
1102
GLHModelImporter >> withCommitDiffs [
1✔
1103

1✔
1104
        ^ withCommitDiffs
1✔
1105
]
1✔
1106

1✔
1107
{ #category : #accessing }
1✔
1108
GLHModelImporter >> withCommitDiffs: anObject [
1✔
1109

1✔
1110
        withCommitDiffs := anObject
1✔
1111
]
1✔
1112

1✔
1113
{ #category : #accessing }
1✔
1114
GLHModelImporter >> withFiles [
1✔
1115
        ^ withFiles
1✔
1116
]
1✔
1117

1✔
1118
{ #category : #accessing }
1✔
1119
GLHModelImporter >> withFiles: aBoolean [
1✔
1120
        withFiles := aBoolean
1✔
1121
]
1✔
1122

1✔
1123
{ #category : #accessing }
1✔
1124
GLHModelImporter >> withInitialCommits: boolean [
1✔
1125
        withInitialCommits := boolean 
1✔
1126
]
1✔
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