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

moosetechnology / GitProjectHealth / 9682577336

26 Jun 2024 03:32PM UTC coverage: 29.519% (+2.6%) from 26.896%
9682577336

Pull #7

github

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

514 of 1154 new or added lines in 11 files covered. (44.54%)

17 existing lines in 3 files now uncovered.

2177 of 7375 relevant lines covered (29.52%)

0.3 hits per line

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

50.11
/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
        ('completing commit: ' , aCommit short_id printString)
1✔
103
                        recordInfo.
1✔
104
        aCommit commitCreator ifNil: [
1✔
105
                ('Import creator of commit: ' , aCommit short_id printString)
1✔
106
                        recordInfo.
1✔
107
                aCommit commitCreator:
1✔
108
                        (self importUserByUsername: aCommit author_name)
1✔
109

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

1✔
116
        self withCommitDiffs ifTrue: [
1✔
117
                | diffs |
1✔
118
                ('Import diff of commit: ' , aCommit short_id printString)
1✔
119
                        recordInfo.
1✔
120
                aCommit diffs ifEmpty: [
1✔
121
                        diffs := self importDiffOfCommit: aCommit.
1✔
122
                        self glhModel addAll: diffs unless: self blockForDiffEquality ] ].
1✔
123

1✔
124
        ^ aCommit
1✔
125
]
1✔
126

127
{ #category : #private }
128
GLHModelImporter >> configureReaderForCommit: reader [
×
129

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

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

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

×
157
]
×
158

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

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

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

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

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

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

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

1✔
192
        ^ glhApi
1✔
193
]
1✔
194

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

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

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

1✔
204
        ^ glhModel
1✔
205
]
1✔
206

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

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

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

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

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

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

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

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

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

1✔
251
                          commit ].
1✔
252

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

1✔
255
        ^ commit
1✔
256
]
1✔
257

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

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

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

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

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

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

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

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

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

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

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

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

1✔
339

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

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

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

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

×
382

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

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

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

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

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

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

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

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

×
440
        ^ foundCommit
×
441
]
×
442

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

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

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

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

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

1✔
469
]
1✔
470

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

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

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

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

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

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

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

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

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

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

×
540
]
×
541

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

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

×
552
        parentsIds := aGLHCommit parent_ids.
×
553

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

×
561

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

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

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

×
579
        parentsIds := aGLHCommit parent_ids.
×
580

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

×
586

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

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

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

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

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

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

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

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

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

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

×
NEW
657
        ^ foundProject
×
NEW
658
]
×
659

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

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

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

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

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

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

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

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

1✔
693
        | result userResult |
1✔
694

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

×
810

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

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

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

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

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

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

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

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

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

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

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

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

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

1✔
883
        | reader |
1✔
884

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1✔
1010
        ^ withCommitDiffs
1✔
1011
]
1✔
1012

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

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

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

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

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