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

moosetechnology / GitProjectHealth / 16137171919

08 Jul 2025 07:46AM UTC coverage: 74.618% (-0.3%) from 74.906%
16137171919

Pull #216

github

web-flow
Merge 57cb7e5f5 into a000fd4b3
Pull Request #216: add issue class in model

8 of 208 new or added lines in 3 files covered. (3.85%)

62 existing lines in 3 files now uncovered.

17595 of 23580 relevant lines covered (74.62%)

0.75 hits per line

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

90.45
/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 diffsOf: aMergeRequest iid inProject: aMergeRequest project_id.
1✔
864

1✔
865
        diffsResult := self newParseDiffResult: result anyOne.
1✔
866

1✔
867

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

1✔
875
        aMergeRequest diffs do: [ :diff | self importDiffRangesForDiff: diff ].
1✔
876

1✔
877
        ^ aMergeRequest diffs
1✔
878
]
1✔
879

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

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

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

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

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

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

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

1✔
943
        groupResult projects do: [ :project |
1✔
944
                self completeImportedProject: project ].
1✔
945

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

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

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

1✔
969
        ^ jobs
1✔
970
]
1✔
971

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

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

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

1✔
988
        aGLHProject repository commits
1✔
989
                addAll: parsedResults
1✔
990
                unless: self blockOnIdEquality.
1✔
991

1✔
992
        self withCommitDiffs ifTrue: [
1✔
993
                parsedResults do: [ :commit | self importDiffOfCommit: commit ] ].
1✔
994

1✔
995
        ^ parsedResults
1✔
996
]
1✔
997

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

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

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

1✔
1029
        foundRelease := glhModel add: foundRelease unless: self blockOnNameEquality.
1✔
1030
        foundRelease := aGLHProject releases add: foundRelease unless: self blockOnNameEquality.
1✔
1031

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

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

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

1✔
1049

1✔
1050
        ^ commits
1✔
1051
]
1✔
1052

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

1✔
1056
        | foundCommits |
1✔
1057
        foundCommits := OrderedCollection new.
1✔
1058

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

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

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

1✔
1081

1✔
1082
        self chainsCommitsFrom: foundCommits.
1✔
1083
        ^ foundCommits
1✔
1084
]
1✔
1085

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

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

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

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

1✔
1112
        aGLHProject mergeRequests
1✔
1113
                addAll: parsedResults
1✔
1114
                unless: self blockOnIdEquality.
1✔
1115

1✔
1116
        mrs := self glhModel
1✔
1117
                       addAll: aGLHProject mergeRequests
1✔
1118
                       unless: self blockOnIdEquality.
1✔
1119

1✔
1120

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

1✔
1125

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

1✔
1130
        ^ mrs
1✔
1131
]
1✔
1132

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

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

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

1✔
1158
        aGLHProject mergeRequests
1✔
1159
                addAll: mergeRequests
1✔
1160
                unless: self blockOnIdEquality.
1✔
1161

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

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

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

1✔
1174
        ^ mergeRequests
1✔
1175
]
1✔
1176

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

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

1✔
1186
        parsedResult := generalReader
1✔
1187
                                on: results readStream;
1✔
1188
                                next.
1✔
1189

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

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

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

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

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

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

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

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

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

1✔
1264
        parentsIds := aGLHCommit parent_ids.
1✔
1265

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

1✔
1271

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

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

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

1✔
1289
        pipeline :=  self parsePipelineResult: result.
1✔
1290

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

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

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

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

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

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

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

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

1✔
1341
        result := self repoApi projects get: aProjectID.
1✔
1342
        projectResult := self parseProjectResult: result.
1✔
1343

1✔
1344
        ^ self completeImportedProject: projectResult
1✔
1345
]
1✔
1346

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

1✔
1350
        | result projects |
1✔
1351
        ('import all Projects') recordInfo.
1✔
1352

1✔
1353

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

1✔
1359
        ^ projects
1✔
1360
]
1✔
1361

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

1✔
1366
        "copy import from commits"
1✔
1367

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

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

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

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

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

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

