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

moosetechnology / GitProjectHealth / 12991409019

27 Jan 2025 02:38PM UTC coverage: 61.269% (+2.1%) from 59.199%
12991409019

push

github

web-flow
Merge pull request #114 from moosetechnology/refactor-change-glhapi-for-gitlab-pharo-api

refactor: replace GLHApi and GLPHApi with Gitlab Pharo API

260 of 476 new or added lines in 15 files covered. (54.62%)

25 existing lines in 3 files now uncovered.

9528 of 15551 relevant lines covered (61.27%)

0.61 hits per line

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

45.81
/src/GitLabHealth-Model-Importer/GLHModelImporter.class.st
1
Class {
2
        #name : #GLHModelImporter,
3
        #superclass : #GPModelImporter,
4
        #instVars : [
5
                'withInitialCommits',
6
                'withInitialMergeRequest',
7
                'generalReader'
8
        ],
9
        #category : #'GitLabHealth-Model-Importer'
10
}
11

12
{ #category : #private }
13
GLHModelImporter >> addCommits: commitsList toRepository: aProjectRepository [
×
14
        "I take a list of GLHCommit. But some might have been parsed but are already on the model..."
×
15

×
16
        "I return the list of added commits"
×
17

×
18
        | existingCommits newlyFoundCommit |
×
19
        existingCommits := aProjectRepository mooseModel allWithType:
×
20
                                   GLHCommit.
×
21
        newlyFoundCommit := commitsList reject: [ :commitParsed |
×
22
                                    existingCommits anySatisfy: [ :existingCommit |
×
23
                                            existingCommit id = commitParsed id ] ].
×
24
        aProjectRepository mooseModel addAll: newlyFoundCommit.
×
25
        aProjectRepository commits addAll: newlyFoundCommit.
×
26
        ^ newlyFoundCommit
×
27
]
×
28

29
{ #category : #private }
30
GLHModelImporter >> addGroupResultToModel: groupResult [
1✔
31
        |group|
1✔
32
        group := self glhModel add: groupResult unless: self blockOnIdEquality.
1✔
33
        self glhModel
1✔
34
                addAll: group projects
1✔
35
                unless: self blockOnIdEquality.
1✔
36
        ^ group 
1✔
37
]
1✔
38

39
{ #category : #private }
40
GLHModelImporter >> chainsCommitsFrom: commitsCollection [
1✔
41

1✔
42
        | dic |
1✔
43
        
1✔
44
        ('Chains ', commitsCollection size printString , ' commits') recordInfo.
1✔
45
        
1✔
46
        dic := ((self glhModel allWithType: GLHCommit) collect: [ :commit |
1✔
47
                        commit id -> commit ]) asSet asDictionary.
1✔
48

1✔
49
        commitsCollection do: [ :commit |
1✔
50
                commit parent_ids do: [ :parentId | 
1✔
51
                        dic
1✔
52
                                at: parentId
1✔
53
                                ifPresent: [ :parentCommit |
1✔
54
                                        parentCommit childCommits
1✔
55
                                                add: commit
1✔
56
                                                unless: self blockOnIdEquality ]
1✔
57
                                ifAbsent: [  ] ] ].
1✔
58
        ^ commitsCollection
1✔
59
]
1✔
60

61
{ #category : #'import -projects' }
62
GLHModelImporter >> completeImportProject: aGLHProject [
1✔
63

1✔
64
        | importedProject |
1✔
65
        ('Complete import of project: ' , aGLHProject id printString)
1✔
66
                recordInfo.
1✔
67
        aGLHProject repository ifNotNil: [ ^ aGLHProject ].
1✔
68

1✔
69
        importedProject := self glhModel
1✔
70
                                   add: aGLHProject
1✔
71
                                   unless: self blockOnIdEquality.
1✔
72

1✔
73
        self importPipelinesOfProject: importedProject.
1✔
74

1✔
75
        "aGLHProject creator: (self importUser: aGLHProject creator_id)."
1✔
76

1✔
77
        (self importUser: importedProject creator_id) addCreatedProject:
1✔
78
                importedProject.
1✔
79

1✔
80

1✔
81
        importedProject repository: GLHRepository new.
1✔
82
        self glhModel add: importedProject repository.
1✔
83
        self importRepository: importedProject repository.
1✔
84

1✔
85
        ^ importedProject
1✔
86
]
1✔
87

88
{ #category : #'import - commits' }
89
GLHModelImporter >> completeImportedCommit: aCommit [
1✔
90

1✔
91
        ('completing commit: ' , aCommit short_id printString) recordInfo.
1✔
92
        self importCreatorOfCommit: aCommit.
1✔
93

1✔
94
        self withCommitDiffs ifTrue: [
1✔
95
                | diffs |
1✔
96
                aCommit diffs ifEmpty: [
1✔
97
                        diffs := self importDiffOfCommit: aCommit.
1✔
98
                        self glhModel addAll: diffs unless: self blockForDiffEquality ] ].
1✔
99

1✔
100
        ^ aCommit
1✔
101
]
1✔
102

103
{ #category : #'private - configure reader' }
104
GLHModelImporter >> configureReaderForCommit: reader [
1✔
105

1✔
106
          reader for: GLHCommit do: [ :mapping |
1✔
107
                mapping mapInstVars:
1✔
108
                        #( id short_id title author_name author_email committer_name
1✔
109
                           committer_email message web_url ).
1✔
110
                (mapping mapInstVar: #authored_date) valueSchema: DateAndTime.
1✔
111
                (mapping mapInstVar: #committed_date) valueSchema: DateAndTime.
1✔
112
                (mapping mapInstVar: #created_at) valueSchema: DateAndTime.
1✔
113
                (mapping mapInstVar: #parent_ids) valueSchema: #ArrayOfIds.
1✔
114
                mapping
1✔
115
                        mapProperty: 'stats'
1✔
116
                        getter: [ :el | "Not used" ]
1✔
117
                        setter: [ :commit :value |
1✔
118
                                commit deletions: (value at: #deletions).
1✔
119
                                commit additions: (value at: #additions) ] ].
1✔
120

1✔
121
        reader for: DateAndTime customDo: [ :mapping |
1✔
122
                mapping decoder: [ :string | DateAndTime fromString: string ] ].
1✔
123

1✔
124
        reader
1✔
125
                for: #ArrayOfIds
1✔
126
                customDo: [ :mapping | mapping decoder: [ :string | string ] ].
1✔
127
  
1✔
128
        reader
1✔
129
                for: #ArrayOfCommit
1✔
130
                customDo: [ :customMappting |
1✔
131
                customMappting listOfElementSchema: GLHCommit ].
1✔
132

1✔
133
]
1✔
134

135
{ #category : #'private - configure reader' }
136
GLHModelImporter >> configureReaderForDiffs: reader [
1✔
137

1✔
138
        reader for: GLHDiff do: [ :mapping |
1✔
139
                mapping mapInstVars:
1✔
140
                        #( deleted_file new_file new_path old_path renamed_file ).
1✔
141
                mapping mapInstVar: #diffString to: #diff ].
1✔
142

1✔
143
        reader
1✔
144
                for: #ArrayOfDiffs
1✔
145
                customDo: [ :customMappting |
1✔
146
                customMappting listOfElementSchema: GLHDiff ].
1✔
147
        ^ reader
1✔
148
]
1✔
149

150
{ #category : #'private - configure reader' }
151
GLHModelImporter >> configureReaderForGroup: reader [
1✔
152

1✔
153
        reader for: GLHGroup do: [ :mapping |
1✔
154
                mapping mapInstVars.
1✔
155
                (mapping mapInstVar: #projects) valueSchema: #ArrayOfProjects ].
1✔
156
        reader mapInstVarsFor: GLHProject.
1✔
157
        reader
1✔
158
                for: #ArrayOfProjects
1✔
159
                customDo: [ :customMappting |
1✔
160
                customMappting listOfElementSchema: GLHProject ].
1✔
161
        reader
1✔
162
                for: #ArrayOfGroups
1✔
163
                customDo: [ :customMappting |
1✔
164
                customMappting listOfElementSchema: GLHGroup ]
1✔
165
]
1✔
166

167
{ #category : #private }
168
GLHModelImporter >> convertApiFileAsFile: aAPIFile [
×
169

×
170
        aAPIFile type = 'tree' ifTrue: [ 
×
171
                ^ GLHFileDirectory new
×
172
                          name: aAPIFile name;
×
173
                          yourself ].
×
174
        ^ GLHFileBlob new
×
175
                  name: aAPIFile name;
×
176
                  yourself
×
177
]
×
178

179
{ #category : #private }
180
GLHModelImporter >> detectEntityType: aType overAttribut: aSelector equalTo: value [
1✔
181

1✔
182
        ^ (self glhModel allWithType: aType) detect: [ :entity |
1✔
183
                  (entity perform: aSelector) = value ] ifNone: [ nil ]. 
1✔
184
]
1✔
185

186
{ #category : #accessing }
187
GLHModelImporter >> glhApi [
×
188

×
189
        self
×
190
                deprecated: 'Use #repoApi instead'
×
191
                on: '7 October 2024'
×
192
                in:
×
193
                'Pharo-11.0.0+build.726.sha.aece1b5473acf3830a0e082c1bc3a15d4ff3522b (64 Bit)'.
×
194

×
195
        ^ repoApi
×
196
]
×
197

198
{ #category : #accessing }
199
GLHModelImporter >> glhApi: anObject [
×
200

×
201
        self
×
202
                deprecated: 'Use #repoApi: instead'
×
203
                on: '7 October 2024'
×
204
                in:
×
205
                'Pharo-11.0.0+build.726.sha.aece1b5473acf3830a0e082c1bc3a15d4ff3522b (64 Bit)'.
×
206

×
207
        repoApi := anObject
×
208
]
×
209

210
{ #category : #accessing }
211
GLHModelImporter >> glhModel [
1✔
212

1✔
213
        ^ glhModel
1✔
214
]
1✔
215

216
{ #category : #accessing }
217
GLHModelImporter >> glhModel: anObject [
1✔
218

1✔
219
        glhModel := anObject
1✔
220
]
1✔
221

222
{ #category : #'import - users' }
223
GLHModelImporter >> importActiveHumanUsers [
×
224

×
NEW
225
        | params result users |
×
NEW
226
        params := { 
×
NEW
227
                #humans -> 'true'.
×
NEW
228
                #active -> 'true'.
×
NEW
229
                #without_project_bots -> 'true'
×
NEW
230
        } asDictionary.
×
NEW
231
        result := self repoApi users allWithParams: params.
×
NEW
232
        users := (result collect: [ :usersJson | self parseUsersResult: usersJson ]) flattened.
×
NEW
233
        
×
NEW
234
        self glhModel
×
NEW
235
                                 addAll: users
×
NEW
236
                                 unless: self blockOnIdEquality.
×
237

×
NEW
238
        ^ users
×
239
]
×
240

241
{ #category : #'import - groups' }
242
GLHModelImporter >> importAllGroups [
×
243

×
NEW
244
        | params results groups |
×
NEW
245
        
×
NEW
246
        params := { 
×
NEW
247
                        #top_level_only -> 'true'
×
NEW
248
        } asDictionary.
×
NEW
249
        results := self repoApi groups getAllWithParams: params.
×
NEW
250
        
×
NEW
251
        groups := (results collect: [ :groupsJson | generalReader
×
NEW
252
                                            on: groupsJson readStream;
×
NEW
253
                                            nextAs: #ArrayOfGroups. ]) flattened.
×
NEW
254
        ^ groups
×
UNCOV
255
]
×
256

257
{ #category : #'import - commits' }
258
GLHModelImporter >> importAndLoadLatestsCommitsOfProject: aGLHProject [
×
259

×
NEW
260
        | commits completedProject |
×
NEW
261
        completedProject := self completeImportProject: aGLHProject.
×
NEW
262
        commits := self importLastestCommitsOfProject: completedProject.
×
263
        commits do: [ :commit | self completeImportedCommit: commit ].
×
264
        self chainsCommitsFrom: commits.
×
265
        ^ commits
×
266
]
×
267

268
{ #category : #'import - commits' }
269
GLHModelImporter >> importCommit: aCommitID ofProject: aGLHProject [
×
270

×
271
        | result parsedResult |
×
272
        (self glhModel allWithType: GLHCommit) asOrderedCollection
×
273
                detect: [ :commit | commit id = aCommitID ]
×
274
                ifFound: [ :commit | ^ commit ].
×
NEW
275
        result := self repoApi commits get: aCommitID inProject: aGLHProject id.
×
NEW
276
        
×
277
        parsedResult := self parseCommitResult: result.
×
NEW
278
        
×
279
        self
×
280
                addCommits: { parsedResult }
×
281
                toRepository: aGLHProject repository.
×
282
        ^ parsedResult
×
283
]
×
284

285
{ #category : #'import - commits' }
286
GLHModelImporter >> importCommitOfProject: anProject withId: anID [
1✔
287

1✔
288
        | commit result |
1✔
289
        anID ifNil: [ ^ nil ].
1✔
290

1✔
291
        ('looking for commit ' , anID printString , ' in project : '
1✔
292
         , anProject id printString) recordInfo.
1✔
293

1✔
294
        commit := (self
1✔
295
                           detectEntityType: GLHCommit
1✔
296
                           overAttribut: #id
1✔
297
                           equalTo: anID) ifNil: [
1✔
298
                          result := self repoApi commits get: anID inProject: anProject id.
1✔
299
                          commit := (self parseCommitsResult: '[' , result , ']')
1✔
300
                                            first.
1✔
301

1✔
302
                          self glhModel add: commit unless: self blockOnIdEquality.
1✔
303
                          commit repository: anProject repository.
1✔
304

1✔
305
                          commit ].
1✔
306

1✔
307
        self withCommitDiffs ifTrue: [ self importDiffOfCommit: commit ].
1✔
308

1✔
309
        ^ commit
1✔
310
]
1✔
311

312
{ #category : #'import - commits' }
313
GLHModelImporter >> importCommits: aGLHProject [
×
314
        "limited to the last 20 commits"
×
315

×
NEW
316
        | results parsedResults params |
×
NEW
317
        params := { 
×
NEW
318
         #with_stats -> 'true'
×
NEW
319
        } asDictionary.
×
NEW
320
        results := self repoApi commits getByPage: 1 perPage: 20 inProject: aGLHProject id withParams: params.
×
NEW
321
        
×
322
        parsedResults := self parseCommitsResult: results.
×
323
        self glhModel addAll: parsedResults unless: self blockOnIdEquality.
×
324

×
325
        parsedResults do: [ :commit |
×
326
                commit repository: aGLHProject repository ].
×
327

×
328
        self withCommitDiffs ifTrue: [
×
329
                parsedResults do: [ :commit | self importDiffOfCommit: commit ] ].
×
330
        
×
331
        ^ parsedResults. 
×
332
]
×
333

334
{ #category : #'import - commits' }
335
GLHModelImporter >> importCommitsFollowing: aCommit upToDays: aNumberOfDay [
×
336
        "import the 'n' commits of a project starting from an initial 'aCommit' commit. 
×
337
        Lazy import does not import the entities inside the model"
×
338

×
339
        | date |
×
340
        date := aCommit created_at asDateAndTime.
×
341

×
342
        ^ self
×
343
                  importCommitsOfBranch: aCommit branch
×
344
                  forRefName: aCommit branch name
×
345
                  since: date
×
346
                  until: (date + aNumberOfDay day)
×
347
]
×
348

349
{ #category : #'import - commits' }
350
GLHModelImporter >> importCommitsOfBranch: aGLHBranch forRefName: refName since: fromDate [
×
351

×
352
        ^ self
×
353
                  importCommitsOfBranch: aGLHBranch
×
354
                  forRefName: aGLHBranch name
×
355
                  since: fromDate
×
356
                  until: nil
×
357
]
×
358

359
{ #category : #'import - commits' }
360
GLHModelImporter >> importCommitsOfBranch: aGLHBranch forRefName: refName since: fromDate until: toDate [
×
361

×
NEW
362
        | params result allCommits |
×
NEW
363
        params := { 
×
NEW
364
          #ref_name -> aGLHBranch name.
×
NEW
365
          #since ->  (fromDate ifNotNil: [ fromDate asDateAndTime asString ] ifNil: [ '' ]).
×
NEW
366
          #until -> (toDate ifNotNil: [ toDate asDateAndTime asString ] ifNil: [ '' ]). 
×
NEW
367
        } asDictionary.
×
NEW
368
        result := self repoApi commits getAllInProject: aGLHBranch repository project id withParams: params.
×
NEW
369
        
×
NEW
370
        allCommits := (result collect: [ :commitsJson | self parseCommitsResult: commitsJson ]) flattened.
×
NEW
371
        
×
372
        aGLHBranch commits
×
NEW
373
                        addAll: allCommits
×
374
                        unless: self blockOnIdEquality.
×
375

×
376
        self glhModel
×
377
                addAll: aGLHBranch commits
×
378
                unless: self blockOnIdEquality.
×
379

×
NEW
380
        ^ allCommits
×
381
]
×
382

383
{ #category : #'import - commits' }
384
GLHModelImporter >> importCommitsOfBranch: aGLHBranch forRefName: refName until: toDate [
×
385

×
386
        ^ self
×
387
                  importCommitsOfBranch: aGLHBranch
×
388
                  forRefName: aGLHBranch name
×
389
                  since: nil
×
390
                  until: toDate
×
391
]
×
392

393
{ #category : #'import - commits' }
394
GLHModelImporter >> importCommitsOfProject: aProject since: fromDate until: toDate [
1✔
395

1✔
396
        | params results allCommits |
1✔
397
        params := {
1✔
398
                          (#since
1✔
399
                           ->
1✔
400
                           (fromDate
1✔
401
                                    ifNotNil: [ fromDate asDateAndTime asString ]
1✔
402
                                    ifNil: [ '' ])).
1✔
403
                          (#until
1✔
404
                           ->
1✔
405
                           (toDate
1✔
406
                                    ifNotNil: [ toDate asDateAndTime asString ]
1✔
407
                                    ifNil: [ '' ])).
1✔
408
                          (#with_stats -> 'true').
1✔
409
                          (#all -> 'true') } asDictionary.
1✔
410
        results := self repoApi commits
1✔
411
                           getAllInProject: aProject id
1✔
412
                           withParams: params.
1✔
413

1✔
414
        allCommits := (results collect: [ :commitsJson |
1✔
415
                               self parseCommitsResult: commitsJson ]) flattened.
1✔
416

1✔
417
        allCommits:= aProject repository commits
1✔
418
                addAll: allCommits
1✔
419
                unless: self blockOnIdEquality.
1✔
420

1✔
421
        ^ self glhModel addAll: allCommits unless: self blockOnIdEquality
1✔
422
]
1✔
423

424
{ #category : #'import -projects' }
425
GLHModelImporter >> importContributedProjectsOfUser: aGLHUser [
×
426

×
NEW
427
        | remaningProjects params results projects |
×
NEW
428
        params := {
×
NEW
429
                          (#order_by -> 'last_activity_at').
×
NEW
430
                          (#simple -> 'true') } asDictionary.
×
NEW
431
        results := self repoApi projects
×
NEW
432
                           contributedProjectsOfUser: aGLHUser id
×
NEW
433
                           withParams: params.
×
NEW
434

×
NEW
435
        projects := (results collect: [ :projectsJson |
×
NEW
436
                             self parseArrayOfProject: projectsJson ]) flattened.
×
NEW
437
        projects := self glhModel
×
NEW
438
                            addAll: projects
×
NEW
439
                            unless: self blockOnIdEquality.
×
NEW
440

×
441
        remaningProjects := self importProjects:
×
NEW
442
                                    ((projects collect: #id) difference:
×
443
                                             ((self userCatalogue atId: aGLHUser id) at:
×
444
                                                      #contributedProjects)).
×
445

×
NEW
446

×
447
        aGLHUser contributedProjects
×
NEW
448
                addAll: projects , remaningProjects
×
449
                unless: self blockOnIdEquality.
×
450

×
451
        self userCatalogue
×
452
                addUser: aGLHUser
×
453
                withProjects: (aGLHUser contributedProjects collect: #id).
×
454

×
NEW
455
        ^ projects
×
456
]
×
457

458
{ #category : #'import - commits' }
459
GLHModelImporter >> importCreatorOfCommit: aCommit [
1✔
460

1✔
461
        aCommit commitCreator ifNil: [
1✔
462
                aCommit commitCreator:
1✔
463
                        (self importUserByUsername: aCommit author_name) ].
1✔
464
        self userCatalogue
1✔
465
                addUser: aCommit commitCreator
1✔
466
                withProject: aCommit repository project id.
1✔
467
        ^ aCommit commitCreator
1✔
468
]
1✔
469

470
{ #category : #'import - commits' }
471
GLHModelImporter >> importDiffOfCommit: aCommit [
1✔
472

1✔
473
        | result diffsResult |
1✔
474
        aCommit diffs ifNotEmpty: [
1✔
475
                'Diff already importer: ' , aCommit short_id printString recordInfo.
1✔
476
                ^ aCommit diffs ].
1✔
477
        ('Import diff of commit: ' , aCommit short_id printString) recordInfo.
1✔
478
        
1✔
479
        result := self repoApi commits diffOf: aCommit id inProject: aCommit repository project id  uniDiff: true.
1✔
480
        
1✔
481
        (self isServerError: result) ifTrue: [ ^ {  } ].
1✔
482
        diffsResult := self newParseDiffResult: result.
1✔
483

1✔
484
        ^ aCommit diffs addAll: diffsResult unless: self blockForDiffEquality.
1✔
485

1✔
486
]
1✔
487

488
{ #category : #'import - repositories' }
489
GLHModelImporter >> importDirectoryFiles: aDirectoryFile OfBranch: aBranch [
×
490

×
NEW
491
        | result files apiFiles params |
×
NEW
492
        params := { 
×
NEW
493
                #ref -> aBranch name.
×
NEW
494
                #path -> (aDirectoryFile path , '/')
×
NEW
495
        } asDictionary.
×
NEW
496
        result := self repoApi repositories repositoryTreeOfProject: aBranch repository project id withParams: params.
×
NEW
497
                         " treeOfRepository: aBranch repository project id
×
498
                          ofBranch: aBranch name
×
NEW
499
                          andPath: aDirectoryFile path , '/'."
×
NEW
500
        apiFiles := (result collect: [ :treeJson | self parseFileTreeResult: treeJson ]) flattened.
×
501
        files := apiFiles collect: [ :apiFile |
×
502
                         self convertApiFileAsFile: apiFile ].
×
NEW
503
        
×
504
        files do: [ :file |
×
505
                self glhModel add: file.
×
506
                aDirectoryFile addFile: file ].
×
NEW
507
        
×
508
        files
×
509
                select: [ :file | file isKindOf: GLHFileDirectory ]
×
510
                thenCollect: [ :file |
×
511
                self importDirectoryFiles: file OfBranch: aBranch ]
×
512
]
×
513

514
{ #category : #'import - repositories' }
515
GLHModelImporter >> importFilesOfBranch: aBranch [
×
516

×
NEW
517
        | result files apiFiles params |
×
NEW
518
        params := { 
×
NEW
519
                #ref -> aBranch name.
×
NEW
520
        } asDictionary.
×
NEW
521
        
×
NEW
522
        result := self repoApi repositories repositoryTreeOfProject: aBranch repository project id withParams: params.
×
NEW
523
        
×
NEW
524
                          "treeOfRepository: aBranch repository project id
×
525
                          ofBranch: aBranch name
×
NEW
526
                          andPath: nil."
×
NEW
527
        apiFiles := (result collect: [ :filesJson | self parseFileTreeResult: filesJson  ]) flattened.
×
528
        files := apiFiles collect: [ :apiFile | 
×
529
                         self convertApiFileAsFile: apiFile ].
×
530
        files do: [ :file | 
×
531
                self glhModel add: file.
×
532
                aBranch addFile: file ].
×
533
        files
×
534
                select: [ :file | file isKindOf: GLHFileDirectory ]
×
535
                thenCollect: [ :file | 
×
536
                self importDirectoryFiles: file OfBranch: aBranch ]
×
537
]
×
538

539
{ #category : #'import - groups' }
540
GLHModelImporter >> importGroup: aGroupID [
1✔
541

1✔
542
        | result groupResult |
1✔
543
        ('Import group: ' , aGroupID printString) recordInfo.
1✔
544

1✔
545
        result := self repoApi groups get: aGroupID.
1✔
546
        
1✔
547
        "group: aGroupID."
1✔
548
        groupResult := self parseGroupResult: result.
1✔
549
        groupResult := self addGroupResultToModel: groupResult.
1✔
550

1✔
551
        groupResult projects do: [ :project |
1✔
552
                self completeImportProject: project ].
1✔
553

1✔
554
        (self subGroupsOf: aGroupID) do: [ :subGroup |
1✔
555
                
1✔
556
                groupResult subGroups
1✔
557
                        add: (self importGroup: subGroup id)
1✔
558
                        unless: self blockOnIdEquality ].
1✔
559
        ^ groupResult
1✔
560
]
1✔
561

562
{ #category : #'import - jobs' }
563
GLHModelImporter >> importJobsOf: aPipeline [
×
564

×
NEW
565
        | jobs results |
×
NEW
566
        results := self repoApi jobs allForPipeline: aPipeline id inProject: aPipeline project id.
×
NEW
567
                          "jobsOfProject: aPipeline project id
×
NEW
568
                          ofPipelines: aPipeline id."
×
NEW
569
        jobs := (results collect: [ :jobsJson | self parseJobsResult: jobsJson ofProject: aPipeline project ]) flattened.
×
570
        jobs do: [ :job | aPipeline addJob: job ].
×
NEW
571
        self glhModel addAll: jobs.
×
NEW
572
        
×
NEW
573
        ^jobs
×
574

×
575
]
×
576

577
{ #category : #'import - commits' }
578
GLHModelImporter >> importLastestCommitsOfProject: aGLHProject [
1✔
579
        "limited to the last 50 commits"
1✔
580

1✔
581
        | results parsedResults params |
1✔
582
        params := { 
1✔
583
                #with_stats -> 'true'.
1✔
584
                #all -> true
1✔
585
         } asDictionary.
1✔
586
        results := self repoApi commits getByPage: 1 perPage: 50 inProject: aGLHProject id withParams: params.
1✔
587

1✔
588
        parsedResults := self parseCommitsResult: results.
1✔
589
        parsedResults := self glhModel
1✔
590
                                 addAll: parsedResults
1✔
591
                                 unless: self blockOnIdEquality.
1✔
592

1✔
593
        aGLHProject repository commits
1✔
594
                addAll: parsedResults
1✔
595
                unless: self blockOnIdEquality.
1✔
596

1✔
597
        self withCommitDiffs ifTrue: [
1✔
598
                parsedResults do: [ :commit | self importDiffOfCommit: commit ] ].
1✔
599

1✔
600
        ^ parsedResults
1✔
601
]
1✔
602

603
{ #category : #'import - commits' }
604
GLHModelImporter >> importParentCommitsOfCommit: aGLHCommit since: aDate [
×
605

×
606
        | parentsIds commits |
×
607
        commits := OrderedCollection new.
×
608
        aGLHCommit created_at asDateAndTime < aDate asDateAndTime ifTrue: [
×
609
                 
×
610
                ^ commits
×
611
                          add: aGLHCommit;
×
612
                          yourself ].
×
613

×
614
        parentsIds := aGLHCommit parent_ids.
×
615

×
616
        commits addAll: (parentsIds collect: [ :id |
×
617
                         self
×
618
                                 importCommitOfProject: aGLHCommit repository project
×
619
                                 withId: id ]).
×
620

×
621

×
622
        ^ (commits collect: [ :parentCommit |
×
623
                   self importParentCommitsOfCommit: parentCommit since: aDate ])
×
624
                  flatten
×
625
]
×
626

627
{ #category : #'imports - pipelines' }
628
GLHModelImporter >> importPipelinesOfProject: aGLHProject [
1✔
629

1✔
630
        (self pipelinesOf: aGLHProject id) do: [ :pipeline |
1✔
631
                self glhModel add: pipeline unless: self blockOnIdEquality .
1✔
632
                aGLHProject pipelines add: pipeline unless: self blockOnIdEquality]
1✔
633
]
1✔
634

635
{ #category : #'import -projects' }
636
GLHModelImporter >> importProject: aProjectID [
×
637

×
638
        | result projectResult |
×
639
        ('Import project with id: ' , aProjectID printString) recordInfo.
×
640

×
NEW
641
        result := self repoApi projects get: aProjectID.
×
642
        projectResult := self parseProjectResult: result.
×
643

×
644
        ^ self completeImportProject: projectResult
×
645
]
×
646

647
{ #category : #'import -projects' }
648
GLHModelImporter >> importProjects [
×
649

×
NEW
650
        | result projects |
×
NEW
651
        ('import all Projects') recordInfo.
×
UNCOV
652

×
NEW
653
        result := self repoApi projects all.
×
NEW
654
        projects := (result collect: [ :projectsJson | self parseArrayOfProject: projectsJson ]) flattened.
×
NEW
655
        
×
NEW
656
        self glhModel addAll: projects unless: self blockOnIdEquality.
×
657

×
NEW
658
        ^ projects
×
659
]
×
660

661
{ #category : #'import -projects' }
NEW
662
GLHModelImporter >> importProjects: aCollectionOfProjectID [
×
663

×
NEW
664
        ^ aCollectionOfProjectID collect: [ :id | self importProject: id ]
×
665
]
×
666

667
{ #category : #'import - repositories' }
668
GLHModelImporter >> importRepository: aGLHRepository [
1✔
669

1✔
670
        | resultBranches branches |
1✔
671
        [
1✔
672
        ('import the repository of project ' , aGLHRepository project name)
1✔
673
                recordInfo.
1✔
674

1✔
675
        resultBranches := self repoApi branches getAllFromProject: aGLHRepository project id.
1✔
676
        
1✔
677
        branches := (resultBranches collect: [ :branchesJson | self parseBranchesResult: branchesJson ]) flattened.
1✔
678

1✔
679
        'import the branches of project ' recordInfo.
1✔
680

1✔
681
        branches := aGLHRepository branches
1✔
682
                            addAll: branches
1✔
683
                            unless: self blockOnNameEquality.
1✔
684
        branches := self glhModel
1✔
685
                            addAll: branches
1✔
686
                            unless: self blockOnNameEquality.
1✔
687

1✔
688

1✔
689
        self withFiles ifTrue: [
1✔
690
                branches do: [ :branch | self importFilesOfBranch: branch ] ] ]
1✔
691
                on: NeoJSONParseError
1✔
692
                do: [
1✔
693
                self inform: aGLHRepository project name , ' has no repository' ]
1✔
694
]
1✔
695

696
{ #category : #'import - users' }
697
GLHModelImporter >> importUser: aUserID [
1✔
698

1✔
699
        | result userResult |
1✔
700
        (self glhModel allWithType: GLHUser)
1✔
701
                detect: [ :user | user id = aUserID ]
1✔
702
                ifFound: [ :user | ^ user ].
1✔
703
        ('Import user: ' , aUserID printString) recordInfo.
1✔
704
        
1✔
705
        result := self repoApi users get: aUserID.
1✔
706
        userResult := self parseUserResult: result.
1✔
707
        
1✔
708
        ^ self glhModel add: userResult unless: self blockOnIdEquality
1✔
709
]
1✔
710

711
{ #category : #'import - users' }
712
GLHModelImporter >> importUserByUsername: anUsername [
1✔
713

1✔
714
        | dicUsername resultUser |
1✔
715
        dicUsername := ((self glhModel allWithType: GLHUser) collect: [ :user |
1✔
716
                                user username -> user ]) asSet asDictionary.
1✔
717

1✔
718
        dicUsername addAll: self userCatalogue collectUsernames.
1✔
719

1✔
720

1✔
721
        resultUser := dicUsername
1✔
722
                              at: anUsername
1✔
723
                              ifAbsent: [ "thus we have to import this new user"
1✔
724
                                      | result userId searchResult params |
1✔
725
                                      ('Import user with username: '
1✔
726
                                       , anUsername printString) recordInfo.
1✔
727
                                      params := { (#search -> anUsername) } asDictionary.
1✔
728
                                      result := self repoApi users allWithParams: params.
1✔
729
                                                        
1✔
730
                                                         "when result is an error"
1✔
731
                                                         (result isString) ifTrue: [ result := { result } ].
1✔
732
                                                        
1✔
733
                                      searchResult := result ifEmpty: [ result ] ifNotEmpty: [(result collect: [ :usersJson |
1✔
734
                                                               NeoJSONReader fromString: usersJson ]) first].
1✔
735
                                                         
1✔
736
                                      (searchResult class = Dictionary and: [
1✔
737
                                               (searchResult at: #message) includesSubstring:
1✔
738
                                                       '403 Forbidden' ])
1✔
739
                                              ifTrue: [ "if the result is an 403 error we fake a new user"
1✔
740
                                                      self glhModel
1✔
741
                                                              add: (GLHUser new
1✔
742
                                                                               username: anUsername;
1✔
743
                                                                               name: anUsername;
1✔
744
                                                                               yourself)
1✔
745
                                                              unless: [ :nu :ou | nu username = ou username ] ]
1✔
746
                                              ifFalse: [
1✔
747
                                                      searchResult
1✔
748
                                                              ifEmpty: [ "results can be empty thus we force a new user with the info we have "
1✔
749
                                                                      self glhModel
1✔
750
                                                                              add: (GLHUser new
1✔
751
                                                                                               username: anUsername;
1✔
752
                                                                                               name: anUsername;
1✔
753
                                                                                               yourself)
1✔
754
                                                                              unless: [ :nu :ou | nu username = ou username ] ]
1✔
755
                                                              ifNotEmpty: [ "because we may already have the researched user, we look by ID in the model"
1✔
756
                                                                      userId := searchResult first at: #id.
1✔
757
                                                                      (self glhModel allWithType: GLHUser)
1✔
758
                                                                              detect: [ :user | user id = userId ]
1✔
759
                                                                              ifNone: [ self importUser: userId ] ] ] ].
1✔
760

1✔
761
        self userCatalogue addUser: resultUser withName: anUsername.
1✔
762

1✔
763
        ^ resultUser
1✔
764
]
1✔
765

766
{ #category : #initialization }
767
GLHModelImporter >> initReader [
1✔
768

1✔
769
        generalReader := NeoJSONReader new.
1✔
770
        self configureReaderForCommit: generalReader.
1✔
771
        self configureReaderForGroup: generalReader.
1✔
772
        self configureReaderForDiffs: generalReader. 
1✔
773
]
1✔
774

775
{ #category : #initialization }
776
GLHModelImporter >> initialize [
1✔
777

1✔
778
        super initialize.
1✔
779
        withCommitDiffs := false.
1✔
780
        withInitialCommits := false.
1✔
781
        withInitialMergeRequest := false.
1✔
782

1✔
783
        withCommitsSince := (Date today - 1 week) asDateAndTime.
1✔
784

1✔
785
        self initReader.
1✔
786

1✔
787
]
1✔
788

789
{ #category : #private }
790
GLHModelImporter >> isServerError: aString [
1✔
791
        ^ aString = '{"message":"500 Internal Server Error"}'
1✔
792
]
1✔
793

794
{ #category : #'import -projects' }
795
GLHModelImporter >> loadAllProjectsFromRepositorySoftware [
×
796
        "heavy import that load all the active project inside the model. Only import the project entities"
×
797
        |projects|
×
798
        
×
799
        projects := self repoApi projects. 
×
800
]
×
801

802
{ #category : #'private - parsing' }
803
GLHModelImporter >> newParseCommitResult: result [
×
804

×
805
        generalReader  on: result readStream.
×
806

×
807
        ^ generalReader nextAs: GLHCommit
×
808
]
×
809

810
{ #category : #'private - parsing' }
811
GLHModelImporter >> newParseDiffResult: result [
1✔
812

1✔
813
        generalReader on: result readStream.
1✔
814
        ^ generalReader nextAs: #ArrayOfDiffs
1✔
815
]
1✔
816

817
{ #category : #'private - parsing' }
818
GLHModelImporter >> parseArrayOfProject: arrayOfProjects [
×
819

×
820
        | reader |
×
821
        reader := NeoJSONReader on: arrayOfProjects readStream.
×
822
        reader
×
823
                for: #ArrayOfProjects
×
824
                customDo: [ :customMappting |
×
825
                customMappting listOfElementSchema: GLHProject ].
×
826
        reader for: GLHProject do: [ :mapping |
×
827
                mapping mapInstVar: #name to: #name.
×
828
                mapping mapInstVar: #description to: #description.
×
829
                mapping mapInstVar: #id to: #id.
×
830
                mapping mapInstVar: #archived to: #archived.
×
831
                mapping mapInstVar: #web_url to: #html_url.
×
832
                mapping mapInstVar: #topics to: #topics ].
×
833
        ^ reader nextAs: #ArrayOfProjects
×
834
]
×
835

836
{ #category : #'private - parsing' }
837
GLHModelImporter >> parseBranchesResult: result [
1✔
838

1✔
839
        | reader |
1✔
840
        reader := NeoJSONReader on: result readStream.
1✔
841
        reader mapInstVarsFor: GLHBranch.
1✔
842
        reader
1✔
843
                for: #ArrayOfBranch
1✔
844
                customDo: [ :customMappting | 
1✔
845
                customMappting listOfElementSchema: GLHBranch ].
1✔
846
        ^ reader nextAs: #ArrayOfBranch
1✔
847
]
1✔
848

849
{ #category : #'private - parsing' }
850
GLHModelImporter >> parseCommitResult: result [
×
851

×
852
        | reader |
×
853
        reader := NeoJSONReader on: result readStream.
×
854

×
855
        reader for: GLHCommit do: [ :mapping |
×
856
                mapping mapInstVars:
×
857
                        #( id short_id title author_name author_email committer_name
×
858
                           committer_email message web_url ).
×
859
                (mapping mapInstVar: #authored_date) valueSchema: DateAndTime.
×
860
                (mapping mapInstVar: #committed_date) valueSchema: DateAndTime.
×
861
                (mapping mapInstVar: #created_at) valueSchema: DateAndTime.
×
862
                (mapping mapInstVar: #parent_ids) valueSchema: #ArrayOfIds.
×
863
                mapping
×
864
                        mapProperty: 'stats'
×
865
                        getter: [ :el | "Not used" ]
×
866
                        setter: [ :commit :value |
×
867
                                commit deletions: (value at: #deletions).
×
868
                                commit additions: (value at: #additions) ] ].
×
869

×
870
        reader for: DateAndTime customDo: [ :mapping |
×
871
                mapping decoder: [ :string | DateAndTime fromString: string ] ].
×
872

×
873
        reader
×
874
                for: #ArrayOfIds
×
875
                customDo: [ :mapping | mapping decoder: [ :string | string ] ].
×
876

×
877

×
878
        ^ reader nextAs: GLHCommit
×
879
]
×
880

881
{ #category : #'private - parsing' }
882
GLHModelImporter >> parseCommitsResult: result [
1✔
883

1✔
884
        | reader |
1✔
885
        reader := NeoJSONReader on: result readStream.
1✔
886

1✔
887
          reader for: GLHCommit do: [ :mapping |
1✔
888
                mapping mapInstVars:
1✔
889
                        #( id short_id title author_name author_email committer_name
1✔
890
                           committer_email message web_url ).
1✔
891
                (mapping mapInstVar: #authored_date) valueSchema: DateAndTime.
1✔
892
                (mapping mapInstVar: #committed_date) valueSchema: DateAndTime.
1✔
893
                (mapping mapInstVar: #created_at) valueSchema: DateAndTime.
1✔
894
                (mapping mapInstVar: #parent_ids) valueSchema: #ArrayOfIds.
1✔
895
                mapping
1✔
896
                        mapProperty: 'stats'
1✔
897
                        getter: [ :el | "Not used" ]
1✔
898
                        setter: [ :commit :value |
1✔
899
                                commit deletions: (value at: #deletions).
1✔
900
                                commit additions: (value at: #additions) ] ].
1✔
901

1✔
902
        reader for: DateAndTime customDo: [ :mapping |
1✔
903
                mapping decoder: [ :string | DateAndTime fromString: string ] ].
1✔
904

1✔
905
        reader
1✔
906
                for: #ArrayOfIds
1✔
907
                customDo: [ :mapping | mapping decoder: [ :string | string ] ].
1✔
908
  
1✔
909
        reader
1✔
910
                for: #ArrayOfCommit
1✔
911
                customDo: [ :customMappting |
1✔
912
                customMappting listOfElementSchema: GLHCommit ].
1✔
913

1✔
914
        ^ reader nextAs: #ArrayOfCommit
1✔
915
]
1✔
916

917
{ #category : #private }
918
GLHModelImporter >> parseDiffResult: result [
×
919

×
920
        | reader |
×
921
        self
×
922
                deprecated: 'Use #newParseDiffResult: instead'
×
923
                on: '28 June 2024'
×
924
                in:
×
925
                'Pharo-11.0.0+build.726.sha.aece1b5473acf3830a0e082c1bc3a15d4ff3522b (64 Bit)'.
×
926
        reader := NeoJSONReader on: result readStream.
×
927
        reader for: GLHDiff do: [ :mapping |
×
928
                mapping mapInstVars:
×
929
                        #( deleted_file new_file new_path old_path renamed_file ).
×
930
                mapping mapInstVar: #diffString to: #diff ].
×
931

×
932
        reader
×
933
                for: #ArrayOfDiffs
×
934
                customDo: [ :customMappting |
×
935
                customMappting listOfElementSchema: GLHDiff ].
×
936
        ^ reader nextAs: #ArrayOfDiffs
×
937
]
×
938

939
{ #category : #'private - parsing' }
940
GLHModelImporter >> parseFileTreeResult: aResult [
×
941

×
942
        | reader |
×
943
        reader := NeoJSONReader on: aResult readStream.
×
944
        reader mapInstVarsFor: GLHApiFile.
×
945
        reader
×
946
                for: #ArrayOfFile
×
947
                customDo: [ :customMappting | 
×
948
                customMappting listOfElementSchema: GLHApiFile ].
×
949
        ^ reader nextAs: #ArrayOfFile
×
950
]
×
951

952
{ #category : #'private - parsing' }
953
GLHModelImporter >> parseGroupResult: aResult [
1✔
954

1✔
955
        | reader |
1✔
956

1✔
957
        reader := NeoJSONReader on: aResult readStream.
1✔
958
        reader for: GLHGroup do: [ :mapping |
1✔
959
                mapping mapInstVars.
1✔
960
                (mapping mapInstVar: #projects) valueSchema: #ArrayOfProjects ].
1✔
961
        reader mapInstVarsFor: GLHProject.
1✔
962
        reader
1✔
963
                for: #ArrayOfProjects
1✔
964
                customDo: [ :customMappting |
1✔
965
                customMappting listOfElementSchema: GLHProject ].
1✔
966
        ^ reader nextAs: GLHGroup
1✔
967
]
1✔
968

969
{ #category : #'private - parsing' }
970
GLHModelImporter >> parseJobsResult: result ofProject: aProject [
×
971

×
972
        | reader |
×
973
        reader := NeoJSONReader on: result readStream.
×
974
        reader for: GLHJob do: [ :mapping |
×
975
                mapping mapInstVars: #( id allow_failure web_url name ).
×
976

×
977
                mapping
×
978
                        mapProperty: #user
×
979
                        getter: [ :object | #ignore ]
×
980
                        setter: [ :object :value |
×
981
                        object user: (self importUser: (value at: #id)) ].
×
982

×
983
                mapping
×
984
                        mapProperty: #commit
×
985
                        getter: [ :object | #ignore ]
×
986
                        setter: [ :object :value |
×
987
                                value ifNotNil: [
×
988
                                        object commit:
×
989
                                                (self importCommit: (value at: #id) ofProject: aProject) ] ].
×
990

×
991
                mapping
×
992
                        mapProperty: #duration
×
993
                        getter: [ :object | #ignore ]
×
994
                        setter: [ :object :value |
×
995
                        value ifNotNil: [ object duration: value seconds ] ] ].
×
996

×
997
        reader
×
998
                for: #ArrayOfGLHJob
×
999
                customDo: [ :customMappting |
×
1000
                customMappting listOfElementSchema: GLHJob ].
×
1001
        ^ reader nextAs: #ArrayOfGLHJob
×
1002
]
×
1003

1004
{ #category : #'private - parsing' }
UNCOV
1005
GLHModelImporter >> parsePipelinesResult: result [
×
UNCOV
1006

×
UNCOV
1007
        | reader |
×
UNCOV
1008
        
×
UNCOV
1009
        (result includesSubstring: '{"message":"40' )ifTrue: [ ^ {  } ].
×
UNCOV
1010
        
×
UNCOV
1011
        reader := NeoJSONReader on: result readStream.
×
UNCOV
1012
        reader mapInstVarsFor: GLHPipeline.
×
UNCOV
1013
        reader for: GLHPipeline do: [ :mapping |
×
UNCOV
1014
                mapping
×
UNCOV
1015
                        mapProperty: #created_at
×
UNCOV
1016
                        getter: [ :object | #ignore ]
×
UNCOV
1017
                        setter: [ :object :value |
×
UNCOV
1018
                        object runDate: (DateAndTime fromString: value) ] ].
×
UNCOV
1019
        reader
×
UNCOV
1020
                for: #ArrayOfPipelines
×
UNCOV
1021
                customDo: [ :customMappting |
×
UNCOV
1022
                customMappting listOfElementSchema: GLHPipeline ].
×
UNCOV
1023
        ^ reader nextAs: #ArrayOfPipelines
×
UNCOV
1024
]
×
1025

1026
{ #category : #'private - parsing' }
1027
GLHModelImporter >> parseProjectResult: aResult [ 
×
1028
                | reader |
×
1029
        reader := NeoJSONReader on: aResult readStream.
×
1030
        reader for: GLHProject do: [ :mapping |
×
1031
                mapping mapInstVars. ].
×
1032
"        reader mapInstVarsFor: GLHProject."
×
1033

×
1034
        ^ reader nextAs: GLHProject
×
1035
]
×
1036

×
NEW
1037
{ #category : #'private - parsing' }
×
1038
GLHModelImporter >> parseSubGroupResult: aResult [
×
1039

×
1040
        | reader |
×
1041
        reader := NeoJSONReader on: aResult readStream.
×
1042
        self configureReaderForGroup: reader.
×
1043
        ^ reader nextAs: #ArrayOfGroups
×
1044
]
×
1045

×
NEW
1046
{ #category : #'private - parsing' }
×
1047
GLHModelImporter >> parseUserResult: result [
×
1048

×
1049
        | reader |
×
1050
        reader := NeoJSONReader on: result readStream.
×
1051
        reader mapInstVarsFor: GLHUser.
×
1052
        ^ reader nextAs: GLHUser
×
1053
]
×
1054

×
NEW
1055
{ #category : #'private - parsing' }
×
1056
GLHModelImporter >> parseUsersResult: result [
×
1057

×
1058
        | reader |
×
1059
        reader := NeoJSONReader on: result readStream.
×
1060

×
1061
        reader mapInstVarsFor: GLHUser.
×
1062

×
1063
        reader
×
1064
                for: #ArrayOfUser
×
1065
                customDo: [ :customMappting |
×
1066
                customMappting listOfElementSchema: GLHUser ].
×
1067

×
1068
        ^ reader nextAs: #ArrayOfUser
×
1069
]
×
1070

×
NEW
1071
{ #category : #'imports - pipelines' }
×
1072
GLHModelImporter >> pipelinesOf: aProjectID [
×
1073

×
1074
        | result |
×
1075
        ('Search pipelines of: ' , aProjectID printString) recordInfo.
×
NEW
1076
        result := self repoApi pipelines getAllInProject: aProjectID.
×
NEW
1077
        "pipelinesOfProject: aProjectID."
×
NEW
1078
        ^ (result collect: [ :pipelinesJson | self parsePipelinesResult: pipelinesJson ]) flattened
×
1079
]
×
1080

×
NEW
1081
{ #category : #private }
×
1082
GLHModelImporter >> selectEntityType: aType overAttribut: aSelector equalTo: value [
×
1083

×
1084
        ^ (self glhModel allWithType: aType)
×
1085
                select: [ :entity | (entity perform: aSelector) = value ]
×
1086
]
×
1087

×
NEW
1088
{ #category : #'import - groups' }
×
1089
GLHModelImporter >> subGroupsOf: aGroupID [
×
1090

×
NEW
1091
        | results subgroups |
×
1092
        ('Search subgroup of: ' , aGroupID printString) recordInfo.
×
NEW
1093
        results := self repoApi groups subgroupsOf: aGroupID.
×
NEW
1094
        subgroups := (results collect: [ :subgroupsJson | self parseSubGroupResult: subgroupsJson ]) flattened.
×
1095
        
×
NEW
1096
        ^ subgroups
×
1097
]
×
1098

×
NEW
1099
{ #category : #accessing }
×
1100
GLHModelImporter >> withInitialCommits: boolean [
×
1101
        withInitialCommits := boolean 
×
1102
]
×
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