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

moosetechnology / GitProjectHealth / 9549969001

17 Jun 2024 02:58PM UTC coverage: 26.896% (-2.6%) from 29.45%
9549969001

push

github

HLAD Nicolas
Merge 10a1182e1

1830 of 6804 relevant lines covered (26.9%)

0.27 hits per line

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

55.39
/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
        ],
13
        #category : #'GitLabHealth-Model-Importer'
14
}
15

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1✔
84
        self importPipelinesOfProject: aGLHProject.
1✔
85

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

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

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

1✔
96
        ^ aGLHProject
1✔
97
]
1✔
98

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

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

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

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

1✔
126
        ^ addedCommit
1✔
127
]
1✔
128

129
{ #category : #private }
130
GLHModelImporter >> configureReaderForCommit: reader [
×
131

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

×
147
        reader for: DateAndTime customDo: [ :mapping |
×
148
                mapping decoder: [ :string | DateAndTime fromString: string ] ].
×
149

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

×
159
]
×
160

161
{ #category : #private }
162
GLHModelImporter >> convertApiFileAsFile: aAPIFile [
×
163

×
164
        aAPIFile type = 'tree' ifTrue: [ 
×
165
                ^ GLHFileDirectory new
×
166
                          name: aAPIFile name;
×
167
                          yourself ].
×
168
        ^ GLHFileBlob new
×
169
                  name: aAPIFile name;
×
170
                  yourself
×
171
]
×
172

173
{ #category : #'as yet unclassified' }
174
GLHModelImporter >> detectEntityType: aType overAttribut: aSelector equalTo: value [
1✔
175

1✔
176
        ^ (self glhModel allWithType: aType) detect: [ :entity |
1✔
177
                  (entity perform: aSelector) = value ] ifNone: [ nil ]. 
1✔
178
]
1✔
179

180
{ #category : #'as yet unclassified' }
181
GLHModelImporter >> filterCommitChanges: aCollection [ 
1✔
182
        |changes|
1✔
183
        
1✔
184
        "reject file infos"
1✔
185
        changes := aCollection.
1✔
186
        changes := changes reject: [ :line | line matchesRegex:  '---.*' ].
1✔
187
        changes := changes reject: [ :line | line matchesRegex:  '\+\+\+.*' ].
1✔
188
        changes := changes reject: [ :line | line matchesRegex:  '\\ No newline at end of file' ].
1✔
189
                
1✔
190

1✔
191
^ changes. 
1✔
192
]
1✔
193

194
{ #category : #accessing }
195
GLHModelImporter >> glhApi [
1✔
196

1✔
197
        ^ glhApi
1✔
198
]
1✔
199

200
{ #category : #accessing }
201
GLHModelImporter >> glhApi: anObject [
1✔
202

1✔
203
        glhApi := anObject
1✔
204
]
1✔
205

206
{ #category : #accessing }
207
GLHModelImporter >> glhModel [
1✔
208

1✔
209
        ^ glhModel
1✔
210
]
1✔
211

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

1✔
215
        glhModel := anObject
1✔
216
]
1✔
217

218
{ #category : #'private - api' }
219
GLHModelImporter >> importCommit: aCommitID ofProject: aGLHProject [
×
220

×
221
        | result parsedResult |
×
222
        (glhModel allWithType: GLHCommit) asOrderedCollection
×
223
                detect: [ :commit | commit id = aCommitID ]
×
224
                ifFound: [ :commit | ^ commit ].
×
225
        result := self glhApi
×
226
                          commit: aCommitID
×
227
                          ofProject: aGLHProject id
×
228
                          withStat: false.
×
229
        parsedResult := self parseCommitResult: result.
×
230
        self
×
231
                addCommits: { parsedResult }
×
232
                toRepository: aGLHProject repository.
×
233
        ^ parsedResult
×
234
]
×
235

236
{ #category : #'as yet unclassified' }
237
GLHModelImporter >> importCommitOfProject: anProject withId: anID [
1✔
238

1✔
239
        | commit result |
1✔
240
        anID ifNil: [ ^ nil ].
1✔
241

1✔
242
        ('looking for commit ' , anID printString , ' in project : '
1✔
243
         , anProject id printString) recordInfo.
1✔
244

1✔
245
        commit := (self
1✔
246
                           detectEntityType: GLHCommit
1✔
247
                           overAttribut: #id
1✔
248
                           equalTo: anID) ifNil: [
1✔
249
                          result := self glhApi commit: anID ofProject: anProject id.
1✔
250
                          commit := (self parseCommitsResult: '[' , result , ']')
1✔
251
                                            first.
1✔
252

1✔
253
                          self glhModel add: commit unless: self blockOnIdEquality.
1✔
254
                          commit repository: anProject repository.
1✔
255

1✔
256
                          commit ].
1✔
257

1✔
258
        self withCommitDiffs ifTrue: [ self importDiffOfCommit: commit ].
1✔
259

1✔
260
        ^ commit
1✔
261
]
1✔
262

263
{ #category : #'private - api' }
264
GLHModelImporter >> importCommits: aGLHProject [
1✔
265
        "limited to the last 20 commits"
1✔
266

1✔
267
        | results parsedResults |
1✔
268
        results := self glhApi
1✔
269
                           commitsOfProject: aGLHProject id
1✔
270
                           forRefName: nil
1✔
271
                           since: nil
1✔
272
                           until: nil
1✔
273
                           path: nil
1✔
274
                           author: nil
1✔
275
                           all: nil
1✔
276
                           with_stats: true
1✔
277
                           firstParent: nil
1✔
278
                           order: nil
1✔
279
                           trailers: nil
1✔
280
                           perPage: nil
1✔
281
                           page: nil.
1✔
282
        parsedResults := self parseCommitsResult: results.
1✔
283
        self glhModel addAll: parsedResults unless: self blockOnIdEquality.
1✔
284

1✔
285
        parsedResults do: [ :commit |
1✔
286
                commit repository: aGLHProject repository ].
1✔
287

1✔
288
        self withCommitDiffs ifTrue: [
1✔
289
                parsedResults do: [ :commit |
1✔
290

1✔
291
                        self importDiffOfCommit: commit ] ]
1✔
292
]
1✔
293

294
{ #category : #'as yet unclassified' }
295
GLHModelImporter >> importCommitsFollowing: aCommit upToDays: aNumberOfDay [
×
296
        "import the 'n' commits of a project starting from an initial 'aCommit' commit. 
×
297
        Lazy import does not import the entities inside the model"
×
298

×
299
        | date |
×
300
        date := aCommit created_at asDateAndTime.
×
301

×
302
        ^ self
×
303
                  importCommitsOfBranch: aCommit branch
×
304
                  forRefName: aCommit branch name
×
305
                  since: date
×
306
                  until: (date + aNumberOfDay day)
×
307
]
×
308

309
{ #category : #commit }
310
GLHModelImporter >> importCommitsOProject: aProject since: fromDate until: toDate [
1✔
311

1✔
312
        | newlyFoundCommit page foundCommit |
1✔
313
        page := 0.
1✔
314
        foundCommit := OrderedCollection new.
1✔
315
        newlyFoundCommit := { true }.
1✔
316
        [ newlyFoundCommit isNotEmpty ] whileTrue: [
1✔
317
                | results |
1✔
318
                page := page + 1.
1✔
319
                ('import commit page ' , page printString) recordInfo.
1✔
320
                results := self glhApi
1✔
321
                                   commitsOfProject: aProject id
1✔
322
                                   forRefName: nil
1✔
323
                                   since:
1✔
324
                                   (fromDate ifNotNil: [ fromDate asDateAndTime asString ])
1✔
325
                                   until:
1✔
326
                                   (toDate ifNotNil: [ toDate asDateAndTime asString ])
1✔
327
                                   path: nil
1✔
328
                                   author: nil
1✔
329
                                   all: true
1✔
330
                                   with_stats: true
1✔
331
                                   firstParent: nil
1✔
332
                                   order: nil
1✔
333
                                   trailers: nil
1✔
334
                                   perPage: 100
1✔
335
                                   page: page.
1✔
336

1✔
337
                newlyFoundCommit := self parseCommitsResult: results.
1✔
338
                "newlyFoundCommit do: [ :c | c repository: aProject repository ]."
1✔
339

1✔
340
                foundCommit addAll: (aProject repository commits
1✔
341
                        addAll: newlyFoundCommit
1✔
342
                        unless: self blockOnIdEquality). ].
1✔
343

1✔
344

1✔
345
        ^ self glhModel addAll: foundCommit unless: self blockOnIdEquality
1✔
346
]
1✔
347

348
{ #category : #api }
349
GLHModelImporter >> importCommitsOf: aGLHProject withStats: aBoolean until: toDate [
×
350

×
351
        | newlyFoundCommit page |
×
352
        
×
353
        self deprecated: [  ] .
×
354
        
×
355
        page := 0.
×
356
        newlyFoundCommit := { true }.
×
357
        [ newlyFoundCommit isNotEmpty ] whileTrue: [
×
358
                | results parsedResults existingCommits |
×
359
                page := page + 1.
×
360
                ('import commit page ' , page printString) recordInfo.
×
361
                results := self glhApi
×
362
                                   commitsOfProject: aGLHProject id
×
363
                                   forRefName: nil
×
364
                                   since: nil
×
365
                                   until: nil
×
366
                                   path: nil
×
367
                                   author: nil
×
368
                                   all: nil
×
369
                                   with_stats: aBoolean
×
370
                                   firstParent: nil
×
371
                                   order: nil
×
372
                                   trailers: nil
×
373
                                   perPage: 100
×
374
                                   page: page.
×
375
                parsedResults := self parseCommitsResult: results.
×
376
                existingCommits := aGLHProject mooseModel allWithType: GLHCommit.
×
377

×
378
                newlyFoundCommit := parsedResults reject: [ :commitParsed |
×
379
                                            (toDate isNil or: [
×
380
                                                     commitParsed committed_date
×
381
                                                     < toDate asDateAndTime ]) or: [
×
382
                                                    existingCommits anySatisfy: [ :existingCommit |
×
383
                                                            existingCommit id = commitParsed id ] ] ].
×
384
                aGLHProject mooseModel addAll: newlyFoundCommit.
×
385
                aGLHProject repository commits addAll: newlyFoundCommit ].
×
386

×
387

×
388
        self withCommitDiffs ifTrue: [
×
389
                aGLHProject repository commits do: [ :commit |
×
390
                        self importDiffOfCommit: commit ] ]
×
391
]
×
392

393
{ #category : #commit }
394
GLHModelImporter >> importCommitsOfBranch: aGLHBranch forRefName: refName since: fromDate [
×
395

×
396
        ^ self
×
397
                  importCommitsOfBranch: aGLHBranch
×
398
                  forRefName: aGLHBranch name
×
399
                  since: fromDate
×
400
                  until: nil
×
401
]
×
402

403
{ #category : #commit }
404
GLHModelImporter >> importCommitsOfBranch: aGLHBranch forRefName: refName since: fromDate until: toDate [
×
405

×
406
        | newlyFoundCommit page foundCommit|
×
407
        page := 0.
×
408
        foundCommit := OrderedCollection new. 
×
409
        newlyFoundCommit := { true }.
×
410
        [ newlyFoundCommit isNotEmpty ] whileTrue: [
×
411
                | results |
×
412
                page := page + 1.
×
413
                ('import commit page ' , page printString) recordInfo.
×
414
                results := self glhApi
×
415
                                   commitsOfProject: aGLHBranch repository project id
×
416
                                   forRefName: aGLHBranch name
×
417
                                   since:
×
418
                                   (fromDate ifNotNil: [ fromDate asDateAndTime asString ])
×
419
                                   until:
×
420
                                   (toDate ifNotNil: [ toDate asDateAndTime asString ])
×
421
                                   path: nil
×
422
                                   author: nil
×
423
                                   all: nil
×
424
                                   with_stats: nil
×
425
                                   firstParent: nil
×
426
                                   order: nil
×
427
                                   trailers: nil
×
428
                                   perPage: 100
×
429
                                   page: page.
×
430

×
431
                newlyFoundCommit := self parseCommitsResult: results.
×
432
        aGLHBranch commits
×
433
                        addAll: newlyFoundCommit
×
434
                        unless: self blockOnIdEquality.
×
435
        foundCommit addAll: newlyFoundCommit.  
×
436
                        ].
×
437

×
438
        self glhModel
×
439
                addAll: aGLHBranch commits
×
440
                unless: self blockOnIdEquality.
×
441

×
442
        "self withCommitDiffs ifTrue: [
×
443
                aGLHBranch commits: [ :commit | self importDiffOfCommit: commit ] ]."
×
444

×
445
        ^ foundCommit
×
446
]
×
447

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

×
451
        ^ self
×
452
                  importCommitsOfBranch: aGLHBranch
×
453
                  forRefName: aGLHBranch name
×
454
                  since: nil
×
455
                  until: toDate
×
456
]
×
457

458
{ #category : #api }
459
GLHModelImporter >> importDiffOfCommit: aCommit [
1✔
460

1✔
461
        | result diffsResult |
1✔
462
        aCommit diffs ifNotEmpty: [
1✔
463
                'Diff already importer: ' , aCommit short_id printString recordInfo.
1✔
464
                ^ aCommit diffs ].
1✔
465
        ('Import diff of commit: ' , aCommit short_id printString) recordInfo.
1✔
466
        result := self glhApi
1✔
467
                          commitDiff: aCommit id
1✔
468
                          ofProject: aCommit repository project id
1✔
469
                          unidiff: true.
1✔
470
        diffsResult := self parseDiffResult: result.
1✔
471

1✔
472
        ^ aCommit diffs addAll: diffsResult unless: self blockForDiffEquality.
1✔
473

1✔
474
]
1✔
475

476
{ #category : #'private - api' }
477
GLHModelImporter >> importDirectoryFiles: aDirectoryFile OfBranch: aBranch [
×
478

×
479
        | result files apiFiles |
×
480
        result := self glhApi
×
481
                          treeOfRepository: aBranch repository project id
×
482
                          ofBranch: aBranch name
×
483
                          andPath: aDirectoryFile path , '/'.
×
484
        apiFiles := self parseFileTreeResult: result.
×
485
        files := apiFiles collect: [ :apiFile |
×
486
                         self convertApiFileAsFile: apiFile ].
×
487
        files do: [ :file |
×
488
                
×
489
                self glhModel add: file.
×
490
                aDirectoryFile addFile: file ].
×
491
        files
×
492
                select: [ :file | file isKindOf: GLHFileDirectory ]
×
493
                thenCollect: [ :file |
×
494
                self importDirectoryFiles: file OfBranch: aBranch ]
×
495
]
×
496

497
{ #category : #'private - api' }
498
GLHModelImporter >> importFilesOfBranch: aBranch [
×
499

×
500
        | result files apiFiles |
×
501
        result := self glhApi
×
502
                          treeOfRepository: aBranch repository project id
×
503
                          ofBranch: aBranch name
×
504
                          andPath: nil.
×
505
        apiFiles := self parseFileTreeResult: result.
×
506
        files := apiFiles collect: [ :apiFile | 
×
507
                         self convertApiFileAsFile: apiFile ].
×
508
        files do: [ :file | 
×
509
                self glhModel add: file.
×
510
                aBranch addFile: file ].
×
511
        files
×
512
                select: [ :file | file isKindOf: GLHFileDirectory ]
×
513
                thenCollect: [ :file | 
×
514
                self importDirectoryFiles: file OfBranch: aBranch ]
×
515
]
×
516

517
{ #category : #api }
518
GLHModelImporter >> importGroup: aGroupID [
1✔
519

1✔
520
        | result groupResult |
1✔
521
        ('Import group: ' , aGroupID printString) recordInfo.
1✔
522

1✔
523
        result := self glhApi group: aGroupID.
1✔
524
        groupResult := self parseGroupResult: result.
1✔
525

1✔
526
        groupResult projects do: [ :project |
1✔
527
                self completeImportProject: project ].
1✔
528
        self addGroupResultToModel: groupResult.
1✔
529
        (self subGroupsOf: aGroupID) do: [ :subGroup |
1✔
530
                groupResult addSubGroup: (self importGroup: subGroup id) ].
1✔
531
        ^ groupResult
1✔
532
]
1✔
533

534
{ #category : #api }
535
GLHModelImporter >> importJobsOf: aPipeline [
×
536

×
537
        | result jobs |
×
538
        result := self glhApi
×
539
                          jobsOfProject: aPipeline project id
×
540
                          ofPipelines: aPipeline id.
×
541
        jobs := self parseJobsResult: result ofProject: aPipeline project.
×
542
        jobs do: [ :job | aPipeline addJob: job ].
×
543
        self glhModel addAll: jobs
×
544

×
545
]
×
546

547
{ #category : #commit }
548
GLHModelImporter >> importParentCommitsOfCommit: aGLHCommit forOnly: number [
×
549

×
550
        | parentsIds commits |
×
551
        commits := OrderedCollection new.
×
552
        number = 0 ifTrue: [
×
553
                ^ commits
×
554
                          add: aGLHCommit;
×
555
                          yourself ].
×
556

×
557
        parentsIds := aGLHCommit parent_ids.
×
558

×
559
        commits addAll: (parentsIds collect: [ :id |
×
560
                         self
×
561
                                 importCommitOfProject: aGLHCommit repository project
×
562
                                 withId: id.
×
563
                         (self selectEntityType: GLHCommit overAttribut: #id equalTo: id)
×
564
                                 first ]).
×
565

×
566

×
567
        ^ commits , (commits collect: [ :parentCommit |
×
568
                   self
×
569
                           importParentCommitsOfCommit: parentCommit
×
570
                           forOnly: number - 1 ]) flatten
×
571
]
×
572

573
{ #category : #commit }
574
GLHModelImporter >> importParentCommitsOfCommit: aGLHCommit since: aDate [
×
575

×
576
        | parentsIds commits |
×
577
        commits := OrderedCollection new.
×
578
        aGLHCommit created_at asDateAndTime < aDate asDateAndTime ifTrue: [
×
579
                 
×
580
                ^ commits
×
581
                          add: aGLHCommit;
×
582
                          yourself ].
×
583

×
584
        parentsIds := aGLHCommit parent_ids.
×
585

×
586
        commits addAll: (parentsIds collect: [ :id |
×
587
                         self
×
588
                                 importCommitOfProject: aGLHCommit repository project
×
589
                                 withId: id ]).
×
590

×
591

×
592
        ^ (commits collect: [ :parentCommit |
×
593
                   self importParentCommitsOfCommit: parentCommit since: aDate ])
×
594
                  flatten
×
595
]
×
596

597
{ #category : #'private - api' }
598
GLHModelImporter >> importPipelinesOfProject: aGLHProject [
1✔
599

1✔
600
        (self pipelinesOf: aGLHProject id) do: [ :pipeline |
1✔
601
                self glhModel add: pipeline.
1✔
602
                aGLHProject addPipeline: pipeline ]
1✔
603
]
1✔
604

605
{ #category : #'private - api' }
606
GLHModelImporter >> importRepository: aGLHRepository [
1✔
607

1✔
608
        | resultBranches branches |
1✔
609
        [
1✔
610
        ('import the repository of project ' , aGLHRepository project name)
1✔
611
                recordInfo.
1✔
612

1✔
613
        resultBranches := self glhApi branchesOfRepository:
1✔
614
                                  aGLHRepository project id.
1✔
615
        branches := self parseBranchesResult: resultBranches.
1✔
616

1✔
617
        ('import the branches of project ') recordInfo.
1✔
618

1✔
619
        aGLHRepository branches
1✔
620
                addAll: branches
1✔
621
                unless: self blockOnNameEquality.
1✔
622
        self glhModel addAll: branches unless: self blockOnNameEquality.
1✔
623

1✔
624
        "branches do: [ :branch |
1✔
625
                aGLHRepository addBranch: branch.
1✔
626
                self glhModel add: branch ]."
1✔
627

1✔
628
        self withFiles ifTrue: [
1✔
629
                branches do: [ :branch | self importFilesOfBranch: branch ] ] ]
1✔
630
                on: NeoJSONParseError
1✔
631
                do: [
1✔
632
                self inform: aGLHRepository project name , ' has no repository' ]
1✔
633
]
1✔
634

635
{ #category : #'private - api' }
636
GLHModelImporter >> importUser: aUserID [
1✔
637

1✔
638
        | result userResult |
1✔
639

1✔
640
        (glhModel allWithType: GLHUser) asOrderedCollection detect: [ :user | user id = aUserID ] ifFound: [ :user | ^ user ].
1✔
641
        ('Import user: ' , aUserID printString) recordInfo.
1✔
642
        result := self glhApi user: aUserID.
1✔
643
        userResult := self parseUserResult: result.
1✔
644
        ^ glhModel add: userResult unless: self blockOnIdEquality
1✔
645
]
1✔
646

647
{ #category : #user }
648
GLHModelImporter >> importUserByUsername: anUsername [
1✔
649
        |dicUsername|
1✔
650
        
1✔
651
        dicUsername := ((self glhModel allWithType: GLHUser) collect: [ :user |
1✔
652
                user username -> user.
1✔
653
                 ]) asSet asDictionary.
1✔
654
        
1✔
655
        ^ dicUsername at: anUsername
1✔
656
                  ifPresent: [ :user | user ]
1✔
657
                  ifAbsent: [
1✔
658
                          | result userId searchResult |
1✔
659
                          ('Import user with username: ' , anUsername printString)
1✔
660
                                  recordInfo.
1✔
661
                          result := self glhApi usersSearchByUsername: anUsername.
1✔
662
                          searchResult := NeoJSONReader fromString: result.
1✔
663

1✔
664
                          (searchResult class = Dictionary and: [
1✔
665
                                   (searchResult at: #message) includesSubstring: '403 Forbidden' ])
1✔
666
                                  ifTrue: [ GLHUser new username: anUsername ]
1✔
667
                                  ifFalse: [
1✔
668
                                          searchResult
1✔
669
                                                  ifEmpty: [ GLHUser new username: anUsername; yourself ]
1✔
670
                                                  ifNotEmpty: [
1✔
671
                                                        
1✔
672
                                                          userId := searchResult first at: #id.
1✔
673
                                                          (self glhModel allWithType: GLHUser)
1✔
674
                                                                  detect: [ :user | user id = userId ]
1✔
675
                                                                  ifNone: [ self importUser: userId ] .
1✔
676
                                                                
1✔
677
                                                                ] ] ]
1✔
678
]
1✔
679

680
{ #category : #initialization }
681
GLHModelImporter >> initialize [
1✔
682

1✔
683
        withFiles := false.
1✔
684
        withCommitDiffs := false.
1✔
685
        withInitialCommits := false. 
1✔
686
        withInitialMergeRequest := false. 
1✔
687
        withCommitsSince := (Date today - 1 week) asDateAndTime
1✔
688
]
1✔
689

690
{ #category : #private }
691
GLHModelImporter >> parseBranchesResult: result [
1✔
692

1✔
693
        | reader |
1✔
694
        reader := NeoJSONReader on: result readStream.
1✔
695
        reader mapInstVarsFor: GLHBranch.
1✔
696
        reader
1✔
697
                for: #ArrayOfBranch
1✔
698
                customDo: [ :customMappting | 
1✔
699
                customMappting listOfElementSchema: GLHBranch ].
1✔
700
        ^ reader nextAs: #ArrayOfBranch
1✔
701
]
1✔
702

703
{ #category : #private }
704
GLHModelImporter >> parseCommitResult: result [
×
705

×
706
        | reader |
×
707
        reader := NeoJSONReader on: result readStream.
×
708

×
709
        reader for: GLHCommit do: [ :mapping |
×
710
                mapping mapInstVars:
×
711
                        #( id short_id title author_name author_email committer_name
×
712
                           committer_email message web_url ).
×
713
                (mapping mapInstVar: #authored_date) valueSchema: DateAndTime.
×
714
                (mapping mapInstVar: #committed_date) valueSchema: DateAndTime.
×
715
                (mapping mapInstVar: #created_at) valueSchema: DateAndTime.
×
716
                (mapping mapInstVar: #parent_ids) valueSchema: #ArrayOfIds.
×
717
                mapping
×
718
                        mapProperty: 'stats'
×
719
                        getter: [ :el | "Not used" ]
×
720
                        setter: [ :commit :value |
×
721
                                commit deletions: (value at: #deletions).
×
722
                                commit additions: (value at: #additions) ] ].
×
723

×
724
        reader for: DateAndTime customDo: [ :mapping |
×
725
                mapping decoder: [ :string | DateAndTime fromString: string ] ].
×
726

×
727
        reader
×
728
                for: #ArrayOfIds
×
729
                customDo: [ :mapping | mapping decoder: [ :string | string ] ].
×
730

×
731

×
732
        ^ reader nextAs: GLHCommit
×
733
]
×
734

735
{ #category : #private }
736
GLHModelImporter >> parseCommitsResult: result [
1✔
737

1✔
738
        | reader |
1✔
739
        reader := NeoJSONReader on: result readStream.
1✔
740

1✔
741
          reader for: GLHCommit do: [ :mapping |
1✔
742
                mapping mapInstVars:
1✔
743
                        #( id short_id title author_name author_email committer_name
1✔
744
                           committer_email message web_url ).
1✔
745
                (mapping mapInstVar: #authored_date) valueSchema: DateAndTime.
1✔
746
                (mapping mapInstVar: #committed_date) valueSchema: DateAndTime.
1✔
747
                (mapping mapInstVar: #created_at) valueSchema: DateAndTime.
1✔
748
                (mapping mapInstVar: #parent_ids) valueSchema: #ArrayOfIds.
1✔
749
                mapping
1✔
750
                        mapProperty: 'stats'
1✔
751
                        getter: [ :el | "Not used" ]
1✔
752
                        setter: [ :commit :value |
1✔
753
                                commit deletions: (value at: #deletions).
1✔
754
                                commit additions: (value at: #additions) ] ].
1✔
755

1✔
756
        reader for: DateAndTime customDo: [ :mapping |
1✔
757
                mapping decoder: [ :string | DateAndTime fromString: string ] ].
1✔
758

1✔
759
        reader
1✔
760
                for: #ArrayOfIds
1✔
761
                customDo: [ :mapping | mapping decoder: [ :string | string ] ].
1✔
762
  
1✔
763
        reader
1✔
764
                for: #ArrayOfCommit
1✔
765
                customDo: [ :customMappting |
1✔
766
                customMappting listOfElementSchema: GLHCommit ].
1✔
767

1✔
768
        ^ reader nextAs: #ArrayOfCommit
1✔
769
]
1✔
770

771
{ #category : #private }
772
GLHModelImporter >> parseDiffResult: result [
1✔
773

1✔
774
        | reader |
1✔
775
        reader := NeoJSONReader on: result readStream.
1✔
776
        reader for: GLHDiff do: [ :mapping |
1✔
777
                mapping mapInstVars:
1✔
778
                        #( deleted_file new_file new_path old_path renamed_file ).
1✔
779
                mapping mapInstVar: #diffString to: #diff ].
1✔
780

1✔
781
        reader
1✔
782
                for: #ArrayOfDiffs
1✔
783
                customDo: [ :customMappting |
1✔
784
                customMappting listOfElementSchema: GLHDiff ].
1✔
785
        ^ reader nextAs: #ArrayOfDiffs
1✔
786
]
1✔
787

788
{ #category : #private }
789
GLHModelImporter >> parseFileTreeResult: aResult [
×
790

×
791
        | reader |
×
792
        reader := NeoJSONReader on: aResult readStream.
×
793
        reader mapInstVarsFor: GLHApiFile.
×
794
        reader
×
795
                for: #ArrayOfFile
×
796
                customDo: [ :customMappting | 
×
797
                customMappting listOfElementSchema: GLHApiFile ].
×
798
        ^ reader nextAs: #ArrayOfFile
×
799
]
×
800

801
{ #category : #private }
802
GLHModelImporter >> parseGroupResult: aResult [
1✔
803

1✔
804
        | reader |
1✔
805

1✔
806
        reader := NeoJSONReader on: aResult readStream.
1✔
807
        reader for: GLHGroup do: [ :mapping |
1✔
808
                mapping mapInstVars.
1✔
809
                (mapping mapInstVar: #projects) valueSchema: #ArrayOfProjects ].
1✔
810
        reader mapInstVarsFor: GLHProject.
1✔
811
        reader
1✔
812
                for: #ArrayOfProjects
1✔
813
                customDo: [ :customMappting |
1✔
814
                customMappting listOfElementSchema: GLHProject ].
1✔
815
        ^ reader nextAs: GLHGroup
1✔
816
]
1✔
817

818
{ #category : #private }
819
GLHModelImporter >> parseJobsResult: result ofProject: aProject [
×
820

×
821
        | reader |
×
822
        reader := NeoJSONReader on: result readStream.
×
823
        reader for: GLHJob do: [ :mapping |
×
824
                mapping mapInstVars: #( id allow_failure web_url name ).
×
825

×
826
                mapping
×
827
                        mapProperty: #user
×
828
                        getter: [ :object | #ignore ]
×
829
                        setter: [ :object :value |
×
830
                        object user: (self importUser: (value at: #id)) ].
×
831

×
832
                mapping
×
833
                        mapProperty: #commit
×
834
                        getter: [ :object | #ignore ]
×
835
                        setter: [ :object :value |
×
836
                                value ifNotNil: [
×
837
                                        object commit:
×
838
                                                (self importCommit: (value at: #id) ofProject: aProject) ] ].
×
839

×
840
                mapping
×
841
                        mapProperty: #duration
×
842
                        getter: [ :object | #ignore ]
×
843
                        setter: [ :object :value |
×
844
                        value ifNotNil: [ object duration: value seconds ] ] ].
×
845

×
846
        reader
×
847
                for: #ArrayOfGLHJob
×
848
                customDo: [ :customMappting |
×
849
                customMappting listOfElementSchema: GLHJob ].
×
850
        ^ reader nextAs: #ArrayOfGLHJob
×
851
]
×
852

853
{ #category : #private }
854
GLHModelImporter >> parsePipelinesResult: result [
1✔
855

1✔
856
        | reader |
1✔
857
        reader := NeoJSONReader on: result readStream.
1✔
858
        reader mapInstVarsFor: GLHPipeline.
1✔
859
        reader for: GLHPipeline do: [ :mapping |
1✔
860
                mapping
1✔
861
                        mapProperty: #created_at
1✔
862
                        getter: [ :object | #ignore ]
1✔
863
                        setter: [ :object :value |
1✔
864
                        object runDate: (DateAndTime fromString: value) ] ].
1✔
865
        reader
1✔
866
                for: #ArrayOfPipelines
1✔
867
                customDo: [ :customMappting |
1✔
868
                customMappting listOfElementSchema: GLHPipeline ].
1✔
869
        ^ reader nextAs: #ArrayOfPipelines
1✔
870
]
1✔
871

872
{ #category : #private }
873
GLHModelImporter >> parseSubGroupResult: aResult [
1✔
874

1✔
875
        | reader |
1✔
876
        reader := NeoJSONReader on: aResult readStream.
1✔
877
        reader mapInstVarsFor: GLHGroup.
1✔
878
        reader
1✔
879
                for: #ArrayOfGroups
1✔
880
                customDo: [ :customMappting | 
1✔
881
                customMappting listOfElementSchema: GLHGroup ].
1✔
882
        ^ reader nextAs: #ArrayOfGroups
1✔
883
]
1✔
884

885
{ #category : #private }
886
GLHModelImporter >> parseUserResult: result [
1✔
887

1✔
888
        | reader |
1✔
889
        reader := NeoJSONReader on: result readStream.
1✔
890
        reader mapInstVarsFor: GLHUser.
1✔
891
        ^ reader nextAs: GLHUser
1✔
892
]
1✔
893

894
{ #category : #'private - api' }
895
GLHModelImporter >> pipelinesOf: aProjectID [
1✔
896

1✔
897
        | result |
1✔
898
        ('Search pipelines of: ' , aProjectID printString) recordInfo.
1✔
899
        result := self glhApi pipelinesOfProject: aProjectID.
1✔
900
        ^ self parsePipelinesResult: result
1✔
901
]
1✔
902

903
{ #category : #'as yet unclassified' }
904
GLHModelImporter >> selectEntityType: aType overAttribut: aSelector equalTo: value [
×
905

×
906
        ^ (self glhModel allWithType: aType)
×
907
                select: [ :entity | (entity perform: aSelector) = value ]
×
908
]
×
909

910
{ #category : #'private - api' }
911
GLHModelImporter >> subGroupsOf: aGroupID [
1✔
912

1✔
913
        | results parsedResult result page |
1✔
914
        ('Search subgroup of: ' , aGroupID printString) recordInfo.
1✔
915
        results := OrderedCollection new.
1✔
916
        page := 1.
1✔
917
        result := self glhApi subgroupsOfGroup: aGroupID page: page.
1✔
918
        parsedResult := self parseSubGroupResult: result.
1✔
919
        results addAll: parsedResult.
1✔
920
        [ parsedResult size = 20 ] whileTrue: [ 
1✔
921
                page := page + 1.
1✔
922
                result := self glhApi subgroupsOfGroup: aGroupID page: page.
1✔
923
                parsedResult := self parseSubGroupResult: result.
1✔
924
                results addAll: parsedResult ].
1✔
925
        ^ results
1✔
926
]
1✔
927

928
{ #category : #accessing }
929
GLHModelImporter >> withCommitDiffs [
1✔
930

1✔
931
        ^ withCommitDiffs
1✔
932
]
1✔
933

934
{ #category : #accessing }
935
GLHModelImporter >> withCommitDiffs: anObject [
1✔
936

1✔
937
        withCommitDiffs := anObject
1✔
938
]
1✔
939

940
{ #category : #accessing }
941
GLHModelImporter >> withFiles [
1✔
942
        ^ withFiles
1✔
943
]
1✔
944

945
{ #category : #accessing }
946
GLHModelImporter >> withFiles: aBoolean [
1✔
947
        withFiles := aBoolean
1✔
948
]
1✔
949

950
{ #category : #accessing }
951
GLHModelImporter >> withInitialCommits: boolean [
×
952
        withInitialCommits := boolean 
×
953
]
×
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