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

moosetechnology / GitProjectHealth / 9693681315

27 Jun 2024 08:58AM UTC coverage: 27.424% (-0.008%) from 27.432%
9693681315

push

github

badetitou
with readstreamdo

0 of 6 new or added lines in 1 file covered. (0.0%)

1 existing line in 1 file now uncovered.

1878 of 6848 relevant lines covered (27.42%)

0.27 hits per line

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

58.72
/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
        #category : #'GitLabHealth-Model-Importer'
15
}
16

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

×
21
        "I return the list of added commits"
×
22

×
23
        | existingCommits newlyFoundCommit |
×
24
        existingCommits := aProjectRepository mooseModel allWithType:
×
25
                                   GLHCommit.
×
26
        newlyFoundCommit := commitsList reject: [ :commitParsed |
×
27
                                    existingCommits anySatisfy: [ :existingCommit |
×
28
                                            existingCommit id = commitParsed id ] ].
×
29
        aProjectRepository mooseModel addAll: newlyFoundCommit.
×
30
        aProjectRepository commits addAll: newlyFoundCommit.
×
31
        ^ newlyFoundCommit
×
32
]
×
33

34
{ #category : #private }
35
GLHModelImporter >> addGroupResultToModel: groupResult [
1✔
36

1✔
37
        self glhModel add: groupResult unless: (self blockEqualityOn: #id).
1✔
38
        self glhModel
1✔
39
                addAll: groupResult projects
1✔
40
                unless: (self blockEqualityOn: #id)
1✔
41
]
1✔
42

43
{ #category : #accessing }
44
GLHModelImporter >> beWithFiles [
×
45
        withFiles := true
×
46
]
×
47

48
{ #category : #accessing }
49
GLHModelImporter >> beWithouFiles [
×
50
        withFiles := false
×
51
]
×
52

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

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

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

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

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

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

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

1✔
82
        ('Complete import of project: ' , aGLHProject id printString)
1✔
83
                recordInfo.
1✔
84

1✔
85
        self importPipelinesOfProject: aGLHProject.
1✔
86

1✔
87
        "aGLHProject creator: (self importUser: aGLHProject creator_id)."
1✔
88

1✔
89
        (self importUser: aGLHProject creator_id) addCreatedProject:
1✔
90
                aGLHProject.
1✔
91

1✔
92
        aGLHProject repository: GLHRepository new.
1✔
93
        self glhModel add: aGLHProject unless: (self blockEqualityOn: #id).
1✔
94
        self glhModel add: aGLHProject repository.
1✔
95
        self importRepository: aGLHProject repository.
1✔
96

1✔
97
        ^ aGLHProject
1✔
98
]
1✔
99

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

1✔
103
        | addedCommit |
1✔
104
        
1✔
105
        addedCommit := aCommit.
1✔
106
        
1✔
107
        addedCommit commitCreator ifNil: [
1✔
108
                        addedCommit := (self importUserByUsername: aCommit author_name)
1✔
109
                               commits
1✔
110
                               add: aCommit
1✔
111
                               unless: [ :existingCommit :newCommit |
1✔
112
                               existingCommit id = newCommit id ].
1✔
113
                 ].
1✔
114
        
1✔
115

1✔
116
        ('Import diff of commit: ' , addedCommit short_id printString) recordInfo.
1✔
117

1✔
118
        self withCommitDiffs ifTrue: [
1✔
119
                |diffs|
1✔
120
                addedCommit diffs ifEmpty: [ 
1✔
121
                        diffs := self importDiffOfCommit: addedCommit.
1✔
122
                        self glhModel addAll: diffs unless: self blockForDiffEquality
1✔
123
                         ] 
1✔
124
                
1✔
125
                 ].
1✔
126

1✔
127
        ^ addedCommit
1✔
128
]
1✔
129

130
{ #category : #private }
131
GLHModelImporter >> configureReaderForCommit: reader [
1✔
132

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

1✔
148
        reader for: DateAndTime customDo: [ :mapping |
1✔
149
                mapping decoder: [ :string | DateAndTime fromString: string ] ].
1✔
150

1✔
151
        reader
1✔
152
                for: #ArrayOfIds
1✔
153
                customDo: [ :mapping | mapping decoder: [ :string | string ] ].
1✔
154
  
1✔
155
        reader
1✔
156
                for: #ArrayOfCommit
1✔
157
                customDo: [ :customMappting |
1✔
158
                customMappting listOfElementSchema: GLHCommit ].
1✔
159

1✔
160
]
1✔
161

162
{ #category : #private }
163
GLHModelImporter >> configureReaderForGroup: reader [
1✔
164

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

179
{ #category : #private }
180
GLHModelImporter >> convertApiFileAsFile: aAPIFile [
×
181

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

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

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

198
{ #category : #'as yet unclassified' }
199
GLHModelImporter >> filterCommitChanges: aCollection [ 
1✔
200
        |changes|
1✔
201
        
1✔
202
        "reject file infos"
1✔
203
        changes := aCollection.
1✔
204
        changes := changes reject: [ :line | line matchesRegex:  '---.*' ].
1✔
205
        changes := changes reject: [ :line | line matchesRegex:  '\+\+\+.*' ].
1✔
206
        changes := changes reject: [ :line | line matchesRegex:  '\\ No newline at end of file' ].
1✔
207
                
1✔
208

1✔
209
^ changes. 
1✔
210
]
1✔
211

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

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

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

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

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

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

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

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

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

×
239
        | page foundGroups newlyFoundGroups |
×
240
        page := 0.
×
241
        foundGroups := OrderedCollection new.
×
242
        newlyFoundGroups := { true }.
×
243
        [ newlyFoundGroups isNotEmpty ] whileTrue: [
×
244
                | results |
×
245
                page := page + 1.
×
246
                results := self glhApi listGroupsWithTopLevelOnly: true page: page.
×
NEW
247
                newlyFoundGroups := results readStreamDo: [ :str |
×
NEW
248
                                            generalReader
×
NEW
249
                                                    on: str;
×
NEW
250
                                                    nextAs: #ArrayOfGroups ].
×
NEW
251
                foundGroups addAll: newlyFoundGroups ].
×
NEW
252
        ^ foundGroups 
×
UNCOV
253
]
×
254

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

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

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

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

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

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

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

1✔
293
                          commit ].
1✔
294

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

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

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

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

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

1✔
325
        self withCommitDiffs ifTrue: [
1✔
326
                parsedResults do: [ :commit |
1✔
327

1✔
328
                        self importDiffOfCommit: commit ] ]
1✔
329
]
1✔
330

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

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

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

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

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

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

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

1✔
381

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

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

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

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

×
424

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

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

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

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

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

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

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

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

×
482
        ^ foundCommit
×
483
]
×
484

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

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

495
{ #category : #api }
496
GLHModelImporter >> importDiffOfCommit: aCommit [
1✔
497

1✔
498
        | result diffsResult |
1✔
499
        aCommit diffs ifNotEmpty: [
1✔
500
                'Diff already importer: ' , aCommit short_id printString recordInfo.
1✔
501
                ^ aCommit diffs ].
1✔
502
        ('Import diff of commit: ' , aCommit short_id printString) recordInfo.
1✔
503
        result := self glhApi
1✔
504
                          commitDiff: aCommit id
1✔
505
                          ofProject: aCommit repository project id
1✔
506
                          unidiff: true.
1✔
507
        diffsResult := self parseDiffResult: result.
1✔
508

1✔
509
        ^ aCommit diffs addAll: diffsResult unless: self blockForDiffEquality.
1✔
510

1✔
511
]
1✔
512

513
{ #category : #'private - api' }
514
GLHModelImporter >> importDirectoryFiles: aDirectoryFile OfBranch: aBranch [
×
515

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

534
{ #category : #'private - api' }
535
GLHModelImporter >> importFilesOfBranch: aBranch [
×
536

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

554
{ #category : #api }
555
GLHModelImporter >> importGroup: aGroupID [
1✔
556

1✔
557
        | result groupResult |
1✔
558
        ('Import group: ' , aGroupID printString) recordInfo.
1✔
559

1✔
560
        result := self glhApi group: aGroupID.
1✔
561
        groupResult := self parseGroupResult: result.
1✔
562

1✔
563
        groupResult projects do: [ :project |
1✔
564
                self completeImportProject: project ].
1✔
565
        self addGroupResultToModel: groupResult.
1✔
566
        (self subGroupsOf: aGroupID) do: [ :subGroup |
1✔
567
                groupResult addSubGroup: (self importGroup: subGroup id) ].
1✔
568
        ^ groupResult
1✔
569
]
1✔
570

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

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

×
582
]
×
583

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

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

×
594
        parentsIds := aGLHCommit parent_ids.
×
595

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

×
603

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

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

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

×
621
        parentsIds := aGLHCommit parent_ids.
×
622

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

×
628

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

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

1✔
637
        (self pipelinesOf: aGLHProject id) do: [ :pipeline |
1✔
638
                self glhModel add: pipeline.
1✔
639
                aGLHProject addPipeline: pipeline ]
1✔
640
]
1✔
641

642
{ #category : #'private - api' }
643
GLHModelImporter >> importRepository: aGLHRepository [
1✔
644

1✔
645
        | resultBranches branches |
1✔
646
        [
1✔
647
        ('import the repository of project ' , aGLHRepository project name)
1✔
648
                recordInfo.
1✔
649

1✔
650
        resultBranches := self glhApi branchesOfRepository:
1✔
651
                                  aGLHRepository project id.
1✔
652
        branches := self parseBranchesResult: resultBranches.
1✔
653

1✔
654
        ('import the branches of project ') recordInfo.
1✔
655

1✔
656
        aGLHRepository branches
1✔
657
                addAll: branches
1✔
658
                unless: self blockOnNameEquality.
1✔
659
        self glhModel addAll: branches unless: self blockOnNameEquality.
1✔
660

1✔
661
        "branches do: [ :branch |
1✔
662
                aGLHRepository addBranch: branch.
1✔
663
                self glhModel add: branch ]."
1✔
664

1✔
665
        self withFiles ifTrue: [
1✔
666
                branches do: [ :branch | self importFilesOfBranch: branch ] ] ]
1✔
667
                on: NeoJSONParseError
1✔
668
                do: [
1✔
669
                self inform: aGLHRepository project name , ' has no repository' ]
1✔
670
]
1✔
671

672
{ #category : #'private - api' }
673
GLHModelImporter >> importUser: aUserID [
1✔
674

1✔
675
        | result userResult |
1✔
676

1✔
677
        (glhModel allWithType: GLHUser) asOrderedCollection detect: [ :user | user id = aUserID ] ifFound: [ :user | ^ user ].
1✔
678
        ('Import user: ' , aUserID printString) recordInfo.
1✔
679
        result := self glhApi user: aUserID.
1✔
680
        userResult := self parseUserResult: result.
1✔
681
        ^ glhModel add: userResult unless: self blockOnIdEquality
1✔
682
]
1✔
683

684
{ #category : #user }
685
GLHModelImporter >> importUserByUsername: anUsername [
1✔
686
        |dicUsername|
1✔
687
        
1✔
688
        dicUsername := ((self glhModel allWithType: GLHUser) collect: [ :user |
1✔
689
                user username -> user.
1✔
690
                 ]) asSet asDictionary.
1✔
691
        
1✔
692
        ^ dicUsername at: anUsername
1✔
693
                  ifPresent: [ :user | user ]
1✔
694
                  ifAbsent: [
1✔
695
                          | result userId searchResult |
1✔
696
                          ('Import user with username: ' , anUsername printString)
1✔
697
                                  recordInfo.
1✔
698
                          result := self glhApi usersSearchByUsername: anUsername.
1✔
699
                          searchResult := NeoJSONReader fromString: result.
1✔
700

1✔
701
                          (searchResult class = Dictionary and: [
1✔
702
                                   (searchResult at: #message) includesSubstring: '403 Forbidden' ])
1✔
703
                                  ifTrue: [ GLHUser new username: anUsername ]
1✔
704
                                  ifFalse: [
1✔
705
                                          searchResult
1✔
706
                                                  ifEmpty: [ GLHUser new username: anUsername; yourself ]
1✔
707
                                                  ifNotEmpty: [
1✔
708
                                                        
1✔
709
                                                          userId := searchResult first at: #id.
1✔
710
                                                          (self glhModel allWithType: GLHUser)
1✔
711
                                                                  detect: [ :user | user id = userId ]
1✔
712
                                                                  ifNone: [ self importUser: userId ] .
1✔
713
                                                                
1✔
714
                                                                ] ] ]
1✔
715
]
1✔
716

717
{ #category : #initialization }
718
GLHModelImporter >> initReader [
1✔
719

1✔
720
        generalReader := NeoJSONReader new.
1✔
721
        self configureReaderForCommit: generalReader.
1✔
722
        self configureReaderForGroup: generalReader
1✔
723
]
1✔
724

725
{ #category : #initialization }
726
GLHModelImporter >> initialize [
1✔
727

1✔
728
        withFiles := false.
1✔
729
        withCommitDiffs := false.
1✔
730
        withInitialCommits := false. 
1✔
731
        withInitialMergeRequest := false. 
1✔
732
        withCommitsSince := (Date today - 1 week) asDateAndTime.
1✔
733
        self initReader
1✔
734
]
1✔
735

736
{ #category : #private }
737
GLHModelImporter >> parseBranchesResult: result [
1✔
738

1✔
739
        | reader |
1✔
740
        reader := NeoJSONReader on: result readStream.
1✔
741
        reader mapInstVarsFor: GLHBranch.
1✔
742
        reader
1✔
743
                for: #ArrayOfBranch
1✔
744
                customDo: [ :customMappting | 
1✔
745
                customMappting listOfElementSchema: GLHBranch ].
1✔
746
        ^ reader nextAs: #ArrayOfBranch
1✔
747
]
1✔
748

749
{ #category : #private }
750
GLHModelImporter >> parseCommitResult: result [
×
751

×
752
        | reader |
×
753
        reader := NeoJSONReader on: result readStream.
×
754

×
755
        reader for: GLHCommit do: [ :mapping |
×
756
                mapping mapInstVars:
×
757
                        #( id short_id title author_name author_email committer_name
×
758
                           committer_email message web_url ).
×
759
                (mapping mapInstVar: #authored_date) valueSchema: DateAndTime.
×
760
                (mapping mapInstVar: #committed_date) valueSchema: DateAndTime.
×
761
                (mapping mapInstVar: #created_at) valueSchema: DateAndTime.
×
762
                (mapping mapInstVar: #parent_ids) valueSchema: #ArrayOfIds.
×
763
                mapping
×
764
                        mapProperty: 'stats'
×
765
                        getter: [ :el | "Not used" ]
×
766
                        setter: [ :commit :value |
×
767
                                commit deletions: (value at: #deletions).
×
768
                                commit additions: (value at: #additions) ] ].
×
769

×
770
        reader for: DateAndTime customDo: [ :mapping |
×
771
                mapping decoder: [ :string | DateAndTime fromString: string ] ].
×
772

×
773
        reader
×
774
                for: #ArrayOfIds
×
775
                customDo: [ :mapping | mapping decoder: [ :string | string ] ].
×
776

×
777

×
778
        ^ reader nextAs: GLHCommit
×
779
]
×
780

781
{ #category : #private }
782
GLHModelImporter >> parseCommitsResult: result [
1✔
783

1✔
784
        | reader |
1✔
785
        reader := NeoJSONReader on: result readStream.
1✔
786

1✔
787
          reader for: GLHCommit do: [ :mapping |
1✔
788
                mapping mapInstVars:
1✔
789
                        #( id short_id title author_name author_email committer_name
1✔
790
                           committer_email message web_url ).
1✔
791
                (mapping mapInstVar: #authored_date) valueSchema: DateAndTime.
1✔
792
                (mapping mapInstVar: #committed_date) valueSchema: DateAndTime.
1✔
793
                (mapping mapInstVar: #created_at) valueSchema: DateAndTime.
1✔
794
                (mapping mapInstVar: #parent_ids) valueSchema: #ArrayOfIds.
1✔
795
                mapping
1✔
796
                        mapProperty: 'stats'
1✔
797
                        getter: [ :el | "Not used" ]
1✔
798
                        setter: [ :commit :value |
1✔
799
                                commit deletions: (value at: #deletions).
1✔
800
                                commit additions: (value at: #additions) ] ].
1✔
801

1✔
802
        reader for: DateAndTime customDo: [ :mapping |
1✔
803
                mapping decoder: [ :string | DateAndTime fromString: string ] ].
1✔
804

1✔
805
        reader
1✔
806
                for: #ArrayOfIds
1✔
807
                customDo: [ :mapping | mapping decoder: [ :string | string ] ].
1✔
808
  
1✔
809
        reader
1✔
810
                for: #ArrayOfCommit
1✔
811
                customDo: [ :customMappting |
1✔
812
                customMappting listOfElementSchema: GLHCommit ].
1✔
813

1✔
814
        ^ reader nextAs: #ArrayOfCommit
1✔
815
]
1✔
816

817
{ #category : #private }
818
GLHModelImporter >> parseDiffResult: result [
1✔
819

1✔
820
        | reader |
1✔
821
        reader := NeoJSONReader on: result readStream.
1✔
822
        reader for: GLHDiff do: [ :mapping |
1✔
823
                mapping mapInstVars:
1✔
824
                        #( deleted_file new_file new_path old_path renamed_file ).
1✔
825
                mapping mapInstVar: #diffString to: #diff ].
1✔
826

1✔
827
        reader
1✔
828
                for: #ArrayOfDiffs
1✔
829
                customDo: [ :customMappting |
1✔
830
                customMappting listOfElementSchema: GLHDiff ].
1✔
831
        ^ reader nextAs: #ArrayOfDiffs
1✔
832
]
1✔
833

834
{ #category : #private }
835
GLHModelImporter >> parseFileTreeResult: aResult [
×
836

×
837
        | reader |
×
838
        reader := NeoJSONReader on: aResult readStream.
×
839
        reader mapInstVarsFor: GLHApiFile.
×
840
        reader
×
841
                for: #ArrayOfFile
×
842
                customDo: [ :customMappting | 
×
843
                customMappting listOfElementSchema: GLHApiFile ].
×
844
        ^ reader nextAs: #ArrayOfFile
×
845
]
×
846

847
{ #category : #private }
848
GLHModelImporter >> parseGroupResult: aResult [
1✔
849

1✔
850
        | reader |
1✔
851

1✔
852
        reader := NeoJSONReader on: aResult readStream.
1✔
853
        reader for: GLHGroup do: [ :mapping |
1✔
854
                mapping mapInstVars.
1✔
855
                (mapping mapInstVar: #projects) valueSchema: #ArrayOfProjects ].
1✔
856
        reader mapInstVarsFor: GLHProject.
1✔
857
        reader
1✔
858
                for: #ArrayOfProjects
1✔
859
                customDo: [ :customMappting |
1✔
860
                customMappting listOfElementSchema: GLHProject ].
1✔
861
        ^ reader nextAs: GLHGroup
1✔
862
]
1✔
863

864
{ #category : #private }
865
GLHModelImporter >> parseJobsResult: result ofProject: aProject [
×
866

×
867
        | reader |
×
868
        reader := NeoJSONReader on: result readStream.
×
869
        reader for: GLHJob do: [ :mapping |
×
870
                mapping mapInstVars: #( id allow_failure web_url name ).
×
871

×
872
                mapping
×
873
                        mapProperty: #user
×
874
                        getter: [ :object | #ignore ]
×
875
                        setter: [ :object :value |
×
876
                        object user: (self importUser: (value at: #id)) ].
×
877

×
878
                mapping
×
879
                        mapProperty: #commit
×
880
                        getter: [ :object | #ignore ]
×
881
                        setter: [ :object :value |
×
882
                                value ifNotNil: [
×
883
                                        object commit:
×
884
                                                (self importCommit: (value at: #id) ofProject: aProject) ] ].
×
885

×
886
                mapping
×
887
                        mapProperty: #duration
×
888
                        getter: [ :object | #ignore ]
×
889
                        setter: [ :object :value |
×
890
                        value ifNotNil: [ object duration: value seconds ] ] ].
×
891

×
892
        reader
×
893
                for: #ArrayOfGLHJob
×
894
                customDo: [ :customMappting |
×
895
                customMappting listOfElementSchema: GLHJob ].
×
896
        ^ reader nextAs: #ArrayOfGLHJob
×
897
]
×
898

899
{ #category : #private }
900
GLHModelImporter >> parsePipelinesResult: result [
1✔
901

1✔
902
        | reader |
1✔
903
        reader := NeoJSONReader on: result readStream.
1✔
904
        reader mapInstVarsFor: GLHPipeline.
1✔
905
        reader for: GLHPipeline do: [ :mapping |
1✔
906
                mapping
1✔
907
                        mapProperty: #created_at
1✔
908
                        getter: [ :object | #ignore ]
1✔
909
                        setter: [ :object :value |
1✔
910
                        object runDate: (DateAndTime fromString: value) ] ].
1✔
911
        reader
1✔
912
                for: #ArrayOfPipelines
1✔
913
                customDo: [ :customMappting |
1✔
914
                customMappting listOfElementSchema: GLHPipeline ].
1✔
915
        ^ reader nextAs: #ArrayOfPipelines
1✔
916
]
1✔
917

918
{ #category : #private }
919
GLHModelImporter >> parseSubGroupResult: aResult [
1✔
920

1✔
921
        | reader |
1✔
922
        reader := NeoJSONReader on: aResult readStream.
1✔
923
        self configureReaderForGroup: reader.
1✔
924
        ^ reader nextAs: #ArrayOfGroups
1✔
925
]
1✔
926

927
{ #category : #private }
928
GLHModelImporter >> parseUserResult: result [
1✔
929

1✔
930
        | reader |
1✔
931
        reader := NeoJSONReader on: result readStream.
1✔
932
        reader mapInstVarsFor: GLHUser.
1✔
933
        ^ reader nextAs: GLHUser
1✔
934
]
1✔
935

936
{ #category : #'private - api' }
937
GLHModelImporter >> pipelinesOf: aProjectID [
1✔
938

1✔
939
        | result |
1✔
940
        ('Search pipelines of: ' , aProjectID printString) recordInfo.
1✔
941
        result := self glhApi pipelinesOfProject: aProjectID.
1✔
942
        ^ self parsePipelinesResult: result
1✔
943
]
1✔
944

945
{ #category : #'as yet unclassified' }
946
GLHModelImporter >> selectEntityType: aType overAttribut: aSelector equalTo: value [
×
947

×
948
        ^ (self glhModel allWithType: aType)
×
949
                select: [ :entity | (entity perform: aSelector) = value ]
×
950
]
×
951

952
{ #category : #'private - api' }
953
GLHModelImporter >> subGroupsOf: aGroupID [
1✔
954

1✔
955
        | results parsedResult result page |
1✔
956
        ('Search subgroup of: ' , aGroupID printString) recordInfo.
1✔
957
        results := OrderedCollection new.
1✔
958
        page := 1.
1✔
959
        result := self glhApi subgroupsOfGroup: aGroupID page: page.
1✔
960
        parsedResult := self parseSubGroupResult: result.
1✔
961
        results addAll: parsedResult.
1✔
962
        [ parsedResult size = 20 ] whileTrue: [ 
1✔
963
                page := page + 1.
1✔
964
                result := self glhApi subgroupsOfGroup: aGroupID page: page.
1✔
965
                parsedResult := self parseSubGroupResult: result.
1✔
966
                results addAll: parsedResult ].
1✔
967
        ^ results
1✔
968
]
1✔
969

970
{ #category : #accessing }
971
GLHModelImporter >> withCommitDiffs [
1✔
972

1✔
973
        ^ withCommitDiffs
1✔
974
]
1✔
975

976
{ #category : #accessing }
977
GLHModelImporter >> withCommitDiffs: anObject [
1✔
978

1✔
979
        withCommitDiffs := anObject
1✔
980
]
1✔
981

982
{ #category : #accessing }
983
GLHModelImporter >> withFiles [
1✔
984
        ^ withFiles
1✔
985
]
1✔
986

987
{ #category : #accessing }
988
GLHModelImporter >> withFiles: aBoolean [
1✔
989
        withFiles := aBoolean
1✔
990
]
1✔
991

992
{ #category : #accessing }
993
GLHModelImporter >> withInitialCommits: boolean [
×
994
        withInitialCommits := boolean 
×
995
]
×
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