1✔
1397
        resultBranches := self repoApi branches getAllFromProject:
1✔
1398
                                  aGLHRepository project id.
1✔
1399

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

1✔
1403
        'import the branches of project ' recordInfo.
1✔
1404

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

1✔
1412

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

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

1✔
1427
        | result diffRanges diffs szzCommits|
1✔
1428
        szzCommits := Set new. 
1✔
1429
        diffs := (self importDiffOfCommit: aCommit).
1✔
1430
        diffRanges := diffs flatCollect: #diffRanges.
1✔
1431
        diffRanges do: [ :range |
1✔
1432
                |blames|
1✔
1433
                
1✔
1434
                        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✔
1435
                        blames collect: [ :blame |
1✔
1436
                         szzCommits add:         (self importCommit:(blame at: #commit at: #id) ofProject: aCommit repository project).
1✔
1437
                                 ]
1✔
1438
                        
1✔
1439
                 ].
1✔
1440
        ^ szzCommits .
1✔
1441

1✔
1442
]
1✔
1443

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

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

1✔
1477
{ #category : #'import - users' }
1✔
1478
GitlabModelImporter >> importUser: aUserID [
1✔
1479

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

1✔
1494
{ #category : #'import - users' }
1✔
1495
GitlabModelImporter >> importUserByUsername: anUsername [
1✔
1496

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

1✔
1501
        dicUsername addAll: self userCatalogue collectUsernames.
1✔
1502

1✔
1503

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

1✔
1544
        self userCatalogue addUser: resultUser withName: anUsername.
1✔
1545

1✔
1546
        ^ resultUser
1✔
1547
]
1✔
1548

1✔
1549
{ #category : #initialization }
1✔
1550
GitlabModelImporter >> initReader [
1✔
1551

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

1✔
1563
{ #category : #initialization }
1✔
1564
GitlabModelImporter >> initialize [
1✔
1565

1✔
1566
        super initialize.
1✔
1567
        withCommitDiffs := true.
1✔
1568
        withInitialCommits := false.
1✔
1569
        withInitialMergeRequest := false.
1✔
1570

1✔
1571
        self withCommitsSince: 1 week.
1✔
1572

1✔
1573
        self initReader
1✔
1574
]
1✔
1575

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

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

1✔
1589
{ #category : #'private - parsing' }
1✔
1590
GitlabModelImporter >> newParseCommitResult: result [
1✔
1591

1✔
1592
        generalReader  on: result readStream.
1✔
1593

1✔
1594
        ^ generalReader nextAs: GLHCommit
1✔
1595
]
1✔
1596

1✔
1597
{ #category : #'private - parsing' }
1✔
1598
GitlabModelImporter >> newParseDiffResult: result [
1✔
1599

1✔
1600
        generalReader on: result readStream.
1✔
1601
        ^ generalReader nextAs: #ArrayOfDiffs
1✔
1602
]
1✔
1603

1✔
1604
{ #category : #'private - parsing' }
1✔
1605
GitlabModelImporter >> parseArrayOfProject: arrayOfProjects [
1✔
1606

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

1✔
1623
{ #category : #'private - parsing' }
1✔
1624
GitlabModelImporter >> parseBranchesResult: result [
1✔
1625

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

1✔
1636
{ #category : #'private - parsing' }
1✔
1637
GitlabModelImporter >> parseCommitResult: result [
1✔
1638

1✔
1639
        | reader |
1✔
1640
        reader := NeoJSONReader on: result readStream.
1✔
1641

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

1✔
1657
        reader for: DateAndTime customDo: [ :mapping |
1✔
1658
                mapping decoder: [ :string | DateAndTime fromString: string ] ].
1✔
1659

1✔
1660
        reader
1✔
1661
                for: #ArrayOfIds
1✔
1662
                customDo: [ :mapping | mapping decoder: [ :string | string ] ].
1✔
1663

1✔
1664

1✔
1665
        ^ reader nextAs: GLHCommit
1✔
1666
]
1✔
1667

1✔
1668
{ #category : #'private - parsing' }
1✔
1669
GitlabModelImporter >> parseCommitsResult: result [
1✔
1670

1✔
1671
        | reader |
1✔
1672
        reader := NeoJSONReader on: result readStream.
1✔
1673

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

1✔
1689
        reader for: DateAndTime customDo: [ :mapping |
1✔
1690
                mapping decoder: [ :string | DateAndTime fromString: string ] ].
1✔
1691

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

1✔
1701
        ^ reader nextAs: #ArrayOfCommit
1✔
1702
]
1✔
1703

1✔
1704
{ #category : #private }
1✔
1705
GitlabModelImporter >> parseDiffResult: result [
1✔
1706

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

1✔
1719
        reader
1✔
1720
                for: #ArrayOfDiffs
1✔
1721
                customDo: [ :customMappting |
1✔
1722
                customMappting listOfElementSchema: GLHDiff ].
1✔
1723
        ^ reader nextAs: #ArrayOfDiffs
1✔
1724
]
1✔
1725

1✔
1726
{ #category : #'private - parsing' }
1✔
1727
GitlabModelImporter >> parseFileTreeResult: aResult [
1✔
1728

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

1✔
1739
{ #category : #'private - parsing' }
1✔
1740
GitlabModelImporter >> parseGroupResult: aResult [
1✔
1741

1✔
1742
        | reader |
1✔
1743

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

1✔
1756
{ #category : #'private - parsing' }
1✔
1757
GitlabModelImporter >> parseJobsResult: result ofProject: aProject [
1✔
1758

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

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

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

1✔
1778
                mapping
1✔
1779
                        mapProperty: #duration
1✔
1780
                        getter: [ :object | #ignore ]
1✔
1781
                        setter: [ :object :value |
1✔
1782
                        value ifNotNil: [ object duration: value seconds ] ] ].
1✔
1783

1✔
1784
        reader
1✔
1785
                for: #ArrayOfGLHJob
1✔
1786
                customDo: [ :customMappting |
1✔
1787
                customMappting listOfElementSchema: GLHJob ].
1✔
1788
        ^ reader nextAs: #ArrayOfGLHJob
1✔
1789
]
1✔
1790

1✔
1791
{ #category : #'private - parsing' }
1✔
1792
GitlabModelImporter >> parseMergeRequestsResult: result [
1✔
1793

1✔
1794
        generalReader on: result readStream.
1✔
1795
        ^ generalReader nextAs: #ArrayOfMergeRequest
1✔
1796
]
1✔
1797

1✔
1798
{ #category : #'private - parsing' }
1✔
1799
GitlabModelImporter >> parseNoteJson: results [  
1✔
1800
    | reader |  
1✔
1801

1✔
1802
    "Créer un lecteur JSON"
1✔
1803
    reader := NeoJSONReader on: results readStream.    
1✔
1804

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

1✔
1811
        (mapping mapInstVar: #created_at) valueSchema: DateAndTime.  
1✔
1812
        (mapping mapInstVar: #updated_at) valueSchema: DateAndTime.  
1✔
1813
    ].    
1✔
1814

1✔
1815
    "Corriger la conversion des dates"
1✔
1816
    reader for: DateAndTime customDo: [ :mapping |  
1✔
1817
        mapping decoder: [ :string | DateAndTime readFrom: string readStream ] ].
1✔
1818

1✔
1819
        reader
1✔
1820
                for: #ArrayOfNote
1✔
1821
                customDo: [ :customMappting | 
1✔
1822
                customMappting listOfElementSchema: GLHNote ].
1✔
1823
         ^ reader nextAs: #ArrayOfNote
1✔
1824

1✔
1825
    "Retourner la Note"
1✔
1826
    "^ reader nextAs: GLHNote"
1✔
1827

1✔
1828

1✔
1829
]
1✔
1830

1✔
1831
{ #category : #'private - parsing' }
1✔
1832
GitlabModelImporter >> parsePipelineResult: result [
1✔
1833

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

1✔
1843
{ #category : #'private - parsing' }
1✔
1844
GitlabModelImporter >> parsePipelinesResult: result [
1✔
1845

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

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

1✔
1863
        ^ reader nextAs: GLHProject
1✔
1864
]
1✔
1865

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

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

1882
{ #category : #'private - parsing' }
UNCOV
1883
GitlabModelImporter >> parseSubGroupResult: aResult [
×
UNCOV
1884

×
UNCOV
1885
        | reader |
×
UNCOV
1886
        reader := NeoJSONReader on: aResult readStream.
×
UNCOV
1887
        self configureReaderForGroup: reader.
×
UNCOV
1888
        ^ reader nextAs: #ArrayOfGroups
×
UNCOV
1889
]
×
1890

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

1899
{ #category : #'private - parsing' }
1900
GitlabModelImporter >> parseUserResult: result [
1✔
1901

1✔
1902
        | reader |
1✔
1903
        
1✔
1904
        reader := generalReader on: result readStream.
1✔
1905
        
1✔
1906
        ^ reader nextAs: GLHUser
1✔
1907

1✔
1908
        
1✔
1909

1✔
1910
]
1✔
1911

1912
{ #category : #'private - parsing' }
1913
GitlabModelImporter >> parseUsersResult: result [
×
1914

×
1915
        | reader |
×
1916
        
×
1917
        reader := generalReader on: result readStream.
×
1918
        
×
1919
        ^ reader nextAs: #ArrayOfUser
×
1920
        
×
1921
]
×
1922

1923
{ #category : #'import - projects' }
1924
GitlabModelImporter >> partiallyImportProject: aProjectID [
×
1925

×
1926
        | result projectResult |
×
1927
        ('Import project with id:  ' , aProjectID printString) recordInfo.
×
1928

×
1929
        (glhModel allWithType: GLHProject)
×
1930
                detect: [ :project | project id = aProjectID ]
×
1931
                ifFound: [ :project | ^ project ].
×
1932

×
1933
        result := self repoApi projects get: aProjectID.
×
1934
        projectResult := self parseProjectResult: result.
×
1935

×
1936
        projectResult repository: GLHRepository new.
×
UNCOV
1937
        self glhModel add: projectResult repository.
×
UNCOV
1938
        self importRepository: projectResult repository.
×
UNCOV
1939

×
UNCOV
1940
        ^ projectResult
×
UNCOV
1941
]
×
1942

1943
{ #category : #'import - pipelines' }
UNCOV
1944
GitlabModelImporter >> pipelinesOf: aProjectID after: after andBefore: before [
×
UNCOV
1945

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

×
UNCOV
1954
        ^ (result collect: [ :pipelinesJson |
×
UNCOV
1955
                           self parsePipelinesResult: pipelinesJson ]) flattened
×
UNCOV
1956
]
×
1957

1958
{ #category : #'import - pipelines' }
1959
GitlabModelImporter >> pipelinesOf: aProjectID withLimit: aLimit [
1✔
1960

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

1✔
1966
        ^ (result collect: [ :pipelinesJson |
1✔
1967
                           self parsePipelinesResult: pipelinesJson ]) flattened
1✔
1968
]
1✔
1969

1970
{ #category : #accessing }
1971
GitlabModelImporter >> repoApi: anObject [
1✔
1972
        super repoApi: anObject.
1✔
1973
        self repoApi output: 'json'
1✔
1974
]
1✔
1975

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

1989
{ #category : #private }
1990
GitlabModelImporter >> selectEntityType: aType overAttribut: aSelector equalTo: value [
×
UNCOV
1991

×
UNCOV
1992
        ^ (self glhModel allWithType: aType)
×
UNCOV
1993
                select: [ :entity | (entity perform: aSelector) = value ]
×
UNCOV
1994
]
×
1995

1996
{ #category : #'import - groups' }
1997
GitlabModelImporter >> subGroupsOf: aGroupID [
1✔
1998

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

2007
{ #category : #accessing }
UNCOV
2008
GitlabModelImporter >> withInitialCommits: boolean [
×
UNCOV
2009
        withInitialCommits := boolean 
×
UNCOV
2010
]
×
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