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

moosetechnology / GitProjectHealth / 16163940073

09 Jul 2025 08:10AM UTC coverage: 74.26% (-0.6%) from 74.908%
16163940073

Pull #216

github

web-flow
Merge ee8bd9087 into 8f0fcd09b
Pull Request #216: add issue class in model

10 of 328 new or added lines in 6 files covered. (3.05%)

24 existing lines in 2 files now uncovered.

17584 of 23679 relevant lines covered (74.26%)

0.74 hits per line

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

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

12
{ #category : #private }
13
GitlabModelImporter >> 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
GitlabModelImporter >> 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 : #'import - pipelines' }
40
GitlabModelImporter >> allPipelinesOf: aProjectID [
×
41

×
42
        | result |
×
43
        ('Search pipelines of: ' , aProjectID printString) recordInfo.
×
44
        result := self repoApi pipelines getAllInProject: aProjectID.
×
45
        result isString ifTrue: [ ^ self parsePipelinesResult: result ].
×
46

×
47
        ^ (result collect: [ :pipelinesJson |
×
48
                           self parsePipelinesResult: pipelinesJson ]) flattened
×
49
]
×
50

51
{ #category : #private }
52
GitlabModelImporter >> chainsCommitsFrom: commitsCollection [
1✔
53

1✔
54
        | dic |
1✔
55
        
1✔
56
        ('Chains ', commitsCollection size printString , ' commits') recordInfo.
1✔
57
        
1✔
58
        dic := ((self glhModel allWithType: GLHCommit) collect: [ :commit |
1✔
59
                        commit id -> commit ]) asSet asDictionary.
1✔
60

1✔
61
        commitsCollection do: [ :commit |
1✔
62
                commit parent_ids do: [ :parentId | 
1✔
63
                        dic
1✔
64
                                at: parentId
1✔
65
                                ifPresent: [ :parentCommit |
1✔
66
                                        parentCommit childCommits
1✔
67
                                                add: commit
1✔
68
                                                unless: self blockOnIdEquality ]
1✔
69
                                ifAbsent: [  ] ] ].
1✔
70
        ^ commitsCollection
1✔
71
]
1✔
72

73
{ #category : #'import - commits' }
74
GitlabModelImporter >> commitsOfProject: aGLHProject forRefName: refName until: toDate [
×
75

×
76
        | params results allCommits |
×
77
        
×
78
        params := { 
×
79
                #ref_name -> refName.
×
80
                #until -> (toDate ifNotNil: [ toDate asDateAndTime asString ] ifNil: [ '' ]) 
×
81
        } asDictionary.
×
82
        results := self repoApi commits getAllInProject: aGLHProject id withParams: params.
×
83
        allCommits := (results collect: [ :commitsJson | self parseCommitsResult: commitsJson ]) flattened.
×
84
        
×
85
        self glhModel addAll: allCommits unless: self blockOnIdEquality.
×
86
        aGLHProject repository commits addAll: allCommits unless: self blockOnIdEquality.
×
87

×
88
        self withCommitDiffs ifTrue: [
×
89
                aGLHProject repository commits do: [ :commit |
×
90
                        self importDiffOfCommit: commit ] ].
×
91
        
×
92
        ^allCommits
×
93
]
×
94

95
{ #category : #'import - projects' }
96
GitlabModelImporter >> completeImportProject: aGLHProject [
×
97

×
98
        | importedProject |
×
99
        ('Complete import of project: ' , aGLHProject id printString)
×
100
                recordInfo.
×
101
        aGLHProject repository ifNotNil: [ ^ aGLHProject ].
×
102

×
103
        importedProject := self glhModel
×
104
                                   add: aGLHProject
×
105
                                   unless: self blockOnIdEquality.
×
106

×
107
        self importLatestPipelinesOfProject: importedProject.
×
108

×
109
        "aGLHProject creator: (self importUser: aGLHProject creator_id)."
×
110

×
111
        (self importUser: importedProject creator_id) addCreatedProject:
×
112
                importedProject.
×
113

×
114

×
115
        importedProject repository: GLHRepository new.
×
116
        self glhModel add: importedProject repository.
×
117
        self importRepository: importedProject repository.
×
118

×
119

×
120
        withInitialMergeRequest ifTrue: [
×
121
                self
×
122
                        importMergeRequests: importedProject
×
123
                        since: DateAndTime today
×
124
                        until: DateAndTime now ].
×
125

×
126
        ^ importedProject
×
127
        
×
128

×
129
]
×
130

131
{ #category : #'import - commits' }
132
GitlabModelImporter >> completeImportedCommit: aCommit [
1✔
133

1✔
134
        ('completing commit: ' , aCommit short_id printString) recordInfo.
1✔
135
        self importCreatorOfCommit: aCommit.
1✔
136

1✔
137
        self withCommitDiffs ifTrue: [
1✔
138
                | diffs |
1✔
139
                aCommit diffs ifEmpty: [
1✔
140
                        diffs := self importDiffOfCommit: aCommit.
1✔
141
                        self glhModel addAll: diffs unless: self blockForDiffEquality ] ].
1✔
142

1✔
143
        ^ aCommit
1✔
144
]
1✔
145

146
{ #category : #'import - pipelines' }
147
GitlabModelImporter >> completeImportedPipeline: aGLHPipeline [ 
×
148
        |result parsedResult|
×
149
        
×
150
        aGLHPipeline duration ifNotNil: [ ^ aGLHPipeline ].
×
151
        
×
152
        result := self repoApi pipelines get: aGLHPipeline id inProject: aGLHPipeline project id. 
×
153
        parsedResult := self parsePipelineResult: result. 
×
154
        
×
155
        "aGLHPipeline methods".
×
156
        { #'created_at:' . #'status:' . #'finished_at:' . #'duration:' . #'started_at:' . #'updated_at:' . #'ref:' } do: [ :m |
×
157
                aGLHPipeline perform: m asSymbol with: (parsedResult perform: (m withoutSuffix: ':') asSymbol )
×
158
                 ].
×
159
        
×
160
        parsedResult cacheAt: #userID ifPresent: [:id |
×
161
                aGLHPipeline user: (self importUser: id). 
×
162
                ].
×
163
        
×
164
        ^ aGLHPipeline. 
×
165
]
×
166

167
{ #category : #'import - pipelines' }
168
GitlabModelImporter >> completeImportedPipelines: aCollectionOfGLHPipeline [
×
169
        ^ aCollectionOfGLHPipeline collect: [ :pipeline | self completeImportedPipeline: pipeline ].  
×
170
]
×
171

172
{ #category : #'import - projects' }
173
GitlabModelImporter >> completeImportedProject: aGLHProject [
1✔
174

1✔
175
        | importedProject |
1✔
176
        ('Complete import of project: ' , aGLHProject id printString)
1✔
177
                recordInfo.
1✔
178
        aGLHProject repository ifNotNil: [ ^ aGLHProject ].
1✔
179

1✔
180
        importedProject := self glhModel
1✔
181
                                   add: aGLHProject
1✔
182
                                   unless: self blockOnIdEquality.
1✔
183

1✔
184
        self importLatestPipelinesOfProject: importedProject.
1✔
185

1✔
186
        "aGLHProject creator: (self importUser: aGLHProject creator_id)."
1✔
187

1✔
188
        (self importUser: importedProject creator_id) addCreatedProject:
1✔
189
                importedProject.
1✔
190

1✔
191

1✔
192
        importedProject repository: GLHRepository new.
1✔
193
        self glhModel add: importedProject repository.
1✔
194
        self importRepository: importedProject repository.
1✔
195

1✔
196

1✔
197
        withInitialMergeRequest ifTrue: [
1✔
198
                self
1✔
199
                        importMergeRequests: importedProject
1✔
200
                        since: DateAndTime today
1✔
201
                        until: DateAndTime now ].
1✔
202

1✔
203
        ^ importedProject
1✔
204
        
1✔
205

1✔
206
]
1✔
207

208
{ #category : #'private - configure reader' }
209
GitlabModelImporter >> configureReaderForCommit: reader [
1✔
210

1✔
211
          reader for: GLHCommit do: [ :mapping |
1✔
212
                mapping mapInstVars:
1✔
213
                        #( id short_id title author_name author_email committer_name
1✔
214
                           committer_email message web_url ).
1✔
215
                (mapping mapInstVar: #authored_date) valueSchema: DateAndTime.
1✔
216
                (mapping mapInstVar: #committed_date) valueSchema: DateAndTime.
1✔
217
                (mapping mapInstVar: #created_at) valueSchema: DateAndTime.
1✔
218
                (mapping mapInstVar: #parent_ids) valueSchema: #ArrayOfIds.
1✔
219
                mapping
1✔
220
                        mapProperty: 'stats'
1✔
221
                        getter: [ :el | "Not used" ]
1✔
222
                        setter: [ :commit :value |
1✔
223
                                commit deletions: (value at: #deletions).
1✔
224
                                commit additions: (value at: #additions) ] ].
1✔
225

1✔
226
        reader for: DateAndTime customDo: [ :mapping |
1✔
227
                mapping decoder: [ :string | DateAndTime fromString: string ] ].
1✔
228

1✔
229
        reader
1✔
230
                for: #ArrayOfIds
1✔
231
                customDo: [ :mapping | mapping decoder: [ :string | string ] ].
1✔
232
  
1✔
233
        reader
1✔
234
                for: #ArrayOfCommit
1✔
235
                customDo: [ :customMappting |
1✔
236
                customMappting listOfElementSchema: GLHCommit ].
1✔
237

1✔
238
]
1✔
239

240
{ #category : #'private - configure reader' }
241
GitlabModelImporter >> configureReaderForDiffs: reader [
1✔
242

1✔
243
        reader for: GLHDiff do: [ :mapping |
1✔
244
                mapping mapInstVars:
1✔
245
                        #( deleted_file new_file new_path old_path renamed_file ).
1✔
246
                mapping mapInstVar: #diffString to: #diff ].
1✔
247

1✔
248
        reader
1✔
249
                for: #ArrayOfDiffs
1✔
250
                customDo: [ :customMappting |
1✔
251
                customMappting listOfElementSchema: GLHDiff ].
1✔
252
        ^ reader
1✔
253
]
1✔
254

255
{ #category : #'private - configure reader' }
256
GitlabModelImporter >> configureReaderForGroup: reader [
1✔
257

1✔
258
        reader for: GLHGroup do: [ :mapping |
1✔
259
                mapping mapInstVars.
1✔
260
                (mapping mapInstVar: #projects) valueSchema: #ArrayOfProjects ].
1✔
261
        reader mapInstVarsFor: GLHProject.
1✔
262
        reader
1✔
263
                for: #ArrayOfProjects
1✔
264
                customDo: [ :customMappting |
1✔
265
                customMappting listOfElementSchema: GLHProject ].
1✔
266
        reader
1✔
267
                for: #ArrayOfGroups
1✔
268
                customDo: [ :customMappting |
1✔
269
                customMappting listOfElementSchema: GLHGroup ]
1✔
270
]
1✔
271

272
{ #category : #'private - configure reader' }
273
GitlabModelImporter >> configureReaderForMergeRequest: reader [
1✔
274
        "declare quil y a un array a mapper"
1✔
275

1✔
276
        reader for: #ArrayOfMergeRequest customDo: [ :customMappting |
1✔
277
                customMappting listOfElementSchema: GLHMergeRequest ].
1✔
278

1✔
279
        "declare la liste des properties"
1✔
280
        reader for: GLHMergeRequest do: [ :mapping |
1✔
281
                mapping mapInstVars:
1✔
282
                        #( blocking_discussions_resolved changes_count description
1✔
283
                           detailed_merge_status discussion_locked downvotes draft first_deployed_to_production_at
1✔
284
                           force_remove_source_branch has_conflicts id iid labels latest_build_finished_at
1✔
285
                           latest_build_started_at merge_commit_sha merge_status
1✔
286
                           merge_when_pipeline_succeeds merged_at milestone project_id
1✔
287
                           reference references_full references_relative
1✔
288
                           references_short sha should_remove_source_branch
1✔
289
                           source_branch source_project_id squash squash_commit_sha
1✔
290
                           squash_on_merge state subscribed target_branch target_project_id
1✔
291
                           task_completion_status_completed_count
1✔
292
                           task_completion_status_count time_stats_human_time_estimate
1✔
293
                           time_stats_human_total_time_spent
1✔
294
                           time_stats_time_estimate time_stats_total_time_spent
1✔
295
                           title updated_at upvotes user_notes_count web_url work_in_progress ).
1✔
296
                (mapping mapInstVar: #created_at) valueSchema: DateAndTime.
1✔
297
                (mapping mapInstVar: #updated_at) valueSchema: DateAndTime.
1✔
298
                (mapping mapInstVar: #merged_at) valueSchema: DateAndTime.
1✔
299
                (mapping mapInstVar: #closed_at) valueSchema: DateAndTime.
1✔
300
                "(mapping mapInstVar: #assignee) valueSchema: GLHUser."
1✔
301
                mapping
1✔
302
                        mapProperty: #author
1✔
303
                        getter: [  ]
1✔
304
                        setter: [ :object :value |
1✔
305
                        object cacheAt: #authorID put: (value at: #id) ].
1✔
306
                mapping
1✔
307
                        mapProperty: #merge_user
1✔
308
                        getter: [  ]
1✔
309
                        setter: [ :object :value | 
1✔
310
                                value ifNotNil: [
1✔
311
                                        object cacheAt: #mergeUserID put: (value at: #id) ] ] ].
1✔
312

1✔
313
        "(mapping mapInstVar: #closed_by) valueSchema: GLHUser.
1✔
314
        (mapping mapInstVar: #mergeCommit) valueSchema: GLHCommit."
1✔
315
        "indique ce que doit faire le reader lorsqu'il parse une DateAndTime object"
1✔
316
        reader for: DateAndTime customDo: [ :mapping |
1✔
317
                mapping decoder: [ :string |
1✔
318
                        string ifNil: [ nil ] ifNotNil: [ DateAndTime fromString: string ] ] ]
1✔
319
]
1✔
320

321
{ #category : #'private - configure reader' }
322
GitlabModelImporter >> configureReaderForPipeline: reader [
1✔
323

1✔
324
        reader mapInstVarsFor: GLHPipeline.
1✔
325
        
1✔
326
        reader for: GLHPipeline do: [ :mapping |
1✔
327

1✔
328
                mapping
1✔
329
                        mapProperty: #created_at
1✔
330
                        getter: [ :object | #ignore ]
1✔
331
                        setter: [ :object :value |
1✔
332
                        object created_at: (value ifNotNil: [DateAndTime fromString: value]).
1✔
333
                        object runDate: (value ifNotNil: [DateAndTime fromString: value]) ].
1✔
334
                
1✔
335
                mapping
1✔
336
                        mapProperty: #updated_at
1✔
337
                        getter: [ :object | #ignore ]
1✔
338
                        setter: [ :object :value |
1✔
339
                        object updated_at: (value ifNotNil: [DateAndTime fromString: value]).
1✔
340
                        ].
1✔
341
                
1✔
342
                mapping
1✔
343
                        mapProperty: #finished_at
1✔
344
                        getter: [ :object | #ignore ]
1✔
345
                        setter: [ :object :value |
1✔
346
                                object finished_at: (value ifNotNil: [DateAndTime fromString: value]).
1✔
347
                        ].
1✔
348
                
1✔
349
                mapping
1✔
350
                        mapProperty: #started_at  
1✔
351
                        getter: [ :object | #ignore ]
1✔
352
                        setter: [ :object :value |
1✔
353
                        object started_at: (value ifNotNil: [DateAndTime fromString: value]).
1✔
354
                        ].
1✔
355
                
1✔
356
                mapping
1✔
357
                        mapProperty: #source
1✔
358
                        getter: [ :object | #ignore ]
1✔
359
                        setter: [ :object :value |
1✔
360
                        object sourceEvent: value.
1✔
361
                        ].
1✔
362
                
1✔
363
                mapping
1✔
364
                        mapProperty: #duration
1✔
365
                        getter: [ :object | #ignore ]
1✔
366
                        setter: [ :object :value |
1✔
367
                        object duration: (value ifNotNil: [value asDuration]) .
1✔
368
                        ].
1✔
369
                
1✔
370
                mapping
1✔
371
                        mapProperty: #user
1✔
372
                        getter: [ :object | #ignore ]
1✔
373
                        setter: [ :object :value |
1✔
374
                        value ifNotNil: [object cacheAt: #userID put: (value at: #id)].
1✔
375
                        ].
1✔
376
                
1✔
377
                 ].
1✔
378
        
1✔
379
        reader
1✔
380
                for: #ArrayOfPipelines
1✔
381
                customDo: [ :customMappting |
1✔
382
                customMappting listOfElementSchema: GLHPipeline ].
1✔
383
]
1✔
384

385
{ #category : #'private - configure reader' }
386
GitlabModelImporter >> configureReaderForReleases: reader [
1✔
387

1✔
388
        reader mapInstVarsFor: GLHRelease .
1✔
389
        
1✔
390
        
1✔
391
        reader for: GLHRelease do: [ :mapping |
1✔
392
                        
1✔
393
                (mapping mapInstVar: #author) valueSchema: GLHUser .
1✔
394
                 ].
1✔
395
        
1✔
396
        
1✔
397
        reader
1✔
398
                for: #ArrayOfReleases
1✔
399
                customDo: [ :customMappting |
1✔
400
                customMappting listOfElementSchema: GLHRelease ].
1✔
401
]
1✔
402

403
{ #category : #'private - configure reader' }
404
GitlabModelImporter >> configureReaderForTags: reader [
1✔
405

1✔
406
        reader mapInstVarsFor: GLHTag .
1✔
407
        
1✔
408
        reader for: GLHTag do: [ :mapping |
1✔
409
                        
1✔
410
                (mapping mapInstVar: #commit) valueSchema: GLHCommit .
1✔
411
"                (mapping mapInstVar: #release) valueSchema: GLHRelease ."
1✔
412
                (mapping mapInstVar: #created_at) valueSchema: DateAndTime .
1✔
413
                
1✔
414
                mapping
1✔
415
                        mapProperty: #release
1✔
416
                        getter: [ :object | #ignore ]
1✔
417
                        setter: [ :object :value |
1✔
418
                        object release: (value ifNotNil: [GLHRelease new description: (value at:#description); tag_name: (value at: #tag_name); yourself ]).
1✔
419
                        ].
1✔
420
                 ].
1✔
421
        
1✔
422
        reader
1✔
423
                for: #ArrayOfTags
1✔
424
                customDo: [ :customMappting |
1✔
425
                customMappting listOfElementSchema: GLHTag ].
1✔
426
]
1✔
427

1✔
428
{ #category : #'private - configure reader' }
1✔
429
GitlabModelImporter >> configureReaderForUsers: reader [
1✔
430

1✔
431
        reader mapInstVarsFor: GLHUser.
1✔
432

1✔
433
        reader
1✔
434
                for: #ArrayOfUser
1✔
435
                customDo: [ :customMappting |
1✔
436
                customMappting listOfElementSchema: GLHUser ].
1✔
437

1✔
438
]
1✔
439

1✔
440
{ #category : #private }
1✔
441
GitlabModelImporter >> convertApiFileAsFile: aAPIFile [
1✔
442

1✔
443
        aAPIFile type = 'tree' ifTrue: [ 
1✔
444
                ^ GLHFileDirectory new
1✔
445
                          name: aAPIFile name;
1✔
446
                          yourself ].
1✔
447
        ^ GLHFileBlob new
1✔
448
                  name: aAPIFile name;
1✔
449
                  yourself
1✔
450
]
1✔
451

1✔
452
{ #category : #private }
1✔
453
GitlabModelImporter >> detectEntityType: aType overAttribut: aSelector equalTo: value [
1✔
454

1✔
455
        ^ (self glhModel allWithType: aType) detect: [ :entity |
1✔
456
                  (entity perform: aSelector) = value ] ifNone: [ nil ]. 
1✔
457
]
1✔
458

1✔
459
{ #category : #accessing }
1✔
460
GitlabModelImporter >> glhApi [
1✔
461

1✔
462
        self
1✔
463
                deprecated: 'Use #repoApi instead'
1✔
464
                on: '7 October 2024'
1✔
465
                in:
1✔
466
                'Pharo-11.0.0+build.726.sha.aece1b5473acf3830a0e082c1bc3a15d4ff3522b (64 Bit)'.
1✔
467

1✔
468
        ^ repoApi
1✔
469
]
1✔
470

1✔
471
{ #category : #accessing }
1✔
472
GitlabModelImporter >> glhApi: anObject [
1✔
473

1✔
474
        self
1✔
475
                deprecated: 'Use #repoApi: instead'
1✔
476
                on: '7 October 2024'
1✔
477
                in:
1✔
478
                'Pharo-11.0.0+build.726.sha.aece1b5473acf3830a0e082c1bc3a15d4ff3522b (64 Bit)'.
1✔
479

1✔
480
        repoApi := anObject
1✔
481
]
1✔
482

1✔
483
{ #category : #accessing }
1✔
484
GitlabModelImporter >> glhModel [
1✔
485

1✔
486
        ^ glhModel
1✔
487
]
1✔
488

1✔
489
{ #category : #accessing }
1✔
490
GitlabModelImporter >> glhModel: anObject [
1✔
491

1✔
492
        glhModel := anObject
1✔
493
]
1✔
494

1✔
495
{ #category : #'import - users' }
1✔
496
GitlabModelImporter >> importActiveHumanUsers [
1✔
497

1✔
498
        | params result users |
1✔
499
        params := { 
1✔
500
                #humans -> 'true'.
1✔
501
                #active -> 'true'.
1✔
502
                #without_project_bots -> 'true'
1✔
503
        } asDictionary.
1✔
504
        result := self repoApi users allWithParams: params.
1✔
505
        users := (result collect: [ :usersJson | self parseUsersResult: usersJson ]) flattened.
1✔
506
        
1✔
507
        self glhModel
1✔
508
                                 addAll: users
1✔
509
                                 unless: self blockOnIdEquality.
1✔
510

1✔
511
        ^ users
1✔
512
]
1✔
513

1✔
514
{ #category : #'import - groups' }
1✔
515
GitlabModelImporter >> importAllGroups [
1✔
516

1✔
517
        | params results groups |
1✔
518
        
1✔
519
        params := { 
1✔
520
                        #top_level_only -> 'true'
1✔
521
        } asDictionary.
1✔
522
        results := self repoApi groups getAllWithParams: params.
1✔
523
        
1✔
524
        groups := (results collect: [ :groupsJson | generalReader
1✔
525
                                            on: groupsJson readStream;
1✔
526
                                            nextAs: #ArrayOfGroups. ]) flattened.
1✔
527
        ^ groups
1✔
528
]
1✔
529

1✔
530
{ #category : #'import - pipelines' }
1✔
531
GitlabModelImporter >> importAllPipelinesOfProject: aGLHProject [
1✔
532

1✔
533
        (self allPipelinesOf: aGLHProject id) do: [ :pipeline |
1✔
534
                |pip|
1✔
535
                pip := self glhModel add: pipeline unless: self blockOnIdEquality .
1✔
536
                pip := aGLHProject pipelines add: pip unless: self blockOnIdEquality.
1✔
537
                self completeImportedPipeline: pip. 
1✔
538
                ].
1✔
539
        
1✔
540
        ^ aGLHProject pipelines
1✔
541
]
1✔
542

1✔
543
{ #category : #'import - commits' }
1✔
544
GitlabModelImporter >> importAndLoadLatestsCommitsOfProject: aGLHProject [
1✔
545

1✔
546
        | commits completedProject |
1✔
547
        completedProject := self completeImportedProject: aGLHProject.
1✔
548
        commits := self importLastestCommitsOfProject: completedProject.
1✔
549
        commits do: [ :commit | self completeImportedCommit: commit ].
1✔
550
        self chainsCommitsFrom: commits.
1✔
551
        ^ commits
1✔
552
]
1✔
553

1✔
554
{ #category : #'import - user' }
1✔
555
GitlabModelImporter >> importAuthorOfCommit: aGLHCommit [ 
1✔
556
                |user|
1✔
557
        user:= (self importUserByUsername: aGLHCommit author_name) .
1✔
558
        aGLHCommit commitCreator: user. 
1✔
559
        ^ user
1✔
560
]
1✔
561

1✔
562
{ #category : #'import - commits' }
1✔
563
GitlabModelImporter >> importCommit: aCommitID ofProject: aGLHProject [
1✔
564

1✔
565
        | result parsedResult |
1✔
566
        (self glhModel allWithType: GLHCommit) asOrderedCollection
1✔
567
                detect: [ :commit | commit id = aCommitID ]
1✔
568
                ifFound: [ :commit | ^ commit ].
1✔
569
        result := self repoApi commits get: aCommitID inProject: aGLHProject id.
1✔
570
        
1✔
571
        parsedResult := self parseCommitResult: result.
1✔
572
        
1✔
573
        self
1✔
574
                addCommits: { parsedResult }
1✔
575
                toRepository: aGLHProject repository.
1✔
576
        ^ parsedResult
1✔
577
]
1✔
578

1✔
579
{ #category : #'import - commits' }
1✔
580
GitlabModelImporter >> importCommitOfProject: anProject withId: anID [
1✔
581

1✔
582
        | commit result |
1✔
583
        anID ifNil: [ ^ nil ].
1✔
584

1✔
585
        ('looking for commit ' , anID printString , ' in project : '
1✔
586
         , anProject id printString) recordInfo.
1✔
587

1✔
588
        commit := (self
1✔
589
                           detectEntityType: GLHCommit
1✔
590
                           overAttribut: #id
1✔
591
                           equalTo: anID) ifNil: [
1✔
592
                          result := self repoApi commits get: anID inProject: anProject id.
1✔
593
                          commit := (self parseCommitsResult: '[' , result , ']')
1✔
594
                                            first.
1✔
595

1✔
596
                          self glhModel add: commit unless: self blockOnIdEquality.
1✔
597
                          commit repository: anProject repository.
1✔
598

1✔
599
                          commit ].
1✔
600

1✔
601
        self withCommitDiffs ifTrue: [ self importDiffOfCommit: commit ].
1✔
602

1✔
603
        ^ commit
1✔
604
]
1✔
605

1✔
606
{ #category : #'import - commits' }
1✔
607
GitlabModelImporter >> importCommits: aGLHProject [
1✔
608
        "limited to the last 20 commits"
1✔
609

1✔
610
        | results parsedResults params |
1✔
611
        params := { 
1✔
612
         #with_stats -> 'true'
1✔
613
        } asDictionary.
1✔
614
        results := self repoApi commits getByPage: 1 perPage: 20 inProject: aGLHProject id withParams: params.
1✔
615
        
1✔
616
        parsedResults := self parseCommitsResult: results.
1✔
617
        self glhModel addAll: parsedResults unless: self blockOnIdEquality.
1✔
618

1✔
619
        parsedResults do: [ :commit |
1✔
620
                commit repository: aGLHProject repository ].
1✔
621

1✔
622
        self withCommitDiffs ifTrue: [
1✔
623
                parsedResults do: [ :commit | self importDiffOfCommit: commit ] ].
1✔
624
        
1✔
625
        ^ parsedResults. 
1✔
626
]
1✔
627

1✔
628
{ #category : #'import - commits' }
1✔
629
GitlabModelImporter >> importCommitsFollowing: aCommit upToDays: aNumberOfDay [
1✔
630
        "import the 'n' commits of a project starting from an initial 'aCommit' commit. 
1✔
631
        Lazy import does not import the entities inside the model"
1✔
632

1✔
633
        | date |
1✔
634
        date := aCommit created_at asDateAndTime.
1✔
635

1✔
636
        ^ self
1✔
637
                  importCommitsOfBranch: aCommit branch
1✔
638
                  forRefName: aCommit branch name
1✔
639
                  since: date
1✔
640
                  until: (date + aNumberOfDay day)
1✔
641
]
1✔
642

1✔
643
{ #category : #commit }
1✔
644
GitlabModelImporter >> importCommitsOf: aGLHProject withStats: aBoolean until: toDate [
1✔
645

1✔
646
        | newlyFoundCommit page |
1✔
647
        
1✔
648
        self deprecated: [  ] .
1✔
649
        
1✔
650
        page := 0.
1✔
651
        newlyFoundCommit := { true }.
1✔
652
        [ newlyFoundCommit isNotEmpty ] whileTrue: [
1✔
653
                | results parsedResults existingCommits |
1✔
654
                page := page + 1.
1✔
655
                ('import commit page ' , page printString) recordInfo.
1✔
656
                results := self repoApi
1✔
657
                                   commitsOfProject: aGLHProject id
1✔
658
                                   forRefName: nil
1✔
659
                                   since: nil
1✔
660
                                   until: nil
1✔
661
                                   path: nil
1✔
662
                                   author: nil
1✔
663
                                   all: nil
1✔
664
                                   with_stats: aBoolean
1✔
665
                                   firstParent: nil
1✔
666
                                   order: nil
1✔
667
                                   trailers: nil
1✔
668
                                   perPage: 100
1✔
669
                                   page: page.
1✔
670
                parsedResults := self parseCommitsResult: results.
1✔
671
                existingCommits := aGLHProject mooseModel allWithType: GLHCommit.
1✔
672

1✔
673
                newlyFoundCommit := parsedResults reject: [ :commitParsed |
1✔
674
                                            (toDate isNil or: [
1✔
675
                                                     commitParsed committed_date
1✔
676
                                                     < toDate asDateAndTime ]) or: [
1✔
677
                                                    existingCommits anySatisfy: [ :existingCommit |
1✔
678
                                                            existingCommit id = commitParsed id ] ] ].
1✔
679
                aGLHProject mooseModel addAll: newlyFoundCommit.
1✔
680
                aGLHProject repository commits addAll: newlyFoundCommit ].
1✔
681

1✔
682

1✔
683
        self withCommitDiffs ifTrue: [
1✔
684
                aGLHProject repository commits do: [ :commit |
1✔
685
                        self importDiffOfCommit: commit ] ]
1✔
686
]
1✔
687

1✔
688
{ #category : #'import - commits' }
1✔
689
GitlabModelImporter >> importCommitsOfBranch: aGLHBranch [
1✔
690

1✔
691
        | commits |
1✔
692
        "        result := self glhApi
1✔
693
                          commitsOfProject: aGLHBranch repository project id
1✔
694
                          forRefName: aGLHBranch name."
1✔
695
        commits := self
1✔
696
                           importCommitsOfBranch: aGLHBranch
1✔
697
                           forRefName: aGLHBranch name
1✔
698
                           since: withCommitsSince.
1✔
699

1✔
700
        self chainsCommitsFrom: commits.
1✔
701

1✔
702
        commits do: [ :aCommit |
1✔
703
                aCommit repository: aGLHBranch repository.
1✔
704
                self completeImportedCommit: aCommit. 
1✔
705
                 ]
1✔
706
]
1✔
707

1✔
708
{ #category : #'import - commits' }
1✔
709
GitlabModelImporter >> importCommitsOfBranch: aGLHBranch forRefName: refName since: fromDate [
1✔
710

1✔
711
        ^ self
1✔
712
                  importCommitsOfBranch: aGLHBranch
1✔
713
                  forRefName: aGLHBranch name
1✔
714
                  since: fromDate
1✔
715
                  until: nil
1✔
716
]
1✔
717

1✔
718
{ #category : #'import - commits' }
1✔
719
GitlabModelImporter >> importCommitsOfBranch: aGLHBranch forRefName: refName since: fromDate until: toDate [
1✔
720

1✔
721
        | params result allCommits |
1✔
722
        params := { 
1✔
723
          #ref_name -> aGLHBranch name.
1✔
724
          #since ->  (fromDate ifNotNil: [ fromDate asDate asDateAndTime asString ] ifNil: [ '' ]).
1✔
725
          #until -> (toDate ifNotNil: [ toDate asDate asDateAndTime asString ] ifNil: [ '' ]). 
1✔
726

1✔
727
        } asDictionary.
1✔
728
        result := self repoApi commits getAllInProject: aGLHBranch repository project id withParams: params.
1✔
729
        
1✔
730
        allCommits := (result collect: [ :commitsJson | self parseCommitsResult: commitsJson ]) flattened.
1✔
731
        
1✔
732
        aGLHBranch commits
1✔
733
                        addAll: allCommits
1✔
734
                        unless: self blockOnIdEquality.
1✔
735

1✔
736
        self glhModel
1✔
737
                addAll: aGLHBranch commits
1✔
738
                unless: self blockOnIdEquality.
1✔
739

1✔
740
        ^ allCommits
1✔
741
]
1✔
742

1✔
743
{ #category : #'import - commits' }
1✔
744
GitlabModelImporter >> importCommitsOfBranch: aGLHBranch forRefName: refName until: toDate [
1✔
745

1✔
746
        ^ self
1✔
747
                  importCommitsOfBranch: aGLHBranch
1✔
748
                  forRefName: aGLHBranch name
1✔
749
                  since: nil
1✔
750
                  until: toDate
1✔
751
]
1✔
752

1✔
753
{ #category : #'import - commits' }
1✔
754
GitlabModelImporter >> importCommitsOfProject: aProject since: fromDate until: toDate [
1✔
755

1✔
756
        | params results allCommits |
1✔
757
        params := {
1✔
758
                          (#since
1✔
759
                           ->
1✔
760
                           (fromDate
1✔
761
                                    ifNotNil: [ fromDate asDate asDateAndTime asString ]
1✔
762
                                    ifNil: [ '' ])).
1✔
763
                          (#until
1✔
764
                           ->
1✔
765
                           (toDate
1✔
766
                                    ifNotNil: [ toDate asDate asDateAndTime asString ]
1✔
767
                                    ifNil: [ '' ])).
1✔
768
                          (#with_stats -> 'true').
1✔
769
                          (#all -> 'true') } asDictionary.
1✔
770
        results := self repoApi commits
1✔
771
                           getAllInProject: aProject id
1✔
772
                           withParams: params.
1✔
773

1✔
774
        allCommits := (results collect: [ :commitsJson |
1✔
775
                               self parseCommitsResult: commitsJson ]) flattened.
1✔
776

1✔
777
        allCommits:= aProject repository commits
1✔
778
                addAll: allCommits
1✔
779
                unless: self blockOnIdEquality.
1✔
780

1✔
781
        ^ self glhModel addAll: allCommits unless: self blockOnIdEquality
1✔
782
]
1✔
783

1✔
784
{ #category : #'import - projects' }
1✔
785
GitlabModelImporter >> importContributedProjectsOfUser: aGLHUser [
1✔
786

1✔
787
        | remaningProjects params results projects projectsIds |
1✔
788
        params := {
1✔
789
                          (#order_by -> 'last_activity_at').
1✔
790
                          (#simple -> 'true') } asDictionary.
1✔
791
        results := self repoApi projects
1✔
792
                           contributedProjectsOfUser: aGLHUser id
1✔
793
                           withParams: params.
1✔
794

1✔
795
        projectsIds := (results collect: [ :projectsJson |
1✔
796
                             (NeoJSONReader fromString: projectsJson) collect: [:projectJson | projectJson at: #id ] ]) flattened.
1✔
797
        
1✔
798
        projects := self importProjects: projectsIds.
1✔
799
        remaningProjects := self importProjects:
1✔
800
                                    ((projects collect: #id) difference:
1✔
801
                                             ((self userCatalogue atId: aGLHUser id) at:
1✔
802
                                                      #contributedProjects)).
1✔
803

1✔
804

1✔
805
        aGLHUser contributedProjects
1✔
806
                addAll: projects , remaningProjects
1✔
807
                unless: self blockOnIdEquality.
1✔
808

1✔
809
        self userCatalogue
1✔
810
                addUser: aGLHUser
1✔
811
                withProjects: (aGLHUser contributedProjects collect: #id).
1✔
812

1✔
813
        ^ projects
1✔
814
]
1✔
815

1✔
816
{ #category : #'import - commits' }
1✔
817
GitlabModelImporter >> importCreatorOfCommit: aCommit [
1✔
818

1✔
819
        aCommit commitCreator ifNil: [
1✔
820
                aCommit commitCreator:
1✔
821
                        (self importUserByUsername: aCommit author_name) ].
1✔
822
        self userCatalogue
1✔
823
                addUser: aCommit commitCreator
1✔
824
                withProject: aCommit repository project id.
1✔
825
        ^ aCommit commitCreator
1✔
826
]
1✔
827

1✔
828
{ #category : #'import - commits' }
1✔
829
GitlabModelImporter >> importDiffOfCommit: aCommit [
1✔
830

1✔
831
        | result diffsResult |
1✔
832
        aCommit diffs ifNotEmpty: [
1✔
833
                'Diff already importer: ' , aCommit short_id printString recordInfo.
1✔
834
                ^ aCommit diffs ].
1✔
835
        ('Import diff of commit: ' , aCommit short_id printString) recordInfo.
1✔
836

1✔
837
        result := self repoApi commits
1✔
838
                          diffOf: aCommit id
1✔
839
                          inProject: aCommit repository project id
1✔
840
                          uniDiff: true.
1✔
841

1✔
842
        (self isServerError: result) ifTrue: [ ^ {  } ].
1✔
843
        diffsResult := self newParseDiffResult: result.
1✔
844

1✔
845
        aCommit diffs addAll: diffsResult unless: self blockForDiffEquality.
1✔
846
        
1✔
847
        "changes are added into the model during the import"
1✔
848
        aCommit diffs do: [ :diff | self importDiffRangesForDiff: diff ].
1✔
849

1✔
850
        ^ aCommit diffs
1✔
851
]
1✔
852

1✔
853
{ #category : #'import - merge request' }
1✔
854
GitlabModelImporter >> importDiffOfMergeRequest: aMergeRequest [
1✔
855

1✔
856
        | result diffsResult |
1✔
857
        aMergeRequest diffs ifNotEmpty: [
1✔
858
                'Diff of already importer: '
1✔
859
                , aMergeRequest iid printString recordInfo.
1✔
860
                ^ aMergeRequest diffs ].
1✔
861
        ('Import diff commits of MR ' , aMergeRequest iid printString)
1✔
862
                recordInfo.
1✔
863
        result := self repoApi mergeRequests
1✔
864
                          diffsOf: aMergeRequest iid
1✔
865
                          inProject: aMergeRequest project_id.
1✔
866
        diffsResult := result flatCollect: [ :aResult |
1✔
867
                               self newParseDiffResult: aResult ].
1✔
868

1✔
869

1✔
870
        aMergeRequest diffs
1✔
871
                addAll: diffsResult
1✔
872
                unless: self blockForDiffEquality.
1✔
873
        self glhModel
1✔
874
                addAll: aMergeRequest diffs
1✔
875
                unless: self blockForDiffEquality.
1✔
876

1✔
877
        aMergeRequest diffs do: [ :diff | self importDiffRangesForDiff: diff ].
1✔
878

1✔
879
        ^ aMergeRequest diffs
1✔
880
]
1✔
881

1✔
882
{ #category : #'import - repositories' }
1✔
883
GitlabModelImporter >> importDirectoryFiles: aDirectoryFile OfBranch: aBranch [
1✔
884

1✔
885
        | result files apiFiles params |
1✔
886
        params := { 
1✔
887
                #ref -> aBranch name.
1✔
888
                #path -> (aDirectoryFile path , '/')
1✔
889
        } asDictionary.
1✔
890
        result := self repoApi repositories repositoryTreeOfProject: aBranch repository project id withParams: params.
1✔
891
                         " treeOfRepository: aBranch repository project id
1✔
892
                          ofBranch: aBranch name
1✔
893
                          andPath: aDirectoryFile path , '/'."
1✔
894
        apiFiles := (result collect: [ :treeJson | self parseFileTreeResult: treeJson ]) flattened.
1✔
895
        files := apiFiles collect: [ :apiFile |
1✔
896
                         self convertApiFileAsFile: apiFile ].
1✔
897
        
1✔
898
        files do: [ :file |
1✔
899
                self glhModel add: file.
1✔
900
                aDirectoryFile addFile: file ].
1✔
901
        
1✔
902
        files
1✔
903
                select: [ :file | file isKindOf: GLHFileDirectory ]
1✔
904
                thenCollect: [ :file |
1✔
905
                self importDirectoryFiles: file OfBranch: aBranch ]
1✔
906
]
1✔
907

1✔
908
{ #category : #'import - repositories' }
1✔
909
GitlabModelImporter >> importFilesOfBranch: aBranch [
1✔
910

1✔
911
        | result files apiFiles params |
1✔
912
        params := { 
1✔
913
                #ref -> aBranch name.
1✔
914
        } asDictionary.
1✔
915
        
1✔
916
        result := self repoApi repositories repositoryTreeOfProject: aBranch repository project id withParams: params.
1✔
917
        
1✔
918
                          "treeOfRepository: aBranch repository project id
1✔
919
                          ofBranch: aBranch name
1✔
920
                          andPath: nil."
1✔
921
        apiFiles := (result collect: [ :filesJson | self parseFileTreeResult: filesJson  ]) flattened.
1✔
922
        files := apiFiles collect: [ :apiFile | 
1✔
923
                         self convertApiFileAsFile: apiFile ].
1✔
924
        files do: [ :file | 
1✔
925
                self glhModel add: file.
1✔
926
                aBranch addFile: file ].
1✔
927
        files
1✔
928
                select: [ :file | file isKindOf: GLHFileDirectory ]
1✔
929
                thenCollect: [ :file | 
1✔
930
                self importDirectoryFiles: file OfBranch: aBranch ]
1✔
931
]
1✔
932

1✔
933
{ #category : #'import - groups' }
1✔
934
GitlabModelImporter >> importGroup: aGroupID [
1✔
935

1✔
936
        | result groupResult |
1✔
937
        ('Import group: ' , aGroupID printString) recordInfo.
1✔
938

1✔
939
        result := self repoApi groups get: aGroupID.
1✔
940
        
1✔
941
        "group: aGroupID."
1✔
942
        groupResult := self parseGroupResult: result.
1✔
943
        groupResult := self addGroupResultToModel: groupResult.
1✔
944

1✔
945
        groupResult projects do: [ :project |
1✔
946
                self completeImportedProject: project ].
1✔
947

1✔
948
        (self subGroupsOf: aGroupID) do: [ :subGroup |
1✔
949
                
1✔
950
                groupResult subGroups
1✔
951
                        add: (self importGroup: subGroup id)
1✔
952
                        unless: self blockOnIdEquality ].
1✔
953
        ^ groupResult
1✔
954
]
1✔
955

1✔
956
{ #category : #'import - jobs' }
1✔
957
GitlabModelImporter >> importJobsOf: aPipeline [
1✔
958

1✔
959
        | jobs results |
1✔
960
        results := self repoApi jobs
1✔
961
                           getAllForPipeline: aPipeline id
1✔
962
                           inProject: aPipeline project id.
1✔
963
        "jobsOfProject: aPipeline project id
1✔
964
                          ofPipelines: aPipeline id."
1✔
965
        jobs := (results collect: [ :jobsJson |
1✔
966
                         self parseJobsResult: jobsJson ofProject: aPipeline project ])
1✔
967
                        flattened.
1✔
968
        jobs do: [ :job | aPipeline addJob: job ].
1✔
969
        self glhModel addAll: jobs.
1✔
970

1✔
971
        ^ jobs
1✔
972
]
1✔
973

1✔
974
{ #category : #'import - commits' }
1✔
975
GitlabModelImporter >> importLastestCommitsOfProject: aGLHProject [
1✔
976
        "limited to the last 50 commits"
1✔
977

1✔
978
        | results parsedResults params |
1✔
979
        params := { 
1✔
980
                #with_stats -> 'true'.
1✔
981
                #all -> true
1✔
982
         } asDictionary.
1✔
983
        results := self repoApi commits getByPage: 1 perPage: 50 inProject: aGLHProject id withParams: params.
1✔
984

1✔
985
        parsedResults := self parseCommitsResult: results.
1✔
986
        parsedResults := self glhModel
1✔
987
                                 addAll: parsedResults
1✔
988
                                 unless: self blockOnIdEquality.
1✔
989

1✔
990
        aGLHProject repository commits
1✔
991
                addAll: parsedResults
1✔
992
                unless: self blockOnIdEquality.
1✔
993

1✔
994
        self withCommitDiffs ifTrue: [
1✔
995
                parsedResults do: [ :commit | self importDiffOfCommit: commit ] ].
1✔
996

1✔
997
        ^ parsedResults
1✔
998
]
1✔
999

1✔
1000
{ #category : #'import - merge request' }
1✔
1001
GitlabModelImporter >> importLatestMergeRequestsOfProject: aGLHProject [ 
1✔
1002
        
1✔
1003
        |results parsedResults|
1✔
1004
        results := self repoApi mergeRequests getByPage: 1 perPage: 20  inProject: aGLHProject id. 
1✔
1005
        parsedResults := self parseMergeRequestsResult: results. 
1✔
1006
        
1✔
1007
        parsedResults := glhModel addAll: parsedResults unless: self blockOnIdEquality.
1✔
1008
        parsedResults := aGLHProject mergeRequests addAll: parsedResults unless: self blockOnIdEquality.
1✔
1009
        ^ parsedResults.
1✔
1010
]
1✔
1011

1✔
1012
{ #category : #'import - pipelines' }
1✔
1013
GitlabModelImporter >> importLatestPipelinesOfProject: aGLHProject [ 
1✔
1014
        (self pipelinesOf: aGLHProject id withLimit:20) do: [ :pipeline |
1✔
1015
                |pip|
1✔
1016
                pip := self glhModel add: pipeline unless: self blockOnIdEquality .
1✔
1017
                pip := aGLHProject pipelines add: pip unless: self blockOnIdEquality.
1✔
1018
                self completeImportedPipeline: pip. 
1✔
1019
                ].
1✔
1020
        
1✔
1021
        ^ aGLHProject pipelines 
1✔
1022
]
1✔
1023

1✔
1024
{ #category : #'import - release' }
1✔
1025
GitlabModelImporter >> importLatestReleaseOfProject: aGLHProject [ 
1✔
1026
        
1✔
1027
        |result foundRelease|
1✔
1028
        result := repoApi releases getLatestOfProject: aGLHProject id.
1✔
1029
        foundRelease := self parseReleaseResult: result. 
1✔
1030

1✔
1031
        foundRelease := glhModel add: foundRelease unless: self blockOnNameEquality.
1✔
1032
        foundRelease := aGLHProject releases add: foundRelease unless: self blockOnNameEquality.
1✔
1033

1✔
1034
        foundRelease author: (self importUser: foundRelease author id). 
1✔
1035
        
1✔
1036
        ^ foundRelease.
1✔
1037
]
1✔
1038

1✔
1039
{ #category : #'import - merge request' }
1✔
1040
GitlabModelImporter >> importMergeRequestCommits: aGLPHEMergeRequest [
1✔
1041

1✔
1042
        | commits result |
1✔
1043
        aGLPHEMergeRequest commits ifNotNil: [ ^ aGLPHEMergeRequest commits ].
1✔
1044
        
1✔
1045
        result := self repoApi mergeRequests commitsOf: aGLPHEMergeRequest iid inProject: aGLPHEMergeRequest project id.
1✔
1046
        
1✔
1047
        commits := (result collect: [ :commitsJson | self parseCommitsResult: commitsJson ]) flattened.
1✔
1048
        commits := commits collect: [ :commit | self importCommit: commit id ofProject: aGLPHEMergeRequest project ].
1✔
1049
        aGLPHEMergeRequest commits: commits.
1✔
1050

1✔
1051

1✔
1052
        ^ commits
1✔
1053
]
1✔
1054

1✔
1055
{ #category : #'import - merge request' }
1✔
1056
GitlabModelImporter >> importMergeRequestMergeCommits: aGLPHEMergeRequest [
1✔
1057

1✔
1058
        | foundCommits |
1✔
1059
        foundCommits := OrderedCollection new.
1✔
1060

1✔
1061
        ('Import commit sha of MR:  ' , aGLPHEMergeRequest iid printString)
1✔
1062
                recordInfo.
1✔
1063
        "the founds commits are added to the model during their respective import"
1✔
1064
        aGLPHEMergeRequest mergeRequestCommit: ((self
1✔
1065
                          importCommitOfProject: aGLPHEMergeRequest project
1✔
1066
                          withId: aGLPHEMergeRequest sha) ifNotNil: [ :commit |
1✔
1067
                         foundCommits add: commit ]).
1✔
1068

1✔
1069
        ('Import commit merge_commit_sha of MR:  '
1✔
1070
         , aGLPHEMergeRequest iid printString) recordInfo.
1✔
1071
        aGLPHEMergeRequest mergedCommit: ((self
1✔
1072
                          importCommitOfProject: aGLPHEMergeRequest project
1✔
1073
                          withId: aGLPHEMergeRequest merge_commit_sha) ifNotNil: [ :commit |
1✔
1074
                         foundCommits add: commit ]).
1✔
1075

1✔
1076
        ('Import commit squash_commit_sha of MR:  '
1✔
1077
         , aGLPHEMergeRequest iid printString) recordInfo.
1✔
1078
        aGLPHEMergeRequest squashCommit: ((self
1✔
1079
                          importCommitOfProject: aGLPHEMergeRequest project
1✔
1080
                          withId: aGLPHEMergeRequest squash_commit_sha) ifNotNil: [ :commit |
1✔
1081
                         foundCommits add: commit ]).
1✔
1082

1✔
1083

1✔
1084
        self chainsCommitsFrom: foundCommits.
1✔
1085
        ^ foundCommits
1✔
1086
]
1✔
1087

1✔
1088
{ #category : #'import - pipelines' }
1✔
1089
GitlabModelImporter >> importMergeRequestPipelines: aGLHMergeRequest [ 
1✔
1090
        "default limit to one page with last 100 pipelines"
1✔
1091
        
1✔
1092
        |results parseResults|
1✔
1093
        
1✔
1094
        results := self repoApi pipelines getByPage: 1 perPage: 100 inProject: aGLHMergeRequest project id forMergerRequestIid: aGLHMergeRequest iid. 
1✔
1095
        
1✔
1096
        parseResults := self parsePipelinesResult: results.
1✔
1097
        
1✔
1098
        parseResults := glhModel addAll: parseResults unless: self blockOnIdEquality.
1✔
1099
        parseResults := aGLHMergeRequest pipelines addAll: parseResults unless: self blockOnIdEquality.
1✔
1100
        ^ parseResults collect: [ :pip | self completeImportedPipeline: pip ]  .
1✔
1101
        
1✔
1102
]
1✔
1103

1✔
1104
{ #category : #'import - merge request' }
1✔
1105
GitlabModelImporter >> importMergeRequests: aGLHProject [
1✔
1106

1✔
1107
        | results parsedResults mrs |
1✔
1108
        ('Import merge request of Project: ' , aGLHProject id printString)
1✔
1109
                recordInfo.
1✔
1110

1✔
1111
        results := self repoApi mergeRequests getAllOfProject: aGLHProject id.
1✔
1112
        parsedResults := (results collect: [ :projectsJson | self parseMergeRequestsResult: projectsJson ]) flattened. 
1✔
1113

1✔
1114
        aGLHProject mergeRequests
1✔
1115
                addAll: parsedResults
1✔
1116
                unless: self blockOnIdEquality.
1✔
1117

1✔
1118
        mrs := self glhModel
1✔
1119
                       addAll: aGLHProject mergeRequests
1✔
1120
                       unless: self blockOnIdEquality.
1✔
1121

1✔
1122

1✔
1123
        "gets it related commits"
1✔
1124
        aGLHProject mergeRequests do: [ :mr |
1✔
1125
                self importMergeRequestMergeCommits: mr ].
1✔
1126

1✔
1127

1✔
1128
        self withCommitDiffs ifTrue: [
1✔
1129
                aGLHProject mergeRequests do: [ :mr |
1✔
1130
                        self importDiffOfMergeRequest: mr ] ].
1✔
1131

1✔
1132
        ^ mrs
1✔
1133
]
1✔
1134

1✔
1135
{ #category : #'import - merge request' }
1✔
1136
GitlabModelImporter >> importMergeRequests: aGLHProject since: fromDate until: toDate [
1✔
1137

1✔
1138
        | params result mergeRequests |
1✔
1139
        ('import MR of Project ' , aGLHProject name) recordInfo.
1✔
1140
        params := {
1✔
1141
                          (#created_after
1✔
1142
                           ->
1✔
1143
                           (fromDate
1✔
1144
                                    ifNotNil: [ fromDate asDateAndTime asString ]
1✔
1145
                                    ifNil: [ '' ])).
1✔
1146
                          (#created_before
1✔
1147
                           ->
1✔
1148
                           (toDate
1✔
1149
                                    ifNotNil: [ toDate asDateAndTime asString ]
1✔
1150
                                    ifNil: [ '' ])).
1✔
1151
                          (#scope -> 'all') } asDictionary.
1✔
1152

1✔
1153
        result := self repoApi mergeRequests
1✔
1154
                          getAllOfProject: aGLHProject id
1✔
1155
                          withParams: params.
1✔
1156
        mergeRequests := (result collect: [ :mergeRequestsJson |
1✔
1157
                                  self parseMergeRequestsResult: mergeRequestsJson ])
1✔
1158
                                 flattened.
1✔
1159

1✔
1160
        aGLHProject mergeRequests
1✔
1161
                addAll: mergeRequests
1✔
1162
                unless: self blockOnIdEquality.
1✔
1163

1✔
1164
        "gets it related commits"
1✔
1165
        aGLHProject mergeRequests do: [ :mr |
1✔
1166
                self importMergeRequestMergeCommits: mr ].
1✔
1167

1✔
1168
        self withCommitDiffs ifTrue: [
1✔
1169
                aGLHProject mergeRequests do: [ :mr |
1✔
1170
                        self importDiffOfMergeRequest: mr ] ].
1✔
1171

1✔
1172
        self glhModel
1✔
1173
                addAll: mergeRequests
1✔
1174
                unless: (self blockEqualityOn: #iid).
1✔
1175

1✔
1176
        ^ mergeRequests
1✔
1177
]
1✔
1178

1✔
1179
{ #category : #'import - merge request' }
1✔
1180
GitlabModelImporter >> importMergeResquestApprovals: aGLPHEMergeRequest [
1✔
1181

1✔
1182
        | results parsedResult |
1✔
1183
        (String streamContents: [ :str |
1✔
1184
                 str << 'Check approvals of '.
1✔
1185
                 aGLPHEMergeRequest printOn: str ]) recordInfo.
1✔
1186
        results := self repoApi mergeRequests approvalsOf: aGLPHEMergeRequest iid inProject: aGLPHEMergeRequest project id.
1✔
1187

1✔
1188
        parsedResult := generalReader
1✔
1189
                                on: results readStream;
1✔
1190
                                next.
1✔
1191

1✔
1192
        (parsedResult at: #approved_by) do: [ :approvedUser |
1✔
1193
                aGLPHEMergeRequest addApproved_by:
1✔
1194
                        (self importUser: ((approvedUser at: #user) at: #id)) ].
1✔
1195
        aGLPHEMergeRequest approved: (parsedResult at: #approved).
1✔
1196
        ^ aGLPHEMergeRequest
1✔
1197
]
1✔
1198

1✔
1199
{ #category : #'import - merge request' }
1✔
1200
GitlabModelImporter >> importMergeResquestAuthor: aGLPHEMergeRequest [
1✔
1201

1✔
1202
        | authorID |
1✔
1203
        aGLPHEMergeRequest author ifNotNil: [ ^ aGLPHEMergeRequest author ].
1✔
1204
        authorID := aGLPHEMergeRequest cacheAt: #authorID ifAbsent: [
1✔
1205
                            | result |
1✔
1206
                            result := self repoApi mergeRequests
1✔
1207
                                              get: aGLPHEMergeRequest iid
1✔
1208
                                              inProject: aGLPHEMergeRequest project_id.
1✔
1209

1✔
1210
                            (generalReader
1✔
1211
                                     on: result readStream;
1✔
1212
                                     next) at: #author at: #id ].
1✔
1213
        ^aGLPHEMergeRequest author: (self importUser: authorID)
1✔
1214
]
1✔
1215

1✔
1216
{ #category : #'import - merge request' }
1✔
1217
GitlabModelImporter >> importMergeResquestMerger: aGLPHEMergeRequest [
1✔
1218

1✔
1219
        | authorID |
1✔
1220
        aGLPHEMergeRequest merge_user ifNotNil: [
1✔
1221
                ^ aGLPHEMergeRequest merge_user ].
1✔
1222
        authorID := aGLPHEMergeRequest cacheAt: #mergeUserID ifAbsent: [
1✔
1223
                            | result |
1✔
1224
                            result := self repoApi mergeRequests
1✔
1225
                                              get: aGLPHEMergeRequest iid
1✔
1226
                                              inProject: aGLPHEMergeRequest project_id.
1✔
1227
                            (generalReader
1✔
1228
                                     on: result readStream;
1✔
1229
                                     next)
1✔
1230
                                    at: #merge_user
1✔
1231
                                    ifPresent: [ :mergeUser |
1✔
1232
                                    mergeUser ifNotNil: [ :mruser | mruser at: #id ] ] ].
1✔
1233
        ^aGLPHEMergeRequest merge_user: (self importUser: authorID)
1✔
1234
]
1✔
1235

1✔
1236
{ #category : #'import - notes' }
1✔
1237
GitlabModelImporter >> importNotesfromMergeRequest: mergeRequest [
1✔
1238
        | results notes |
1✔
1239
        
1✔
1240
        results := self repoApi notes allInMergeRequest: mergeRequest iid ofProject: mergeRequest project id.
1✔
1241
        
1✔
1242
        notes := results collect: [ :note | 
1✔
1243
                self parseNoteJson: note ].
1✔
1244
        "notes := self parseNoteJson: results."
1✔
1245
        notes do: [ :tabNotes | tabNotes do: [ :note |
1✔
1246
                        note author: (self importUser: (note author at: #id)).
1✔
1247
                        note name: note id asString]. ].
1✔
1248
        notes := notes flattened.
1✔
1249
        notes := self glhModel addAll: notes unless: self blockOnIdEquality. 
1✔
1250
        notes := mergeRequest note addAll: notes unless: self blockOnIdEquality. 
1✔
1251
        ^notes
1✔
1252
        
1✔
1253
]
1✔
1254

1✔
1255
{ #category : #'import - commits' }
1✔
1256
GitlabModelImporter >> importParentCommitsOfCommit: aGLHCommit since: aDate [
1✔
1257

1✔
1258
        | parentsIds commits |
1✔
1259
        commits := OrderedCollection new.
1✔
1260
        aGLHCommit created_at asDateAndTime < aDate asDateAndTime ifTrue: [
1✔
1261
                 
1✔
1262
                ^ commits
1✔
1263
                          add: aGLHCommit;
1✔
1264
                          yourself ].
1✔
1265

1✔
1266
        parentsIds := aGLHCommit parent_ids.
1✔
1267

1✔
1268
        commits addAll: (parentsIds collect: [ :id |
1✔
1269
                         self
1✔
1270
                                 importCommitOfProject: aGLHCommit repository project
1✔
1271
                                 withId: id ]).
1✔
1272

1✔
1273

1✔
1274
        ^ (commits collect: [ :parentCommit |
1✔
1275
                   self importParentCommitsOfCommit: parentCommit since: aDate ])
1✔
1276
                  flatten
1✔
1277
]
1✔
1278

1✔
1279
{ #category : #'import - pipelines' }
1✔
1280
GitlabModelImporter >> importPipeline: pipelineId OfProject: aGLHProject [
1✔
1281

1✔
1282
        
1✔
1283
        | result pipeline|
1✔
1284
        
1✔
1285
        aGLHProject pipelines detect: [ :pip | pip id = pipelineId ] ifOne: [ :pip| ^pip ].
1✔
1286
        
1✔
1287
        ('Search pipelines of: ' , aGLHProject id printString) recordInfo.
1✔
1288
        result := self repoApi pipelines get: pipelineId inProject: aGLHProject id.
1✔
1289
        result isString ifTrue: [ ^ self parsePipelineResult: result ].
1✔
1290

1✔
1291
        pipeline :=  self parsePipelineResult: result.
1✔
1292

1✔
1293
        pipeline := self glhModel add: pipeline unless: self blockOnIdEquality .
1✔
1294
        pipeline := aGLHProject pipelines add: pipeline unless: self blockOnIdEquality.
1✔
1295
        
1✔
1296
        ^ self completeImportedPipeline: pipeline. 
1✔
1297
]
1✔
1298

1✔
1299
{ #category : #'import - pipelines' }
1✔
1300
GitlabModelImporter >> importPipelinesOfProject: aGLHProject after: after andBefore: before [
1✔
1301
        ^ (self pipelinesOf: aGLHProject id after: after andBefore: before) collect: [ :pipeline |
1✔
1302
                |pip|
1✔
1303
                pip := self glhModel add: pipeline unless: self blockOnIdEquality .
1✔
1304
                pip := aGLHProject pipelines add: pip unless: self blockOnIdEquality.
1✔
1305
                
1✔
1306
                ].
1✔
1307
        
1✔
1308
]
1✔
1309

1✔
1310
{ #category : #'import - pipelines' }
1✔
1311
GitlabModelImporter >> importPipelinesOfProject: aGLHProject after: after andBefore: before onBranch: aBranch [
1✔
1312
        | result parsedResults|
1✔
1313
        ('Search pipelines of: ' , aGLHProject id printString) recordInfo.
1✔
1314
        
1✔
1315
        result := self repoApi pipelines getAllInProject: aGLHProject id 
1✔
1316
                                                                                                withParams: {        #updated_before -> before.
1✔
1317
                                                                                                                                        #updated_after -> after.
1✔
1318
                                                                                                                                        #ref -> aBranch name} asDictionary .
1✔
1319
        result isString ifTrue: [ ^ self parsePipelinesResult: result ].
1✔
1320

1✔
1321
        parsedResults := (result collect: [ :pipelinesJson |
1✔
1322
                           self parsePipelinesResult: pipelinesJson ]) flattened.
1✔
1323
        
1✔
1324

1✔
1325
        ^ parsedResults collect: [ :pipeline |
1✔
1326
                |pip|
1✔
1327
                pip := self glhModel add: pipeline unless: self blockOnIdEquality .
1✔
1328
                aGLHProject pipelines add: pip unless: self blockOnIdEquality.
1✔
1329
                ].
1✔
1330
        
1✔
1331
]
1✔
1332

1✔
1333
{ #category : #'import - projects' }
1✔
1334
GitlabModelImporter >> importProject: aProjectID [
1✔
1335

1✔
1336
        | result projectResult |
1✔
1337
        ('Import project with id:  ' , aProjectID printString) recordInfo.
1✔
1338

1✔
1339
        (glhModel allWithType: GLHProject)
1✔
1340
                detect: [ :project | project id = aProjectID ]
1✔
1341
                ifFound: [ :project | ^ project ].
1✔
1342

1✔
1343
        result := self repoApi projects get: aProjectID.
1✔
1344
        projectResult := self parseProjectResult: result.
1✔
1345

1✔
1346
        ^ self completeImportedProject: projectResult
1✔
1347
]
1✔
1348

1✔
1349
{ #category : #'import - projects' }
1✔
1350
GitlabModelImporter >> importProjects [
1✔
1351

1✔
1352
        | result projects |
1✔
1353
        ('import all Projects') recordInfo.
1✔
1354

1✔
1355

1✔
1356
        result := self repoApi projects all.
1✔
1357
        projects := (result collect: [ :projectsJson | self parseArrayOfProject: projectsJson ]) flattened.
1✔
1358
        
1✔
1359
        self glhModel addAll: projects unless: self blockOnIdEquality.
1✔
1360

1✔
1361
        ^ projects
1✔
1362
]
1✔
1363

1✔
1364
{ #category : #'import - projects' }
1✔
1365
GitlabModelImporter >> importProjectsSince: since [
1✔
1366
        "heavy import of all projects"
1✔
1367

1✔
1368
        "copy import from commits"
1✔
1369

1✔
1370
        | newlyFoundProjects page foundProject amount |
1✔
1371
        ('import all Projects since: ' , since printString) recordInfo.
1✔
1372

1✔
1373
        "number of projects per page"
1✔
1374
        amount := 100.
1✔
1375
        page := 0.
1✔
1376
        foundProject := OrderedCollection new.
1✔
1377
        newlyFoundProjects := { true }.
1✔
1378
        [ newlyFoundProjects isNotEmpty ] whileTrue: [
1✔
1379
                | results |
1✔
1380
                page := page + 1.
1✔
1381
                ('import projects page #' , page printString) recordInfo.
1✔
1382

1✔
1383
                results := self repoApi projects allWithParams: {#since -> since} asDictionary .
1✔
1384

1✔
1385
                newlyFoundProjects := self glhModel
1✔
1386
                                              addAll: (self parseArrayOfProject: results)
1✔
1387
                                              unless: self blockOnIdEquality.
1✔
1388
                foundProject addAll: newlyFoundProjects ].
1✔
1389
]
1✔
1390

1✔
1391
{ #category : #'import - repositories' }
1✔
1392
GitlabModelImporter >> importRepository: aGLHRepository [
1✔
1393

1✔
1394
        | resultBranches branches |
1✔
1395
        [
1✔
1396
        ('import the repository of project ' , aGLHRepository project name)
1✔
1397
                recordInfo.
1✔
1398

1✔
1399
        resultBranches := self repoApi branches getAllFromProject:
1✔
1400
                                  aGLHRepository project id.
1✔
1401

1✔
1402
        branches := (resultBranches collect: [ :branchesJson |
1✔
1403
                             self parseBranchesResult: branchesJson ]) flattened.
1✔
1404

1✔
1405
        'import the branches of project ' recordInfo.
1✔
1406

1✔
1407
        branches := aGLHRepository branches
1✔
1408
                            addAll: branches
1✔
1409
                            unless: self blockOnNameEquality.
1✔
1410
        branches := self glhModel
1✔
1411
                            addAll: branches
1✔
1412
                            unless: self blockOnNameEquality.
1✔
1413

1✔
1414

1✔
1415
        self withFiles ifTrue: [
1✔
1416
                branches do: [ :branch | self importFilesOfBranch: branch ] ] ]
1✔
1417
                on: NeoJSONParseError
1✔
1418
                do: [
1✔
1419
                self inform: aGLHRepository project name , ' has no repository' ].
1✔
1420
        
1✔
1421
        withInitialCommits ifTrue: [
1✔
1422
                aGLHRepository branches do: [ :branch |
1✔
1423
                        self importCommitsOfBranch: branch ] ]
1✔
1424
]
1✔
1425

1✔
1426
{ #category : #'as yet unclassified' }
1✔
1427
GitlabModelImporter >> importSZZFromCommit: aCommit [
1✔
1428

1✔
1429
        | result diffRanges diffs szzCommits|
1✔
1430
        szzCommits := Set new. 
1✔
1431
        diffs := (self importDiffOfCommit: aCommit).
1✔
1432
        diffRanges := diffs flatCollect: #diffRanges.
1✔
1433
        diffRanges do: [ :range |
1✔
1434
                |blames|
1✔
1435
                
1✔
1436
                        blames := NeoJSONReader fromString:( self repoApi repositories getBlameOf: range diff new_path  inRef: aCommit id start: range start end:range end ofProject: (aCommit repository project id)).
1✔
1437
                        blames collect: [ :blame |
1✔
1438
                        blame isDictionary ifTrue: [ szzCommits add:         (self importCommit:(blame at: #commit at: #id) ofProject: aCommit repository project). ]
1✔
1439
                         
1✔
1440
                                 ]
1✔
1441
                        
1✔
1442
                 ].
1✔
1443
        ^ szzCommits .
1✔
1444

1✔
1445
]
1✔
1446

1✔
1447
{ #category : #'import - tag' }
1✔
1448
GitlabModelImporter >> importTagsForProject: aProject [ 
1✔
1449
        |results tags |
1✔
1450
        results  := repoApi tags getAllOfProject: aProject id.
1✔
1451
        "get a group of tags"
1✔
1452
        tags := results flatCollect: [ :result |
1✔
1453
                        self parseTagsResult: result. 
1✔
1454
                 ].
1✔
1455

1✔
1456
        tags := glhModel addAll: tags unless: self blockOnNameEquality.
1✔
1457
        tags := aProject repository tags addAll: tags unless: self blockOnNameEquality.
1✔
1458
        
1✔
1459
        "update tag's commit if already imported"
1✔
1460
        tags do: [ :tag |
1✔
1461
                |commit|
1✔
1462
                commit := glhModel add: tag commit unless: self blockOnIdEquality.
1✔
1463
                commit := aProject repository commits add: tag commit unless: self blockOnIdEquality.
1✔
1464
                tag commit: commit. 
1✔
1465
                 ].
1✔
1466
        
1✔
1467
        "update tag's release if already imported"
1✔
1468
        tags do: [ :tag |
1✔
1469
                |release|
1✔
1470
                release ifNotNil: [ 
1✔
1471
                        release := glhModel add: tag release unless: (self blockEqualityOn: #tag_name).
1✔
1472
                        release := aProject releases add: tag release unless: (self blockEqualityOn: #tag_name).
1✔
1473
                        tag release: release. 
1✔
1474
                         ].
1✔
1475
                 ].
1✔
1476
        
1✔
1477
        ^ tags
1✔
1478
]
1✔
1479

1✔
1480
{ #category : #'import - users' }
1✔
1481
GitlabModelImporter >> importUser: aUserID [
1✔
1482

1✔
1483
        | result userResult |
1✔
1484
        (self glhModel allWithType: GLHUser)
1✔
1485
                detect: [ :user | user id = aUserID ]
1✔
1486
                ifFound: [ :user | ^ user ].
1✔
1487
        ('Import user: ' , aUserID printString) recordInfo.
1✔
1488
        
1✔
1489
        result := self repoApi users get: aUserID.
1✔
1490
        userResult := self parseUserResult: result.
1✔
1491
        
1✔
1492
        userResult := self glhModel add: userResult unless: self blockOnIdEquality.
1✔
1493
        userCatalogue addUser: userResult.
1✔
1494
        ^ userResult 
1✔
1495
]
1✔
1496

1✔
1497
{ #category : #'import - users' }
1✔
1498
GitlabModelImporter >> importUserByUsername: anUsername [
1✔
1499

1✔
1500
        | dicUsername resultUser |
1✔
1501
        dicUsername := ((self glhModel allWithType: GLHUser) collect: [ :user |
1✔
1502
                                user username -> user ]) asSet asDictionary.
1✔
1503

1✔
1504
        dicUsername addAll: self userCatalogue collectUsernames.
1✔
1505

1✔
1506

1✔
1507
        resultUser := dicUsername
1✔
1508
                              at: anUsername
1✔
1509
                              ifAbsent: [ "thus we have to import this new user"
1✔
1510
                                      | result userId searchResult params |
1✔
1511
                                      ('Import user with username: '
1✔
1512
                                       , anUsername printString) recordInfo.
1✔
1513
                                      params := { (#search -> anUsername) } asDictionary.
1✔
1514
                                      result := self repoApi users allWithParams: params.
1✔
1515
                                                        
1✔
1516
                                                         "when result is an error"
1✔
1517
                                                         (result isString) ifTrue: [ result := { result } ].
1✔
1518
                                                        
1✔
1519
                                      searchResult := result ifEmpty: [ result ] ifNotEmpty: [(result collect: [ :usersJson |
1✔
1520
                                                               NeoJSONReader fromString: usersJson ]) first].
1✔
1521
                                                         
1✔
1522
                                      (searchResult class = Dictionary and: [
1✔
1523
                                               (searchResult at: #message) includesSubstring:
1✔
1524
                                                       '403 Forbidden' ])
1✔
1525
                                              ifTrue: [ "if the result is an 403 error we fake a new user"
1✔
1526
                                                      self glhModel
1✔
1527
                                                              add: (GLHUser new
1✔
1528
                                                                               username: anUsername;
1✔
1529
                                                                               name: anUsername;
1✔
1530
                                                                               yourself)
1✔
1531
                                                              unless: [ :nu :ou | nu username = ou username ] ]
1✔
1532
                                              ifFalse: [
1✔
1533
                                                      searchResult
1✔
1534
                                                              ifEmpty: [ "results can be empty thus we force a new user with the info we have "
1✔
1535
                                                                      self glhModel
1✔
1536
                                                                              add: (GLHUser new
1✔
1537
                                                                                               username: anUsername;
1✔
1538
                                                                                               name: anUsername;
1✔
1539
                                                                                               yourself)
1✔
1540
                                                                              unless: [ :nu :ou | nu username = ou username ] ]
1✔
1541
                                                              ifNotEmpty: [ "because we may already have the researched user, we look by ID in the model"
1✔
1542
                                                                      userId := searchResult first at: #id.
1✔
1543
                                                                      (self glhModel allWithType: GLHUser)
1✔
1544
                                                                              detect: [ :user | user id = userId ]
1✔
1545
                                                                              ifNone: [ self importUser: userId ] ] ] ].
1✔
1546

1✔
1547
        self userCatalogue addUser: resultUser withName: anUsername.
1✔
1548

1✔
1549
        ^ resultUser
1✔
1550
]
1✔
1551

1✔
1552
{ #category : #initialization }
1✔
1553
GitlabModelImporter >> initReader [
1✔
1554

1✔
1555
        generalReader := NeoJSONReader new.
1✔
1556
        self configureReaderForCommit: generalReader.
1✔
1557
        self configureReaderForGroup: generalReader.
1✔
1558
        self configureReaderForDiffs: generalReader.
1✔
1559
        self configureReaderForMergeRequest: generalReader.
1✔
1560
        self configureReaderForPipeline: generalReader. 
1✔
1561
        self configureReaderForTags: generalReader. 
1✔
1562
        self configureReaderForReleases: generalReader. 
1✔
1563
        self configureReaderForUsers: generalReader. 
1✔
1564
]
1✔
1565

1✔
1566
{ #category : #initialization }
1✔
1567
GitlabModelImporter >> initialize [
1✔
1568

1✔
1569
        super initialize.
1✔
1570
        withCommitDiffs := true.
1✔
1571
        withInitialCommits := false.
1✔
1572
        withInitialMergeRequest := false.
1✔
1573

1✔
1574
        self withCommitsSince: 1 week.
1✔
1575

1✔
1576
        self initReader
1✔
1577
]
1✔
1578

1✔
1579
{ #category : #private }
1✔
1580
GitlabModelImporter >> isServerError: aString [
1✔
1581
        ^ aString = '{"message":"500 Internal Server Error"}'
1✔
1582
]
1✔
1583

1✔
1584
{ #category : #'import - projects' }
1✔
1585
GitlabModelImporter >> loadAllProjectsFromRepositorySoftware [
1✔
1586
        "heavy import that load all the active project inside the model. Only import the project entities"
1✔
1587
        |projects|
1✔
1588
        
1✔
1589
        projects := self repoApi projects. 
1✔
1590
]
1✔
1591

1✔
1592
{ #category : #'private - parsing' }
1✔
1593
GitlabModelImporter >> newParseCommitResult: result [
1✔
1594

1✔
1595
        generalReader  on: result readStream.
1✔
1596

1✔
1597
        ^ generalReader nextAs: GLHCommit
1✔
1598
]
1✔
1599

1✔
1600
{ #category : #'private - parsing' }
1✔
1601
GitlabModelImporter >> newParseDiffResult: result [
1✔
1602

1✔
1603
        generalReader on: result readStream.
1✔
1604
        ^ generalReader nextAs: #ArrayOfDiffs
1✔
1605
]
1✔
1606

1✔
1607
{ #category : #'private - parsing' }
1✔
1608
GitlabModelImporter >> parseArrayOfProject: arrayOfProjects [
1✔
1609

1✔
1610
        | reader |
1✔
1611
        reader := NeoJSONReader on: arrayOfProjects readStream.
1✔
1612
        reader
1✔
1613
                for: #ArrayOfProjects
1✔
1614
                customDo: [ :customMappting |
1✔
1615
                customMappting listOfElementSchema: GLHProject ].
1✔
1616
        reader for: GLHProject do: [ :mapping |
1✔
1617
                mapping mapInstVar: #name to: #name.
1✔
1618
                mapping mapInstVar: #description to: #description.
1✔
1619
                mapping mapInstVar: #id to: #id.
1✔
1620
                mapping mapInstVar: #archived to: #archived.
1✔
1621
                mapping mapInstVar: #web_url to: #html_url.
1✔
1622
                mapping mapInstVar: #topics to: #topics ].
1✔
1623
        ^ reader nextAs: #ArrayOfProjects
1✔
1624
]
1✔
1625

1✔
1626
{ #category : #'private - parsing' }
1✔
1627
GitlabModelImporter >> parseBranchesResult: result [
1✔
1628

1✔
1629
        | reader |
1✔
1630
        reader := NeoJSONReader on: result readStream.
1✔
1631
        reader mapInstVarsFor: GLHBranch.
1✔
1632
        reader
1✔
1633
                for: #ArrayOfBranch
1✔
1634
                customDo: [ :customMappting | 
1✔
1635
                customMappting listOfElementSchema: GLHBranch ].
1✔
1636
        ^ reader nextAs: #ArrayOfBranch
1✔
1637
]
1✔
1638

1✔
1639
{ #category : #'private - parsing' }
1✔
1640
GitlabModelImporter >> parseCommitResult: result [
1✔
1641

1✔
1642
        | reader |
1✔
1643
        reader := NeoJSONReader on: result readStream.
1✔
1644

1✔
1645
        reader for: GLHCommit do: [ :mapping |
1✔
1646
                mapping mapInstVars:
1✔
1647
                        #( id short_id title author_name author_email committer_name
1✔
1648
                           committer_email message web_url ).
1✔
1649
                (mapping mapInstVar: #authored_date) valueSchema: DateAndTime.
1✔
1650
                (mapping mapInstVar: #committed_date) valueSchema: DateAndTime.
1✔
1651
                (mapping mapInstVar: #created_at) valueSchema: DateAndTime.
1✔
1652
                (mapping mapInstVar: #parent_ids) valueSchema: #ArrayOfIds.
1✔
1653
                mapping
1✔
1654
                        mapProperty: 'stats'
1✔
1655
                        getter: [ :el | "Not used" ]
1✔
1656
                        setter: [ :commit :value |
1✔
1657
                                commit deletions: (value at: #deletions).
1✔
1658
                                commit additions: (value at: #additions) ] ].
1✔
1659

1✔
1660
        reader for: DateAndTime customDo: [ :mapping |
1✔
1661
                mapping decoder: [ :string | DateAndTime fromString: string ] ].
1✔
1662

1✔
1663
        reader
1✔
1664
                for: #ArrayOfIds
1✔
1665
                customDo: [ :mapping | mapping decoder: [ :string | string ] ].
1✔
1666

1✔
1667

1✔
1668
        ^ reader nextAs: GLHCommit
1✔
1669
]
1✔
1670

1✔
1671
{ #category : #'private - parsing' }
1✔
1672
GitlabModelImporter >> parseCommitsResult: result [
1✔
1673

1✔
1674
        | reader |
1✔
1675
        reader := NeoJSONReader on: result readStream.
1✔
1676

1✔
1677
          reader for: GLHCommit do: [ :mapping |
1✔
1678
                mapping mapInstVars:
1✔
1679
                        #( id short_id title author_name author_email committer_name
1✔
1680
                           committer_email message web_url ).
1✔
1681
                (mapping mapInstVar: #authored_date) valueSchema: DateAndTime.
1✔
1682
                (mapping mapInstVar: #committed_date) valueSchema: DateAndTime.
1✔
1683
                (mapping mapInstVar: #created_at) valueSchema: DateAndTime.
1✔
1684
                (mapping mapInstVar: #parent_ids) valueSchema: #ArrayOfIds.
1✔
1685
                mapping
1✔
1686
                        mapProperty: 'stats'
1✔
1687
                        getter: [ :el | "Not used" ]
1✔
1688
                        setter: [ :commit :value |
1✔
1689
                                commit deletions: (value at: #deletions).
1✔
1690
                                commit additions: (value at: #additions) ] ].
1✔
1691

1✔
1692
        reader for: DateAndTime customDo: [ :mapping |
1✔
1693
                mapping decoder: [ :string | DateAndTime fromString: string ] ].
1✔
1694

1✔
1695
        reader
1✔
1696
                for: #ArrayOfIds
1✔
1697
                customDo: [ :mapping | mapping decoder: [ :string | string ] ].
1✔
1698
  
1✔
1699
        reader
1✔
1700
                for: #ArrayOfCommit
1✔
1701
                customDo: [ :customMappting |
1✔
1702
                customMappting listOfElementSchema: GLHCommit ].
1✔
1703

1✔
1704
        ^ reader nextAs: #ArrayOfCommit
1✔
1705
]
1✔
1706

1✔
1707
{ #category : #private }
1✔
1708
GitlabModelImporter >> parseDiffResult: result [
1✔
1709

1✔
1710
        | reader |
1✔
1711
        self
1✔
1712
                deprecated: 'Use #newParseDiffResult: instead'
1✔
1713
                on: '28 June 2024'
1✔
1714
                in:
1✔
1715
                'Pharo-11.0.0+build.726.sha.aece1b5473acf3830a0e082c1bc3a15d4ff3522b (64 Bit)'.
1✔
1716
        reader := NeoJSONReader on: result readStream.
1✔
1717
        reader for: GLHDiff do: [ :mapping |
1✔
1718
                mapping mapInstVars:
1✔
1719
                        #( deleted_file new_file new_path old_path renamed_file ).
1✔
1720
                mapping mapInstVar: #diffString to: #diff ].
1✔
1721

1✔
1722
        reader
1✔
1723
                for: #ArrayOfDiffs
1✔
1724
                customDo: [ :customMappting |
1✔
1725
                customMappting listOfElementSchema: GLHDiff ].
1✔
1726
        ^ reader nextAs: #ArrayOfDiffs
1✔
1727
]
1✔
1728

1✔
1729
{ #category : #'private - parsing' }
1✔
1730
GitlabModelImporter >> parseFileTreeResult: aResult [
1✔
1731

1✔
1732
        | reader |
1✔
1733
        reader := NeoJSONReader on: aResult readStream.
1✔
1734
        reader mapInstVarsFor: GLHApiFile.
1✔
1735
        reader
1✔
1736
                for: #ArrayOfFile
1✔
1737
                customDo: [ :customMappting | 
1✔
1738
                customMappting listOfElementSchema: GLHApiFile ].
1✔
1739
        ^ reader nextAs: #ArrayOfFile
1✔
1740
]
1✔
1741

1✔
1742
{ #category : #'private - parsing' }
1✔
1743
GitlabModelImporter >> parseGroupResult: aResult [
1✔
1744

1✔
1745
        | reader |
1✔
1746

1✔
1747
        reader := NeoJSONReader on: aResult readStream.
1✔
1748
        reader for: GLHGroup do: [ :mapping |
1✔
1749
                mapping mapInstVars.
1✔
1750
                (mapping mapInstVar: #projects) valueSchema: #ArrayOfProjects ].
1✔
1751
        reader mapInstVarsFor: GLHProject.
1✔
1752
        reader
1✔
1753
                for: #ArrayOfProjects
1✔
1754
                customDo: [ :customMappting |
1✔
1755
                customMappting listOfElementSchema: GLHProject ].
1✔
1756
        ^ reader nextAs: GLHGroup
1✔
1757
]
1✔
1758

1✔
1759
{ #category : #'private - parsing' }
1✔
1760
GitlabModelImporter >> parseJobsResult: result ofProject: aProject [
1✔
1761

1✔
1762
        | reader |
1✔
1763
        reader := NeoJSONReader on: result readStream.
1✔
1764
        reader for: GLHJob do: [ :mapping |
1✔
1765
                mapping mapInstVars: #( id allow_failure web_url name ).
1✔
1766

1✔
1767
                mapping
1✔
1768
                        mapProperty: #user
1✔
1769
                        getter: [ :object | #ignore ]
1✔
1770
                        setter: [ :object :value |
1✔
1771
                        object user: (self importUser: (value at: #id)) ].
1✔
1772

1✔
1773
                mapping
1✔
1774
                        mapProperty: #commit
1✔
1775
                        getter: [ :object | #ignore ]
1✔
1776
                        setter: [ :object :value |
1✔
1777
                                value ifNotNil: [
1✔
1778
                                        object commit:
1✔
1779
                                                (self importCommit: (value at: #id) ofProject: aProject) ] ].
1✔
1780

1✔
1781
                mapping
1✔
1782
                        mapProperty: #duration
1✔
1783
                        getter: [ :object | #ignore ]
1✔
1784
                        setter: [ :object :value |
1✔
1785
                        value ifNotNil: [ object duration: value seconds ] ] ].
1✔
1786

1✔
1787
        reader
1✔
1788
                for: #ArrayOfGLHJob
1✔
1789
                customDo: [ :customMappting |
1✔
1790
                customMappting listOfElementSchema: GLHJob ].
1✔
1791
        ^ reader nextAs: #ArrayOfGLHJob
1✔
1792
]
1✔
1793

1✔
1794
{ #category : #'private - parsing' }
1✔
1795
GitlabModelImporter >> parseMergeRequestsResult: result [
1✔
1796

1✔
1797
        generalReader on: result readStream.
1✔
1798
        ^ generalReader nextAs: #ArrayOfMergeRequest
1✔
1799
]
1✔
1800

1✔
1801
{ #category : #'private - parsing' }
1✔
1802
GitlabModelImporter >> parseNoteJson: results [  
1✔
1803
    | reader |  
1✔
1804

1✔
1805
    "Créer un lecteur JSON"
1✔
1806
    reader := NeoJSONReader on: results readStream.    
1✔
1807

1✔
1808
    "Définir le mapping pour l'objet GLHNote"
1✔
1809
    reader for: GLHNote do: [ :mapping |  
1✔
1810
        mapping mapInstVars: #(id noteable_id attachment system confidential internal  
1✔
1811
                               noteable_iid resolvable imported imported_from  
1✔
1812
                               author body project_id noteable_type).  
1✔
1813

1✔
1814
        (mapping mapInstVar: #created_at) valueSchema: DateAndTime.  
1✔
1815
        (mapping mapInstVar: #updated_at) valueSchema: DateAndTime.  
1✔
1816
    ].    
1✔
1817

1✔
1818
    "Corriger la conversion des dates"
1✔
1819
    reader for: DateAndTime customDo: [ :mapping |  
1✔
1820
        mapping decoder: [ :string | DateAndTime readFrom: string readStream ] ].
1✔
1821

1✔
1822
        reader
1✔
1823
                for: #ArrayOfNote
1✔
1824
                customDo: [ :customMappting | 
1✔
1825
                customMappting listOfElementSchema: GLHNote ].
1✔
1826
         ^ reader nextAs: #ArrayOfNote
1✔
1827

1✔
1828
    "Retourner la Note"
1✔
1829
    "^ reader nextAs: GLHNote"
1✔
1830

1✔
1831

1✔
1832
]
1✔
1833

1✔
1834
{ #category : #'private - parsing' }
1✔
1835
GitlabModelImporter >> parsePipelineResult: result [
1✔
1836

1✔
1837
        | reader |
1✔
1838
        
1✔
1839
        (result includesSubstring: '{"message":"40' )ifTrue: [ ^ {  } ].
1✔
1840
        
1✔
1841
        reader := generalReader on: result readStream.
1✔
1842
        
1✔
1843
        ^ reader nextAs: GLHPipeline
1✔
1844
]
1✔
1845

1✔
1846
{ #category : #'private - parsing' }
1✔
1847
GitlabModelImporter >> parsePipelinesResult: result [
1✔
1848

1✔
1849
        | reader |
1✔
1850
        
1✔
1851
        (result includesSubstring: '{"message":"40' )ifTrue: [ ^ {  } ].
1✔
1852
        
1✔
1853
        reader := generalReader on: result readStream.
1✔
1854
        
1✔
1855
        ^ reader nextAs: #ArrayOfPipelines
1✔
1856
]
1✔
1857

1✔
1858
{ #category : #'private - parsing' }
1✔
1859
GitlabModelImporter >> parseProjectResult: aResult [ 
1✔
1860
                | reader |
1✔
1861
        reader := NeoJSONReader on: aResult readStream.
1✔
1862
        reader for: GLHProject do: [ :mapping |
1✔
1863
                mapping mapInstVars. ].
1✔
1864
"        reader mapInstVarsFor: GLHProject."
1✔
1865

1✔
1866
        ^ reader nextAs: GLHProject
1✔
1867
]
1✔
1868

1869
{ #category : #parsing }
1870
GitlabModelImporter >> parseReleaseResult: result [
×
1871
        |reader|
×
1872
        reader := generalReader on: result readStream.
×
1873
        
×
UNCOV
1874
        ^ reader nextAs: GLHRelease 
×
UNCOV
1875
]
×
1876

1877
{ #category : #parsing }
1878
GitlabModelImporter >> parseReleasesResult: result [
×
1879
        |reader|
×
1880
        reader := generalReader on: result readStream.
×
1881
        
×
UNCOV
1882
        ^ reader nextAs: #ArrayOfReleases
×
UNCOV
1883
]
×
1884

1885
{ #category : #'private - parsing' }
1886
GitlabModelImporter >> parseSubGroupResult: aResult [
×
1887

×
1888
        | reader |
×
1889
        reader := NeoJSONReader on: aResult readStream.
×
1890
        self configureReaderForGroup: reader.
×
UNCOV
1891
        ^ reader nextAs: #ArrayOfGroups
×
UNCOV
1892
]
×
1893

1894
{ #category : #parsing }
1895
GitlabModelImporter >> parseTagsResult: result [
×
1896
        |reader|
×
1897
        reader := generalReader on: result readStream.
×
1898
        
×
UNCOV
1899
        ^ reader nextAs: #ArrayOfTags
×
UNCOV
1900
]
×
1901

1902
{ #category : #'private - parsing' }
1903
GitlabModelImporter >> parseUserResult: result [
1✔
1904

1✔
1905
        | reader |
1✔
1906
        
1✔
1907
        reader := generalReader on: result readStream.
1✔
1908
        
1✔
1909
        ^ reader nextAs: GLHUser
1✔
1910

1✔
1911
        
1✔
1912

1✔
1913
]
1✔
1914

1915
{ #category : #'private - parsing' }
1916
GitlabModelImporter >> parseUsersResult: result [
×
1917

×
1918
        | reader |
×
1919
        
×
1920
        reader := generalReader on: result readStream.
×
1921
        
×
1922
        ^ reader nextAs: #ArrayOfUser
×
UNCOV
1923
        
×
UNCOV
1924
]
×
1925

1926
{ #category : #'import - projects' }
1927
GitlabModelImporter >> partiallyImportProject: aProjectID [
×
1928

×
1929
        | result projectResult |
×
1930
        ('Import project with id:  ' , aProjectID printString) recordInfo.
×
1931

×
1932
        (glhModel allWithType: GLHProject)
×
1933
                detect: [ :project | project id = aProjectID ]
×
1934
                ifFound: [ :project | ^ project ].
×
1935

×
1936
        result := self repoApi projects get: aProjectID.
×
1937
        projectResult := self parseProjectResult: result.
×
1938

×
1939
        projectResult repository: GLHRepository new.
×
1940
        self glhModel add: projectResult repository.
×
1941
        self importRepository: projectResult repository.
×
1942

×
UNCOV
1943
        ^ projectResult
×
UNCOV
1944
]
×
1945

1946
{ #category : #'import - pipelines' }
1947
GitlabModelImporter >> pipelinesOf: aProjectID after: after andBefore: before [
×
1948

×
1949
        | result |
×
1950
        ('Search pipelines of: ' , aProjectID printString) recordInfo.
×
1951
        
×
1952
        result := self repoApi pipelines getAllInProject: aProjectID 
×
1953
                                                                                                withParams: {        #updated_before -> before.
×
1954
                                                                                                                                        #updated_after -> after} asDictionary .
×
1955
        result isString ifTrue: [ ^ self parsePipelinesResult: result ].
×
1956

×
1957
        ^ (result collect: [ :pipelinesJson |
×
UNCOV
1958
                           self parsePipelinesResult: pipelinesJson ]) flattened
×
UNCOV
1959
]
×
1960

1961
{ #category : #'import - pipelines' }
1962
GitlabModelImporter >> pipelinesOf: aProjectID withLimit: aLimit [
1✔
1963

1✔
1964
        | result |
1✔
1965
        ('Search pipelines of: ' , aProjectID printString) recordInfo.
1✔
1966
        result := self repoApi pipelines getByPage: 1 perPage: aLimit inProject: aProjectID.
1✔
1967
        result isString ifTrue: [ ^ self parsePipelinesResult: result ].
1✔
1968

1✔
1969
        ^ (result collect: [ :pipelinesJson |
1✔
1970
                           self parsePipelinesResult: pipelinesJson ]) flattened
1✔
1971
]
1✔
1972

1973
{ #category : #accessing }
1974
GitlabModelImporter >> repoApi: anObject [
1✔
1975
        super repoApi: anObject.
1✔
1976
        self repoApi output: 'json'
1✔
1977
]
1✔
1978

1979
{ #category : #'search - merge request' }
1980
GitlabModelImporter >> searchMergeRequestMentionning: aString [ 
×
1981
        |mergeRequests results|
×
1982
        results := repoApi mergeRequests search: aString.
×
1983
        mergeRequests := self parseMergeRequestsResult: results.
×
1984
        mergeRequests :=        mergeRequests collect: [ :mr |
×
1985
                mr project: (self importProject: mr project_id).
×
1986
                mr
×
1987
                 ].
×
1988
        
×
UNCOV
1989
        ^ glhModel addAll: mergeRequests unless: self blockOnIdEquality. 
×
UNCOV
1990
]
×
1991

1992
{ #category : #private }
1993
GitlabModelImporter >> selectEntityType: aType overAttribut: aSelector equalTo: value [
×
1994

×
1995
        ^ (self glhModel allWithType: aType)
×
UNCOV
1996
                select: [ :entity | (entity perform: aSelector) = value ]
×
UNCOV
1997
]
×
1998

1999
{ #category : #'import - groups' }
2000
GitlabModelImporter >> subGroupsOf: aGroupID [
1✔
2001

1✔
2002
        | results subgroups |
1✔
2003
        ('Search subgroup of: ' , aGroupID printString) recordInfo.
1✔
2004
        results := self repoApi groups subgroupsOf: aGroupID.
1✔
2005
        subgroups := (results collect: [ :subgroupsJson | self parseSubGroupResult: subgroupsJson ]) flattened.
1✔
2006
        
1✔
2007
        ^ subgroups
1✔
2008
]
1✔
2009

2010
{ #category : #accessing }
2011
GitlabModelImporter >> withInitialCommits: boolean [
×
UNCOV
2012
        withInitialCommits := boolean 
×
UNCOV
2013
]
×
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