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

moosetechnology / GitProjectHealth / 10075779876

24 Jul 2024 11:28AM UTC coverage: 31.874% (-0.4%) from 32.312%
10075779876

Pull #9

github

web-flow
Merge 3f514973e into 30d38cc2f
Pull Request #9: Refactoring/metrics interface

84 of 391 new or added lines in 10 files covered. (21.48%)

13 existing lines in 2 files now uncovered.

2526 of 7925 relevant lines covered (31.87%)

0.32 hits per line

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

53.73
/src/GitLabHealth-Model-Importer/GLHModelImporter.class.st
1
Class {
2
        #name : #GLHModelImporter,
3
        #superclass : #Object,
4
        #instVars : [
5
                'glhModel',
6
                'glhApi',
7
                'withFiles',
8
                'withCommitDiffs',
9
                'withCommitsSince',
10
                'withInitialCommits',
11
                'withInitialMergeRequest',
12
                'generalReader'
13
        ],
14
        #classVars : [
15
                'currentImporter'
16
        ],
17
        #category : #'GitLabHealth-Model-Importer'
18
}
19

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

×
NEW
23
        ^ currentImporter
×
NEW
24
]
×
25

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

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

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

43
{ #category : #private }
44
GLHModelImporter >> addGroupResultToModel: groupResult [
1✔
45

1✔
46
        self glhModel add: groupResult unless: (self blockEqualityOn: #id).
1✔
47
        self glhModel
1✔
48
                addAll: groupResult projects
1✔
49
                unless: (self blockEqualityOn: #id)
1✔
50
]
1✔
51

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

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

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

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

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

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

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

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

88
{ #category : #'private - api' }
89
GLHModelImporter >> completeImportProject: aGLHProject [
1✔
90

1✔
91
        ('Complete import of project: ' , aGLHProject id printString)
1✔
92
                recordInfo.
1✔
93

1✔
94
        self importPipelinesOfProject: aGLHProject.
1✔
95

1✔
96
        "aGLHProject creator: (self importUser: aGLHProject creator_id)."
1✔
97

1✔
98
        (self importUser: aGLHProject creator_id) addCreatedProject:
1✔
99
                aGLHProject.
1✔
100

1✔
101
        aGLHProject repository: GLHRepository new.
1✔
102
        self glhModel add: aGLHProject unless: (self blockEqualityOn: #id).
1✔
103
        self glhModel add: aGLHProject repository.
1✔
104
        self importRepository: aGLHProject repository.
1✔
105

1✔
106
        ^ aGLHProject
1✔
107
]
1✔
108

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

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

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

1✔
121
        ^ aCommit
1✔
122
]
1✔
123

124
{ #category : #private }
125
GLHModelImporter >> configureReaderForCommit: reader [
1✔
126

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

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

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

1✔
154
]
1✔
155

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

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

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

171
{ #category : #private }
172
GLHModelImporter >> configureReaderForGroup: reader [
1✔
173

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

188
{ #category : #private }
189
GLHModelImporter >> convertApiFileAsFile: aAPIFile [
×
190

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

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

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

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

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

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

1✔
221
        ^ glhApi
1✔
222
]
1✔
223

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

1✔
227
        glhApi := anObject
1✔
228
]
1✔
229

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

1✔
233
        ^ glhModel
1✔
234
]
1✔
235

236
{ #category : #accessing }
237
GLHModelImporter >> glhModel: anObject [
1✔
238

1✔
239
        glhModel := anObject
1✔
240
]
1✔
241

242
{ #category : #api }
243
GLHModelImporter >> importAllGroups [
×
244

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

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

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

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

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

1✔
282
        | commit result |
1✔
283
        anID ifNil: [ ^ nil ].
1✔
284

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

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

1✔
296
                          self glhModel add: commit unless: self blockOnIdEquality.
1✔
297
                          commit repository: anProject repository.
1✔
298

1✔
299
                          commit ].
1✔
300

1✔
301
        self withCommitDiffs ifTrue: [ self importDiffOfCommit: commit ].
1✔
302

1✔
303
        ^ commit
1✔
304
]
1✔
305

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

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

1✔
328
        parsedResults do: [ :commit |
1✔
329
                commit repository: aGLHProject repository ].
1✔
330

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

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

×
342
        | date |
×
343
        date := aCommit created_at asDateAndTime.
×
344

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

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

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

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

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

1✔
387

1✔
388
        ^ self glhModel addAll: foundCommit unless: self blockOnIdEquality
1✔
389
]
1✔
390

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

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

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

×
430

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

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

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

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

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

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

×
481
        self glhModel
×
482
                addAll: aGLHBranch commits
×
483
                unless: self blockOnIdEquality.
×
484

×
485
        "self withCommitDiffs ifTrue: [
×
486
                aGLHBranch commits: [ :commit | self importDiffOfCommit: commit ] ]."
×
487

×
488
        ^ foundCommit
×
489
]
×
490

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

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

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

509
{ #category : #api }
510
GLHModelImporter >> importDiffOfCommit: aCommit [
1✔
511

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

1✔
523
        ^ aCommit diffs addAll: diffsResult unless: self blockForDiffEquality.
1✔
524

1✔
525
]
1✔
526

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

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

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

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

568
{ #category : #api }
569
GLHModelImporter >> importGroup: aGroupID [
1✔
570

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

1✔
574
        result := self glhApi group: aGroupID.
1✔
575
        groupResult := self parseGroupResult: result.
1✔
576

1✔
577
        groupResult projects do: [ :project |
1✔
578
                self completeImportProject: project ].
1✔
579
        self addGroupResultToModel: groupResult.
1✔
580
        (self subGroupsOf: aGroupID) do: [ :subGroup |
1✔
581
                groupResult addSubGroup: (self importGroup: subGroup id) ].
1✔
582
        ^ groupResult
1✔
583
]
1✔
584

585
{ #category : #api }
586
GLHModelImporter >> importJobsOf: aPipeline [
×
587

×
588
        | result jobs |
×
589
        result := self glhApi
×
590
                          jobsOfProject: aPipeline project id
×
591
                          ofPipelines: aPipeline id.
×
592
        jobs := self parseJobsResult: result ofProject: aPipeline project.
×
593
        jobs do: [ :job | aPipeline addJob: job ].
×
594
        self glhModel addAll: jobs
×
595

×
596
]
×
597

598
{ #category : #commit }
599
GLHModelImporter >> importParentCommitsOfCommit: aGLHCommit forOnly: number [
×
600

×
601
        | parentsIds commits |
×
602
        commits := OrderedCollection new.
×
603
        number = 0 ifTrue: [
×
604
                ^ commits
×
605
                          add: aGLHCommit;
×
606
                          yourself ].
×
607

×
608
        parentsIds := aGLHCommit parent_ids.
×
609

×
610
        commits addAll: (parentsIds collect: [ :id |
×
611
                         self
×
612
                                 importCommitOfProject: aGLHCommit repository project
×
613
                                 withId: id.
×
614
                         (self selectEntityType: GLHCommit overAttribut: #id equalTo: id)
×
615
                                 first ]).
×
616

×
617

×
618
        ^ commits , (commits collect: [ :parentCommit |
×
619
                   self
×
620
                           importParentCommitsOfCommit: parentCommit
×
621
                           forOnly: number - 1 ]) flatten
×
622
]
×
623

624
{ #category : #commit }
625
GLHModelImporter >> importParentCommitsOfCommit: aGLHCommit since: aDate [
×
626

×
627
        | parentsIds commits |
×
628
        commits := OrderedCollection new.
×
629
        aGLHCommit created_at asDateAndTime < aDate asDateAndTime ifTrue: [
×
630
                 
×
631
                ^ commits
×
632
                          add: aGLHCommit;
×
633
                          yourself ].
×
634

×
635
        parentsIds := aGLHCommit parent_ids.
×
636

×
637
        commits addAll: (parentsIds collect: [ :id |
×
638
                         self
×
639
                                 importCommitOfProject: aGLHCommit repository project
×
640
                                 withId: id ]).
×
641

×
642

×
643
        ^ (commits collect: [ :parentCommit |
×
644
                   self importParentCommitsOfCommit: parentCommit since: aDate ])
×
645
                  flatten
×
646
]
×
647

648
{ #category : #'private - api' }
649
GLHModelImporter >> importPipelinesOfProject: aGLHProject [
1✔
650

1✔
651
        (self pipelinesOf: aGLHProject id) do: [ :pipeline |
1✔
652
                self glhModel add: pipeline.
1✔
653
                aGLHProject addPipeline: pipeline ]
1✔
654
]
1✔
655

656
{ #category : #imports }
657
GLHModelImporter >> importProjects [
×
658
        "heavy import of all projects"
×
NEW
659

×
660
        "copy import from commits"
×
NEW
661

×
NEW
662
        | newlyFoundProjects page foundProject amount |
×
NEW
663
        'import all Projects into the model' recordInfo.
×
NEW
664

×
665
        "number of projects per page"
×
NEW
666
        amount := 100.
×
667
        page := 0.
×
668
        foundProject := OrderedCollection new.
×
669
        newlyFoundProjects := { true }.
×
670
        [ newlyFoundProjects isNotEmpty ] whileTrue: [
×
671
                | results |
×
672
                page := page + 1.
×
673
                ('import project of page ' , page printString) recordInfo.
×
674
                results := self glhApi projects: amount page: page.
×
NEW
675

×
676
                newlyFoundProjects := glhModel
×
NEW
677
                                              addAll: (self parseArrayOfProject: results)
×
NEW
678
                                              unless: self blockOnIdEquality.
×
NEW
679
                foundProject addAll: newlyFoundProjects ].
×
680

×
681
        ^ foundProject
×
NEW
682
]
×
683

684
{ #category : #projects }
NEW
685
GLHModelImporter >> importProjects: aCollectionOfProjectID [
×
686
        
×
NEW
687
        ^ aCollectionOfProjectID collect: [ :id |
×
NEW
688
                self importProject: id.
×
NEW
689
                 ]
×
NEW
690
         
×
UNCOV
691
]
×
692

693
{ #category : #imports }
694
GLHModelImporter >> importProjectsSince: since [
×
695
        "heavy import of all projects"
×
696

×
697
        "copy import from commits"
×
698

×
699
        | newlyFoundProjects page foundProject amount |
×
700
        'import all Projects into the model' recordInfo.
×
701

×
702
        "number of projects per page"
×
703
        amount := 100.
×
704
        page := 0.
×
705
        foundProject := OrderedCollection new.
×
706
        newlyFoundProjects := { true }.
×
707
        [ newlyFoundProjects isNotEmpty ] whileTrue: [
×
708
                | results |
×
709
                page := page + 1.
×
NEW
710
                ('import projects page #' , page printString) recordInfo.
×
711
                results := self glhApi projects: amount since: since page: page.
×
712

×
713
                newlyFoundProjects := glhModel
×
714
                                              addAll: (self parseArrayOfProject: results)
×
715
                                              unless: self blockOnIdEquality.
×
716
                foundProject addAll: newlyFoundProjects ].
×
717

×
718
        ^ foundProject
×
719
]
×
720

721
{ #category : #'private - api' }
722
GLHModelImporter >> importRepository: aGLHRepository [
1✔
723

1✔
724
        | resultBranches branches |
1✔
725
        [
1✔
726
        ('import the repository of project ' , aGLHRepository project name)
1✔
727
                recordInfo.
1✔
728

1✔
729
        resultBranches := self glhApi branchesOfRepository:
1✔
730
                                  aGLHRepository project id.
1✔
731
        branches := self parseBranchesResult: resultBranches.
1✔
732

1✔
733
        ('import the branches of project ') recordInfo.
1✔
734

1✔
735
        aGLHRepository branches
1✔
736
                addAll: branches
1✔
737
                unless: self blockOnNameEquality.
1✔
738
        self glhModel addAll: branches unless: self blockOnNameEquality.
1✔
739

1✔
740
        "branches do: [ :branch |
1✔
741
                aGLHRepository addBranch: branch.
1✔
742
                self glhModel add: branch ]."
1✔
743

1✔
744
        self withFiles ifTrue: [
1✔
745
                branches do: [ :branch | self importFilesOfBranch: branch ] ] ]
1✔
746
                on: NeoJSONParseError
1✔
747
                do: [
1✔
748
                self inform: aGLHRepository project name , ' has no repository' ]
1✔
749
]
1✔
750

751
{ #category : #'private - api' }
752
GLHModelImporter >> importUser: aUserID [
1✔
753

1✔
754
        | result userResult |
1✔
755
        (glhModel allWithType: GLHUser) asOrderedCollection
1✔
756
                detect: [ :user | user id = aUserID ]
1✔
757
                ifFound: [ :user | ^ user ].
1✔
758
        ('Import user: ' , aUserID printString) recordInfo.
1✔
759
        result := self glhApi user: aUserID.
1✔
760
        userResult := self parseUserResult: result.
1✔
761
        ^ glhModel add: userResult unless: self blockOnIdEquality
1✔
762
]
1✔
763

764
{ #category : #user }
765
GLHModelImporter >> importUserByUsername: anUsername [
1✔
766

1✔
767
        | dicUsername |
1✔
768
        dicUsername := ((self glhModel allWithType: GLHUser) collect: [ :user |
1✔
769
                                user username -> user ]) asSet asDictionary.
1✔
770

1✔
771
        ^ dicUsername at: anUsername ifPresent: [ :user | user ] ifAbsent: [
1✔
772
                  | result userId searchResult |
1✔
773
                  ('Import user with username: ' , anUsername printString)
1✔
774
                          recordInfo.
1✔
775
                  result := self glhApi usersSearchByUsername: anUsername.
1✔
776
                  searchResult := NeoJSONReader fromString: result.
1✔
777

1✔
778
                  (searchResult class = Dictionary and: [
1✔
779
                           (searchResult at: #message) includesSubstring: '403 Forbidden' ])
1✔
780
                          ifTrue: [
1✔
781
                                  glhModel
1✔
782
                                          add: (GLHUser new username: anUsername; name: anUsername; yourself )
1✔
783
                                          unless: [ :nu :ou | nu username = ou username ] ]
1✔
784
                          ifFalse: [
1✔
785
                                  searchResult
1✔
786
                                          ifEmpty: [
1✔
787
                                                  GLHUser new
1✔
788
                                                          username: anUsername;
1✔
789
                                                          yourself ]
1✔
790
                                          ifNotEmpty: [
1✔
791
                                                  userId := searchResult first at: #id.
1✔
792
                                                  (self glhModel allWithType: GLHUser)
1✔
793
                                                          detect: [ :user | user id = userId ]
1✔
794
                                                          ifNone: [ self importUser: userId ] ] ] ]
1✔
795
]
1✔
796

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

1✔
800
        generalReader := NeoJSONReader new.
1✔
801
        self configureReaderForCommit: generalReader.
1✔
802
        self configureReaderForGroup: generalReader.
1✔
803
        self configureReaderForDiffs: generalReader. 
1✔
804
]
1✔
805

806
{ #category : #initialization }
807
GLHModelImporter >> initialize [
1✔
808

1✔
809
        withFiles := false.
1✔
810
        withCommitDiffs := false.
1✔
811
        withInitialCommits := false.
1✔
812
        withInitialMergeRequest := false.
1✔
813
        withCommitsSince := (Date today - 1 week) asDateAndTime.
1✔
814
        self initReader.
1✔
815
        currentImporter := self. 
1✔
816
]
1✔
817

818
{ #category : #importer }
819
GLHModelImporter >> loadAllSystemProjects [
×
820
        "heavy import that load all the active project inside the model. Only import the project entities"
×
821
        |projects|
×
822
        
×
823
        projects := self glhApi projects. 
×
824
]
×
825

826
{ #category : #private }
827
GLHModelImporter >> newParseCommitResult: result [
×
828

×
829
        generalReader  on: result readStream.
×
830

×
831
        ^ generalReader nextAs: GLHCommit
×
832
]
×
833

834
{ #category : #private }
835
GLHModelImporter >> newParseDiffResult: result [
1✔
836

1✔
837
        generalReader on: result readStream.
1✔
838
        ^ generalReader nextAs: #ArrayOfDiffs
1✔
839
]
1✔
840

841
{ #category : #parsing }
842
GLHModelImporter >> parseArrayOfProject: arrayOfProjects [
×
843

×
844
        | reader |
×
845
        reader := NeoJSONReader on: arrayOfProjects readStream.
×
846
        reader
×
847
                for: #ArrayOfProjects
×
848
                customDo: [ :customMappting |
×
849
                customMappting listOfElementSchema: GLHProject ].
×
850
        reader for: GLHProject do: [ :mapping |
×
851
                mapping mapInstVar: #name to: #name.
×
852
                mapping mapInstVar: #description to: #description.
×
853
                mapping mapInstVar: #id to: #id.
×
854
                mapping mapInstVar: #archived to: #archived.
×
855
                mapping mapInstVar: #web_url to: #html_url.
×
856
                mapping mapInstVar: #topics to: #topics ].
×
857
        ^ reader nextAs: #ArrayOfProjects
×
858
]
×
859

860
{ #category : #private }
861
GLHModelImporter >> parseBranchesResult: result [
1✔
862

1✔
863
        | reader |
1✔
864
        reader := NeoJSONReader on: result readStream.
1✔
865
        reader mapInstVarsFor: GLHBranch.
1✔
866
        reader
1✔
867
                for: #ArrayOfBranch
1✔
868
                customDo: [ :customMappting | 
1✔
869
                customMappting listOfElementSchema: GLHBranch ].
1✔
870
        ^ reader nextAs: #ArrayOfBranch
1✔
871
]
1✔
872

873
{ #category : #private }
874
GLHModelImporter >> parseCommitResult: result [
×
875

×
876
        | reader |
×
877
        reader := NeoJSONReader on: result readStream.
×
878

×
879
        reader for: GLHCommit do: [ :mapping |
×
880
                mapping mapInstVars:
×
881
                        #( id short_id title author_name author_email committer_name
×
882
                           committer_email message web_url ).
×
883
                (mapping mapInstVar: #authored_date) valueSchema: DateAndTime.
×
884
                (mapping mapInstVar: #committed_date) valueSchema: DateAndTime.
×
885
                (mapping mapInstVar: #created_at) valueSchema: DateAndTime.
×
886
                (mapping mapInstVar: #parent_ids) valueSchema: #ArrayOfIds.
×
887
                mapping
×
888
                        mapProperty: 'stats'
×
889
                        getter: [ :el | "Not used" ]
×
890
                        setter: [ :commit :value |
×
891
                                commit deletions: (value at: #deletions).
×
892
                                commit additions: (value at: #additions) ] ].
×
893

×
894
        reader for: DateAndTime customDo: [ :mapping |
×
895
                mapping decoder: [ :string | DateAndTime fromString: string ] ].
×
896

×
897
        reader
×
898
                for: #ArrayOfIds
×
899
                customDo: [ :mapping | mapping decoder: [ :string | string ] ].
×
900

×
901

×
902
        ^ reader nextAs: GLHCommit
×
903
]
×
904

905
{ #category : #private }
906
GLHModelImporter >> parseCommitsResult: result [
1✔
907

1✔
908
        | reader |
1✔
909
        reader := NeoJSONReader on: result readStream.
1✔
910

1✔
911
          reader for: GLHCommit do: [ :mapping |
1✔
912
                mapping mapInstVars:
1✔
913
                        #( id short_id title author_name author_email committer_name
1✔
914
                           committer_email message web_url ).
1✔
915
                (mapping mapInstVar: #authored_date) valueSchema: DateAndTime.
1✔
916
                (mapping mapInstVar: #committed_date) valueSchema: DateAndTime.
1✔
917
                (mapping mapInstVar: #created_at) valueSchema: DateAndTime.
1✔
918
                (mapping mapInstVar: #parent_ids) valueSchema: #ArrayOfIds.
1✔
919
                mapping
1✔
920
                        mapProperty: 'stats'
1✔
921
                        getter: [ :el | "Not used" ]
1✔
922
                        setter: [ :commit :value |
1✔
923
                                commit deletions: (value at: #deletions).
1✔
924
                                commit additions: (value at: #additions) ] ].
1✔
925

1✔
926
        reader for: DateAndTime customDo: [ :mapping |
1✔
927
                mapping decoder: [ :string | DateAndTime fromString: string ] ].
1✔
928

1✔
929
        reader
1✔
930
                for: #ArrayOfIds
1✔
931
                customDo: [ :mapping | mapping decoder: [ :string | string ] ].
1✔
932
  
1✔
933
        reader
1✔
934
                for: #ArrayOfCommit
1✔
935
                customDo: [ :customMappting |
1✔
936
                customMappting listOfElementSchema: GLHCommit ].
1✔
937

1✔
938
        ^ reader nextAs: #ArrayOfCommit
1✔
939
]
1✔
940

941
{ #category : #private }
942
GLHModelImporter >> parseDiffResult: result [
1✔
943

1✔
944
        | reader |
1✔
945
        self
1✔
946
                deprecated: 'Use #newParseDiffResult: instead'
1✔
947
                on: '28 June 2024'
1✔
948
                in:
1✔
949
                'Pharo-11.0.0+build.726.sha.aece1b5473acf3830a0e082c1bc3a15d4ff3522b (64 Bit)'.
1✔
950
        reader := NeoJSONReader on: result readStream.
1✔
951
        reader for: GLHDiff do: [ :mapping |
1✔
952
                mapping mapInstVars:
1✔
953
                        #( deleted_file new_file new_path old_path renamed_file ).
1✔
954
                mapping mapInstVar: #diffString to: #diff ].
1✔
955

1✔
956
        reader
1✔
957
                for: #ArrayOfDiffs
1✔
958
                customDo: [ :customMappting |
1✔
959
                customMappting listOfElementSchema: GLHDiff ].
1✔
960
        ^ reader nextAs: #ArrayOfDiffs
1✔
961
]
1✔
962

963
{ #category : #private }
964
GLHModelImporter >> parseFileTreeResult: aResult [
×
965

×
966
        | reader |
×
967
        reader := NeoJSONReader on: aResult readStream.
×
968
        reader mapInstVarsFor: GLHApiFile.
×
969
        reader
×
970
                for: #ArrayOfFile
×
971
                customDo: [ :customMappting | 
×
972
                customMappting listOfElementSchema: GLHApiFile ].
×
973
        ^ reader nextAs: #ArrayOfFile
×
974
]
×
975

976
{ #category : #private }
977
GLHModelImporter >> parseGroupResult: aResult [
1✔
978

1✔
979
        | reader |
1✔
980

1✔
981
        reader := NeoJSONReader on: aResult readStream.
1✔
982
        reader for: GLHGroup do: [ :mapping |
1✔
983
                mapping mapInstVars.
1✔
984
                (mapping mapInstVar: #projects) valueSchema: #ArrayOfProjects ].
1✔
985
        reader mapInstVarsFor: GLHProject.
1✔
986
        reader
1✔
987
                for: #ArrayOfProjects
1✔
988
                customDo: [ :customMappting |
1✔
989
                customMappting listOfElementSchema: GLHProject ].
1✔
990
        ^ reader nextAs: GLHGroup
1✔
991
]
1✔
992

993
{ #category : #private }
994
GLHModelImporter >> parseJobsResult: result ofProject: aProject [
×
995

×
996
        | reader |
×
997
        reader := NeoJSONReader on: result readStream.
×
998
        reader for: GLHJob do: [ :mapping |
×
999
                mapping mapInstVars: #( id allow_failure web_url name ).
×
1000

×
1001
                mapping
×
1002
                        mapProperty: #user
×
1003
                        getter: [ :object | #ignore ]
×
1004
                        setter: [ :object :value |
×
1005
                        object user: (self importUser: (value at: #id)) ].
×
1006

×
1007
                mapping
×
1008
                        mapProperty: #commit
×
1009
                        getter: [ :object | #ignore ]
×
1010
                        setter: [ :object :value |
×
1011
                                value ifNotNil: [
×
1012
                                        object commit:
×
1013
                                                (self importCommit: (value at: #id) ofProject: aProject) ] ].
×
1014

×
1015
                mapping
×
1016
                        mapProperty: #duration
×
1017
                        getter: [ :object | #ignore ]
×
1018
                        setter: [ :object :value |
×
1019
                        value ifNotNil: [ object duration: value seconds ] ] ].
×
1020

×
1021
        reader
×
1022
                for: #ArrayOfGLHJob
×
1023
                customDo: [ :customMappting |
×
1024
                customMappting listOfElementSchema: GLHJob ].
×
1025
        ^ reader nextAs: #ArrayOfGLHJob
×
1026
]
×
1027

1028
{ #category : #private }
1029
GLHModelImporter >> parsePipelinesResult: result [
1✔
1030

1✔
1031
        | reader |
1✔
1032
        reader := NeoJSONReader on: result readStream.
1✔
1033
        reader mapInstVarsFor: GLHPipeline.
1✔
1034
        reader for: GLHPipeline do: [ :mapping |
1✔
1035
                mapping
1✔
1036
                        mapProperty: #created_at
1✔
1037
                        getter: [ :object | #ignore ]
1✔
1038
                        setter: [ :object :value |
1✔
1039
                        object runDate: (DateAndTime fromString: value) ] ].
1✔
1040
        reader
1✔
1041
                for: #ArrayOfPipelines
1✔
1042
                customDo: [ :customMappting |
1✔
1043
                customMappting listOfElementSchema: GLHPipeline ].
1✔
1044
        ^ reader nextAs: #ArrayOfPipelines
1✔
1045
]
1✔
1046

1047
{ #category : #private }
1048
GLHModelImporter >> parseSubGroupResult: aResult [
1✔
1049

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

1056
{ #category : #private }
1057
GLHModelImporter >> parseUserResult: result [
1✔
1058

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

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

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

1074
{ #category : #'as yet unclassified' }
1075
GLHModelImporter >> selectEntityType: aType overAttribut: aSelector equalTo: value [
×
1076

×
1077
        ^ (self glhModel allWithType: aType)
×
1078
                select: [ :entity | (entity perform: aSelector) = value ]
×
1079
]
×
1080

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

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

1099
{ #category : #accessing }
1100
GLHModelImporter >> withCommitDiffs [
1✔
1101

1✔
1102
        ^ withCommitDiffs
1✔
1103
]
1✔
1104

1105
{ #category : #accessing }
1106
GLHModelImporter >> withCommitDiffs: anObject [
1✔
1107

1✔
1108
        withCommitDiffs := anObject
1✔
1109
]
1✔
1110

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

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

1121
{ #category : #accessing }
1122
GLHModelImporter >> withInitialCommits: boolean [
×
1123
        withInitialCommits := boolean 
×
1124
]
×
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