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

moosetechnology / GitProjectHealth / 9681022804

26 Jun 2024 01:56PM UTC coverage: 29.585% (+2.7%) from 26.896%
9681022804

Pull #7

github

web-flow
Merge 1d2c206b6 into dfd76b711
Pull Request #7: Optimize code and writting tests

513 of 1111 new or added lines in 11 files covered. (46.17%)

16 existing lines in 3 files now uncovered.

2176 of 7355 relevant lines covered (29.59%)

0.3 hits per line

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

50.06
/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

1✔
103
        aCommit commitCreator ifNil: [
1✔
104
                        ('Import creator of commit: ' , aCommit short_id printString)
1✔
105
                recordInfo.
1✔
106
                aCommit commitCreator:
1✔
107
                        (self importUserByUsername: aCommit author_name)
1✔
108

1✔
109
                "        addedCommit := (self importUserByUsername: addedCommit author_name)
1✔
110
                               commits
1✔
111
                               add: addedCommit
1✔
112
                               unless: [ :existingCommit :newCommit |
1✔
113
                               existingCommit id = newCommit id ]." ].
1✔
114

1✔
115
        self withCommitDiffs ifTrue: [
1✔
116
                | diffs |
1✔
117
                ('Import diff of commit: ' , aCommit short_id printString)
1✔
118
                        recordInfo.
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 [
×
128

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

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

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

×
156
]
×
157

158
{ #category : #private }
159
GLHModelImporter >> convertApiFileAsFile: aAPIFile [
×
160

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

170
{ #category : #'as yet unclassified' }
171
GLHModelImporter >> detectEntityType: aType overAttribut: aSelector equalTo: value [
1✔
172

1✔
173
        ^ (self glhModel allWithType: aType) detect: [ :entity |
1✔
174
                  (entity perform: aSelector) = value ] ifNone: [ nil ]. 
1✔
175
]
1✔
176

177
{ #category : #'as yet unclassified' }
178
GLHModelImporter >> filterCommitChanges: aCollection [
1✔
179

1✔
180
        ^ aCollection reject: [ :line |
1✔
181
                  | trimmedLine |
1✔
182
                  trimmedLine := line trimLeft.
1✔
183
                  (trimmedLine beginsWith: '---') or: [
1✔
184
                          (trimmedLine beginsWith: '+++') or: [
1✔
185
                                  trimmedLine beginsWith: '\ No newline at end of file' ] ] ]
1✔
186
]
1✔
187

188
{ #category : #accessing }
189
GLHModelImporter >> glhApi [
1✔
190

1✔
191
        ^ glhApi
1✔
192
]
1✔
193

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

1✔
197
        glhApi := anObject
1✔
198
]
1✔
199

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

1✔
203
        ^ glhModel
1✔
204
]
1✔
205

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

1✔
209
        glhModel := anObject
1✔
210
]
1✔
211

212
{ #category : #'private - api' }
213
GLHModelImporter >> importCommit: aCommitID ofProject: aGLHProject [
×
214

×
215
        | result parsedResult |
×
216
        (glhModel allWithType: GLHCommit) asOrderedCollection
×
217
                detect: [ :commit | commit id = aCommitID ]
×
218
                ifFound: [ :commit | ^ commit ].
×
219
        result := self glhApi
×
220
                          commit: aCommitID
×
221
                          ofProject: aGLHProject id
×
222
                          withStat: false.
×
223
        parsedResult := self parseCommitResult: result.
×
224
        self
×
225
                addCommits: { parsedResult }
×
226
                toRepository: aGLHProject repository.
×
227
        ^ parsedResult
×
228
]
×
229

230
{ #category : #'as yet unclassified' }
231
GLHModelImporter >> importCommitOfProject: anProject withId: anID [
1✔
232

1✔
233
        | commit result |
1✔
234
        anID ifNil: [ ^ nil ].
1✔
235

1✔
236
        ('looking for commit ' , anID printString , ' in project : '
1✔
237
         , anProject id printString) recordInfo.
1✔
238

1✔
239
        commit := (self
1✔
240
                           detectEntityType: GLHCommit
1✔
241
                           overAttribut: #id
1✔
242
                           equalTo: anID) ifNil: [
1✔
243
                          result := self glhApi commit: anID ofProject: anProject id.
1✔
244
                          commit := (self parseCommitsResult: '[' , result , ']')
1✔
245
                                            first.
1✔
246

1✔
247
                          self glhModel add: commit unless: self blockOnIdEquality.
1✔
248
                          commit repository: anProject repository.
1✔
249

1✔
250
                          commit ].
1✔
251

1✔
252
        self withCommitDiffs ifTrue: [ self importDiffOfCommit: commit ].
1✔
253

1✔
254
        ^ commit
1✔
255
]
1✔
256

257
{ #category : #'private - api' }
258
GLHModelImporter >> importCommits: aGLHProject [
1✔
259
        "limited to the last 20 commits"
1✔
260

1✔
261
        | results parsedResults |
1✔
262
        results := self glhApi
1✔
263
                           commitsOfProject: aGLHProject id
1✔
264
                           forRefName: nil
1✔
265
                           since: nil
1✔
266
                           until: nil
1✔
267
                           path: nil
1✔
268
                           author: nil
1✔
269
                           all: nil
1✔
270
                           with_stats: true
1✔
271
                           firstParent: nil
1✔
272
                           order: nil
1✔
273
                           trailers: nil
1✔
274
                           perPage: nil
1✔
275
                           page: nil.
1✔
276
        parsedResults := self parseCommitsResult: results.
1✔
277
        self glhModel addAll: parsedResults unless: self blockOnIdEquality.
1✔
278

1✔
279
        parsedResults do: [ :commit |
1✔
280
                commit repository: aGLHProject repository ].
1✔
281

1✔
282
        self withCommitDiffs ifTrue: [
1✔
283
                parsedResults do: [ :commit |
1✔
284

1✔
285
                        self importDiffOfCommit: commit ] ]
1✔
286
]
1✔
287

288
{ #category : #'as yet unclassified' }
289
GLHModelImporter >> importCommitsFollowing: aCommit upToDays: aNumberOfDay [
×
290
        "import the 'n' commits of a project starting from an initial 'aCommit' commit. 
×
291
        Lazy import does not import the entities inside the model"
×
292

×
293
        | date |
×
294
        date := aCommit created_at asDateAndTime.
×
295

×
296
        ^ self
×
297
                  importCommitsOfBranch: aCommit branch
×
298
                  forRefName: aCommit branch name
×
299
                  since: date
×
300
                  until: (date + aNumberOfDay day)
×
301
]
×
302

303
{ #category : #commit }
304
GLHModelImporter >> importCommitsOProject: aProject since: fromDate until: toDate [
1✔
305

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

1✔
331
                newlyFoundCommit := self parseCommitsResult: results.
1✔
332
                "newlyFoundCommit do: [ :c | c repository: aProject repository ]."
1✔
333

1✔
334
                foundCommit addAll: (aProject repository commits
1✔
335
                        addAll: newlyFoundCommit
1✔
336
                        unless: self blockOnIdEquality). ].
1✔
337

1✔
338

1✔
339
        ^ self glhModel addAll: foundCommit unless: self blockOnIdEquality
1✔
340
]
1✔
341

342
{ #category : #api }
343
GLHModelImporter >> importCommitsOf: aGLHProject withStats: aBoolean until: toDate [
×
344

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

×
372
                newlyFoundCommit := parsedResults reject: [ :commitParsed |
×
373
                                            (toDate isNil or: [
×
374
                                                     commitParsed committed_date
×
375
                                                     < toDate asDateAndTime ]) or: [
×
376
                                                    existingCommits anySatisfy: [ :existingCommit |
×
377
                                                            existingCommit id = commitParsed id ] ] ].
×
378
                aGLHProject mooseModel addAll: newlyFoundCommit.
×
379
                aGLHProject repository commits addAll: newlyFoundCommit ].
×
380

×
381

×
382
        self withCommitDiffs ifTrue: [
×
383
                aGLHProject repository commits do: [ :commit |
×
384
                        self importDiffOfCommit: commit ] ]
×
385
]
×
386

387
{ #category : #commit }
388
GLHModelImporter >> importCommitsOfBranch: aGLHBranch forRefName: refName since: fromDate [
×
389

×
390
        ^ self
×
391
                  importCommitsOfBranch: aGLHBranch
×
392
                  forRefName: aGLHBranch name
×
393
                  since: fromDate
×
394
                  until: nil
×
395
]
×
396

397
{ #category : #commit }
398
GLHModelImporter >> importCommitsOfBranch: aGLHBranch forRefName: refName since: fromDate until: toDate [
×
399

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

×
425
                newlyFoundCommit := self parseCommitsResult: results.
×
426
        aGLHBranch commits
×
427
                        addAll: newlyFoundCommit
×
428
                        unless: self blockOnIdEquality.
×
429
        foundCommit addAll: newlyFoundCommit.  
×
430
                        ].
×
431

×
432
        self glhModel
×
433
                addAll: aGLHBranch commits
×
434
                unless: self blockOnIdEquality.
×
435

×
436
        "self withCommitDiffs ifTrue: [
×
437
                aGLHBranch commits: [ :commit | self importDiffOfCommit: commit ] ]."
×
438

×
439
        ^ foundCommit
×
440
]
×
441

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

×
445
        ^ self
×
446
                  importCommitsOfBranch: aGLHBranch
×
447
                  forRefName: aGLHBranch name
×
448
                  since: nil
×
449
                  until: toDate
×
450
]
×
451

452
{ #category : #api }
453
GLHModelImporter >> importDiffOfCommit: aCommit [
1✔
454

1✔
455
        | result diffsResult |
1✔
456
        aCommit diffs ifNotEmpty: [
1✔
457
                'Diff already importer: ' , aCommit short_id printString recordInfo.
1✔
458
                ^ aCommit diffs ].
1✔
459
        ('Import diff of commit: ' , aCommit short_id printString) recordInfo.
1✔
460
        result := self glhApi
1✔
461
                          commitDiff: aCommit id
1✔
462
                          ofProject: aCommit repository project id
1✔
463
                          unidiff: true.
1✔
464
        diffsResult := self parseDiffResult: result.
1✔
465

1✔
466
        ^ aCommit diffs addAll: diffsResult unless: self blockForDiffEquality.
1✔
467

1✔
468
]
1✔
469

470
{ #category : #'private - api' }
471
GLHModelImporter >> importDirectoryFiles: aDirectoryFile OfBranch: aBranch [
×
472

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

491
{ #category : #'private - api' }
492
GLHModelImporter >> importFilesOfBranch: aBranch [
×
493

×
494
        | result files apiFiles |
×
495
        result := self glhApi
×
496
                          treeOfRepository: aBranch repository project id
×
497
                          ofBranch: aBranch name
×
498
                          andPath: nil.
×
499
        apiFiles := self parseFileTreeResult: result.
×
500
        files := apiFiles collect: [ :apiFile | 
×
501
                         self convertApiFileAsFile: apiFile ].
×
502
        files do: [ :file | 
×
503
                self glhModel add: file.
×
504
                aBranch addFile: file ].
×
505
        files
×
506
                select: [ :file | file isKindOf: GLHFileDirectory ]
×
507
                thenCollect: [ :file | 
×
508
                self importDirectoryFiles: file OfBranch: aBranch ]
×
509
]
×
510

511
{ #category : #api }
512
GLHModelImporter >> importGroup: aGroupID [
1✔
513

1✔
514
        | result groupResult |
1✔
515
        ('Import group: ' , aGroupID printString) recordInfo.
1✔
516

1✔
517
        result := self glhApi group: aGroupID.
1✔
518
        groupResult := self parseGroupResult: result.
1✔
519

1✔
520
        groupResult projects do: [ :project |
1✔
521
                self completeImportProject: project ].
1✔
522
        self addGroupResultToModel: groupResult.
1✔
523
        (self subGroupsOf: aGroupID) do: [ :subGroup |
1✔
524
                groupResult addSubGroup: (self importGroup: subGroup id) ].
1✔
525
        ^ groupResult
1✔
526
]
1✔
527

528
{ #category : #api }
529
GLHModelImporter >> importJobsOf: aPipeline [
×
530

×
531
        | result jobs |
×
532
        result := self glhApi
×
533
                          jobsOfProject: aPipeline project id
×
534
                          ofPipelines: aPipeline id.
×
535
        jobs := self parseJobsResult: result ofProject: aPipeline project.
×
536
        jobs do: [ :job | aPipeline addJob: job ].
×
537
        self glhModel addAll: jobs
×
538

×
539
]
×
540

541
{ #category : #commit }
542
GLHModelImporter >> importParentCommitsOfCommit: aGLHCommit forOnly: number [
×
543

×
544
        | parentsIds commits |
×
545
        commits := OrderedCollection new.
×
546
        number = 0 ifTrue: [
×
547
                ^ commits
×
548
                          add: aGLHCommit;
×
549
                          yourself ].
×
550

×
551
        parentsIds := aGLHCommit parent_ids.
×
552

×
553
        commits addAll: (parentsIds collect: [ :id |
×
554
                         self
×
555
                                 importCommitOfProject: aGLHCommit repository project
×
556
                                 withId: id.
×
557
                         (self selectEntityType: GLHCommit overAttribut: #id equalTo: id)
×
558
                                 first ]).
×
559

×
560

×
561
        ^ commits , (commits collect: [ :parentCommit |
×
562
                   self
×
563
                           importParentCommitsOfCommit: parentCommit
×
564
                           forOnly: number - 1 ]) flatten
×
565
]
×
566

567
{ #category : #commit }
568
GLHModelImporter >> importParentCommitsOfCommit: aGLHCommit since: aDate [
×
569

×
570
        | parentsIds commits |
×
571
        commits := OrderedCollection new.
×
572
        aGLHCommit created_at asDateAndTime < aDate asDateAndTime ifTrue: [
×
573
                 
×
574
                ^ commits
×
575
                          add: aGLHCommit;
×
576
                          yourself ].
×
577

×
578
        parentsIds := aGLHCommit parent_ids.
×
579

×
580
        commits addAll: (parentsIds collect: [ :id |
×
581
                         self
×
582
                                 importCommitOfProject: aGLHCommit repository project
×
583
                                 withId: id ]).
×
584

×
585

×
586
        ^ (commits collect: [ :parentCommit |
×
587
                   self importParentCommitsOfCommit: parentCommit since: aDate ])
×
588
                  flatten
×
589
]
×
590

591
{ #category : #'private - api' }
592
GLHModelImporter >> importPipelinesOfProject: aGLHProject [
1✔
593

1✔
594
        (self pipelinesOf: aGLHProject id) do: [ :pipeline |
1✔
595
                self glhModel add: pipeline.
1✔
596
                aGLHProject addPipeline: pipeline ]
1✔
597
]
1✔
598

599
{ #category : #imports }
NEW
600
GLHModelImporter >> importProjects [
×
NEW
601
        "heavy import of all projects"
×
NEW
602
        
×
NEW
603
        "copy import from commits"
×
NEW
604
        
×
NEW
605
        
×
NEW
606
        | newlyFoundProjects page foundProject amount|
×
NEW
607
        ('import all Projects into the model') recordInfo.
×
NEW
608
        
×
NEW
609
        "number of projects per page"
×
NEW
610
        amount := 50.
×
NEW
611
        page := 0.
×
NEW
612
        foundProject := OrderedCollection new.
×
NEW
613
        newlyFoundProjects := { true }.
×
NEW
614
        [ newlyFoundProjects isNotEmpty ] whileTrue: [
×
NEW
615
                | results |
×
NEW
616
                page := page + 1.
×
NEW
617
                ('import project of page ' , page printString) recordInfo.
×
NEW
618
                results := self glhApi projects: amount page: page.
×
NEW
619
                
×
NEW
620
                newlyFoundProjects := glhModel
×
NEW
621
                                        addAll: (self parseArrayOfProject: results)
×
NEW
622
                                        unless: self blockOnIdEquality.
×
NEW
623
                foundProject addAll: newlyFoundProjects 
×
NEW
624
                
×
NEW
625
                ].
×
NEW
626

×
NEW
627
        ^ foundProject
×
NEW
628
        
×
NEW
629
]
×
630

631
{ #category : #imports }
NEW
632
GLHModelImporter >> importProjectsSince: since [
×
NEW
633
        "heavy import of all projects"
×
NEW
634

×
NEW
635
        "copy import from commits"
×
NEW
636

×
NEW
637
        | newlyFoundProjects page foundProject amount |
×
NEW
638
        'import all Projects into the model' recordInfo.
×
NEW
639

×
NEW
640
        "number of projects per page"
×
NEW
641
        amount := 100.
×
NEW
642
        page := 0.
×
NEW
643
        foundProject := OrderedCollection new.
×
NEW
644
        newlyFoundProjects := { true }.
×
NEW
645
        [ newlyFoundProjects isNotEmpty ] whileTrue: [
×
NEW
646
                | results |
×
NEW
647
                page := page + 1.
×
NEW
648
                ('import project of page ' , page printString) recordInfo.
×
NEW
649
                results := self glhApi projects: amount since: since page: page.
×
NEW
650

×
NEW
651
                newlyFoundProjects := glhModel
×
NEW
652
                                              addAll: (self parseArrayOfProject: results)
×
NEW
653
                                              unless: self blockOnIdEquality.
×
NEW
654
                foundProject addAll: newlyFoundProjects ].
×
NEW
655

×
NEW
656
        ^ foundProject
×
NEW
657
]
×
658

659
{ #category : #'private - api' }
660
GLHModelImporter >> importRepository: aGLHRepository [
1✔
661

1✔
662
        | resultBranches branches |
1✔
663
        [
1✔
664
        ('import the repository of project ' , aGLHRepository project name)
1✔
665
                recordInfo.
1✔
666

1✔
667
        resultBranches := self glhApi branchesOfRepository:
1✔
668
                                  aGLHRepository project id.
1✔
669
        branches := self parseBranchesResult: resultBranches.
1✔
670

1✔
671
        ('import the branches of project ') recordInfo.
1✔
672

1✔
673
        aGLHRepository branches
1✔
674
                addAll: branches
1✔
675
                unless: self blockOnNameEquality.
1✔
676
        self glhModel addAll: branches unless: self blockOnNameEquality.
1✔
677

1✔
678
        "branches do: [ :branch |
1✔
679
                aGLHRepository addBranch: branch.
1✔
680
                self glhModel add: branch ]."
1✔
681

1✔
682
        self withFiles ifTrue: [
1✔
683
                branches do: [ :branch | self importFilesOfBranch: branch ] ] ]
1✔
684
                on: NeoJSONParseError
1✔
685
                do: [
1✔
686
                self inform: aGLHRepository project name , ' has no repository' ]
1✔
687
]
1✔
688

689
{ #category : #'private - api' }
690
GLHModelImporter >> importUser: aUserID [
1✔
691

1✔
692
        | result userResult |
1✔
693

1✔
694
        (glhModel allWithType: GLHUser) asOrderedCollection detect: [ :user | user id = aUserID ] ifFound: [ :user | ^ user ].
1✔
695
        ('Import user: ' , aUserID printString) recordInfo.
1✔
696
        result := self glhApi user: aUserID.
1✔
697
        userResult := self parseUserResult: result.
1✔
698
        ^ glhModel add: userResult unless: self blockOnIdEquality
1✔
699
]
1✔
700

701
{ #category : #user }
702
GLHModelImporter >> importUserByUsername: anUsername [
1✔
703

1✔
704
        | dicUsername |
1✔
705
        dicUsername := ((self glhModel allWithType: GLHUser) collect: [ :user |
1✔
706
                                user username -> user ]) asSet asDictionary.
1✔
707

1✔
708
        ^ dicUsername at: anUsername ifPresent: [ :user | user ] ifAbsent: [
1✔
709
                  | result userId searchResult |
1✔
710
                  ('Import user with username: ' , anUsername printString)
1✔
711
                          recordInfo.
1✔
712
                  result := self glhApi usersSearchByUsername: anUsername.
1✔
713
                  searchResult := NeoJSONReader fromString: result.
1✔
714

1✔
715
                  (searchResult class = Dictionary and: [
1✔
716
                           (searchResult at: #message) includesSubstring: '403 Forbidden' ])
1✔
717
                          ifTrue: [ glhModel add: (GLHUser new username: anUsername) unless: [ :nu :ou | nu username = ou username ] ]
1✔
718
                          ifFalse: [
1✔
719
                                  searchResult
1✔
720
                                          ifEmpty: [
1✔
721
                                                  GLHUser new
1✔
722
                                                          username: anUsername;
1✔
723
                                                          yourself ]
1✔
724
                                          ifNotEmpty: [
1✔
725
                                                  userId := searchResult first at: #id.
1✔
726
                                                  (self glhModel allWithType: GLHUser)
1✔
727
                                                          detect: [ :user | user id = userId ]
1✔
728
                                                          ifNone: [ self importUser: userId ] ] ] ]
1✔
729
]
1✔
730

731
{ #category : #initialization }
732
GLHModelImporter >> initialize [
1✔
733

1✔
734
        withFiles := false.
1✔
735
        withCommitDiffs := false.
1✔
736
        withInitialCommits := false. 
1✔
737
        withInitialMergeRequest := false. 
1✔
738
        withCommitsSince := (Date today - 1 week) asDateAndTime
1✔
739
]
1✔
740

741
{ #category : #importer }
NEW
742
GLHModelImporter >> loadAllSystemProjects [
×
NEW
743
        "heavy import that load all the active project inside the model. Only import the project entities"
×
NEW
744
        |projects|
×
NEW
745
        
×
NEW
746
        projects := self glhApi projects. 
×
NEW
747
]
×
748

749
{ #category : #parsing }
NEW
750
GLHModelImporter >> parseArrayOfProject: arrayOfProjects [
×
NEW
751

×
NEW
752
        | reader |
×
NEW
753
        reader := NeoJSONReader on: arrayOfProjects readStream.
×
NEW
754
        reader
×
NEW
755
                for: #ArrayOfProjects
×
NEW
756
                customDo: [ :customMappting |
×
NEW
757
                customMappting listOfElementSchema: GLHProject ].
×
NEW
758
        reader for: GLHProject do: [ :mapping |
×
NEW
759
                mapping mapInstVar: #name to: #name.
×
NEW
760
                mapping mapInstVar: #description to: #description.
×
NEW
761
                mapping mapInstVar: #id to: #id.
×
NEW
762
                mapping mapInstVar: #archived to: #archived.
×
NEW
763
                mapping mapInstVar: #web_url to: #html_url.
×
NEW
764
                mapping mapInstVar: #topics to: #topics ].
×
NEW
765
        ^ reader nextAs: #ArrayOfProjects
×
NEW
766
]
×
767

768
{ #category : #private }
769
GLHModelImporter >> parseBranchesResult: result [
1✔
770

1✔
771
        | reader |
1✔
772
        reader := NeoJSONReader on: result readStream.
1✔
773
        reader mapInstVarsFor: GLHBranch.
1✔
774
        reader
1✔
775
                for: #ArrayOfBranch
1✔
776
                customDo: [ :customMappting | 
1✔
777
                customMappting listOfElementSchema: GLHBranch ].
1✔
778
        ^ reader nextAs: #ArrayOfBranch
1✔
779
]
1✔
780

781
{ #category : #private }
782
GLHModelImporter >> parseCommitResult: result [
×
783

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

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

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

×
805
        reader
×
806
                for: #ArrayOfIds
×
807
                customDo: [ :mapping | mapping decoder: [ :string | string ] ].
×
808

×
809

×
810
        ^ reader nextAs: GLHCommit
×
811
]
×
812

813
{ #category : #private }
814
GLHModelImporter >> parseCommitsResult: result [
1✔
815

1✔
816
        | reader |
1✔
817
        reader := NeoJSONReader on: result readStream.
1✔
818

1✔
819
          reader for: GLHCommit do: [ :mapping |
1✔
820
                mapping mapInstVars:
1✔
821
                        #( id short_id title author_name author_email committer_name
1✔
822
                           committer_email message web_url ).
1✔
823
                (mapping mapInstVar: #authored_date) valueSchema: DateAndTime.
1✔
824
                (mapping mapInstVar: #committed_date) valueSchema: DateAndTime.
1✔
825
                (mapping mapInstVar: #created_at) valueSchema: DateAndTime.
1✔
826
                (mapping mapInstVar: #parent_ids) valueSchema: #ArrayOfIds.
1✔
827
                mapping
1✔
828
                        mapProperty: 'stats'
1✔
829
                        getter: [ :el | "Not used" ]
1✔
830
                        setter: [ :commit :value |
1✔
831
                                commit deletions: (value at: #deletions).
1✔
832
                                commit additions: (value at: #additions) ] ].
1✔
833

1✔
834
        reader for: DateAndTime customDo: [ :mapping |
1✔
835
                mapping decoder: [ :string | DateAndTime fromString: string ] ].
1✔
836

1✔
837
        reader
1✔
838
                for: #ArrayOfIds
1✔
839
                customDo: [ :mapping | mapping decoder: [ :string | string ] ].
1✔
840
  
1✔
841
        reader
1✔
842
                for: #ArrayOfCommit
1✔
843
                customDo: [ :customMappting |
1✔
844
                customMappting listOfElementSchema: GLHCommit ].
1✔
845

1✔
846
        ^ reader nextAs: #ArrayOfCommit
1✔
847
]
1✔
848

849
{ #category : #private }
850
GLHModelImporter >> parseDiffResult: result [
1✔
851

1✔
852
        | reader |
1✔
853
        reader := NeoJSONReader on: result readStream.
1✔
854
        reader for: GLHDiff do: [ :mapping |
1✔
855
                mapping mapInstVars:
1✔
856
                        #( deleted_file new_file new_path old_path renamed_file ).
1✔
857
                mapping mapInstVar: #diffString to: #diff ].
1✔
858

1✔
859
        reader
1✔
860
                for: #ArrayOfDiffs
1✔
861
                customDo: [ :customMappting |
1✔
862
                customMappting listOfElementSchema: GLHDiff ].
1✔
863
        ^ reader nextAs: #ArrayOfDiffs
1✔
864
]
1✔
865

866
{ #category : #private }
867
GLHModelImporter >> parseFileTreeResult: aResult [
×
868

×
869
        | reader |
×
870
        reader := NeoJSONReader on: aResult readStream.
×
871
        reader mapInstVarsFor: GLHApiFile.
×
872
        reader
×
873
                for: #ArrayOfFile
×
874
                customDo: [ :customMappting | 
×
875
                customMappting listOfElementSchema: GLHApiFile ].
×
876
        ^ reader nextAs: #ArrayOfFile
×
877
]
×
878

879
{ #category : #private }
880
GLHModelImporter >> parseGroupResult: aResult [
1✔
881

1✔
882
        | reader |
1✔
883

1✔
884
        reader := NeoJSONReader on: aResult readStream.
1✔
885
        reader for: GLHGroup do: [ :mapping |
1✔
886
                mapping mapInstVars.
1✔
887
                (mapping mapInstVar: #projects) valueSchema: #ArrayOfProjects ].
1✔
888
        reader mapInstVarsFor: GLHProject.
1✔
889
        reader
1✔
890
                for: #ArrayOfProjects
1✔
891
                customDo: [ :customMappting |
1✔
892
                customMappting listOfElementSchema: GLHProject ].
1✔
893
        ^ reader nextAs: GLHGroup
1✔
894
]
1✔
895

896
{ #category : #private }
897
GLHModelImporter >> parseJobsResult: result ofProject: aProject [
×
898

×
899
        | reader |
×
900
        reader := NeoJSONReader on: result readStream.
×
901
        reader for: GLHJob do: [ :mapping |
×
902
                mapping mapInstVars: #( id allow_failure web_url name ).
×
903

×
904
                mapping
×
905
                        mapProperty: #user
×
906
                        getter: [ :object | #ignore ]
×
907
                        setter: [ :object :value |
×
908
                        object user: (self importUser: (value at: #id)) ].
×
909

×
910
                mapping
×
911
                        mapProperty: #commit
×
912
                        getter: [ :object | #ignore ]
×
913
                        setter: [ :object :value |
×
914
                                value ifNotNil: [
×
915
                                        object commit:
×
916
                                                (self importCommit: (value at: #id) ofProject: aProject) ] ].
×
917

×
918
                mapping
×
919
                        mapProperty: #duration
×
920
                        getter: [ :object | #ignore ]
×
921
                        setter: [ :object :value |
×
922
                        value ifNotNil: [ object duration: value seconds ] ] ].
×
923

×
924
        reader
×
925
                for: #ArrayOfGLHJob
×
926
                customDo: [ :customMappting |
×
927
                customMappting listOfElementSchema: GLHJob ].
×
928
        ^ reader nextAs: #ArrayOfGLHJob
×
929
]
×
930

931
{ #category : #private }
932
GLHModelImporter >> parsePipelinesResult: result [
1✔
933

1✔
934
        | reader |
1✔
935
        reader := NeoJSONReader on: result readStream.
1✔
936
        reader mapInstVarsFor: GLHPipeline.
1✔
937
        reader for: GLHPipeline do: [ :mapping |
1✔
938
                mapping
1✔
939
                        mapProperty: #created_at
1✔
940
                        getter: [ :object | #ignore ]
1✔
941
                        setter: [ :object :value |
1✔
942
                        object runDate: (DateAndTime fromString: value) ] ].
1✔
943
        reader
1✔
944
                for: #ArrayOfPipelines
1✔
945
                customDo: [ :customMappting |
1✔
946
                customMappting listOfElementSchema: GLHPipeline ].
1✔
947
        ^ reader nextAs: #ArrayOfPipelines
1✔
948
]
1✔
949

950
{ #category : #private }
951
GLHModelImporter >> parseSubGroupResult: aResult [
1✔
952

1✔
953
        | reader |
1✔
954
        reader := NeoJSONReader on: aResult readStream.
1✔
955
        reader mapInstVarsFor: GLHGroup.
1✔
956
        reader
1✔
957
                for: #ArrayOfGroups
1✔
958
                customDo: [ :customMappting | 
1✔
959
                customMappting listOfElementSchema: GLHGroup ].
1✔
960
        ^ reader nextAs: #ArrayOfGroups
1✔
961
]
1✔
962

963
{ #category : #private }
964
GLHModelImporter >> parseUserResult: result [
1✔
965

1✔
966
        | reader |
1✔
967
        reader := NeoJSONReader on: result readStream.
1✔
968
        reader mapInstVarsFor: GLHUser.
1✔
969
        ^ reader nextAs: GLHUser
1✔
970
]
1✔
971

972
{ #category : #'private - api' }
973
GLHModelImporter >> pipelinesOf: aProjectID [
1✔
974

1✔
975
        | result |
1✔
976
        ('Search pipelines of: ' , aProjectID printString) recordInfo.
1✔
977
        result := self glhApi pipelinesOfProject: aProjectID.
1✔
978
        ^ self parsePipelinesResult: result
1✔
979
]
1✔
980

981
{ #category : #'as yet unclassified' }
982
GLHModelImporter >> selectEntityType: aType overAttribut: aSelector equalTo: value [
×
983

×
984
        ^ (self glhModel allWithType: aType)
×
985
                select: [ :entity | (entity perform: aSelector) = value ]
×
986
]
×
987

988
{ #category : #'private - api' }
989
GLHModelImporter >> subGroupsOf: aGroupID [
1✔
990

1✔
991
        | results parsedResult result page |
1✔
992
        ('Search subgroup of: ' , aGroupID printString) recordInfo.
1✔
993
        results := OrderedCollection new.
1✔
994
        page := 1.
1✔
995
        result := self glhApi subgroupsOfGroup: aGroupID page: page.
1✔
996
        parsedResult := self parseSubGroupResult: result.
1✔
997
        results addAll: parsedResult.
1✔
998
        [ parsedResult size = 20 ] whileTrue: [ 
1✔
999
                page := page + 1.
1✔
1000
                result := self glhApi subgroupsOfGroup: aGroupID page: page.
1✔
1001
                parsedResult := self parseSubGroupResult: result.
1✔
1002
                results addAll: parsedResult ].
1✔
1003
        ^ results
1✔
1004
]
1✔
1005

1006
{ #category : #accessing }
1007
GLHModelImporter >> withCommitDiffs [
1✔
1008

1✔
1009
        ^ withCommitDiffs
1✔
1010
]
1✔
1011

1012
{ #category : #accessing }
1013
GLHModelImporter >> withCommitDiffs: anObject [
1✔
1014

1✔
1015
        withCommitDiffs := anObject
1✔
1016
]
1✔
1017

1018
{ #category : #accessing }
1019
GLHModelImporter >> withFiles [
1✔
1020
        ^ withFiles
1✔
1021
]
1✔
1022

1023
{ #category : #accessing }
1024
GLHModelImporter >> withFiles: aBoolean [
1✔
1025
        withFiles := aBoolean
1✔
1026
]
1✔
1027

1028
{ #category : #accessing }
1029
GLHModelImporter >> withInitialCommits: boolean [
×
1030
        withInitialCommits := boolean 
×
1031
]
×
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