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

moosetechnology / GitProjectHealth / 15776545908

20 Jun 2025 10:07AM UTC coverage: 74.916% (+0.5%) from 74.453%
15776545908

Pull #209

github

web-flow
Merge pull request #213 from moosetechnology/more-test-notes

add the massively important asFloat....
Pull Request #209: Update with correct average for notes

681 of 1102 new or added lines in 10 files covered. (61.8%)

52 existing lines in 2 files now uncovered.

17567 of 23449 relevant lines covered (74.92%)

0.75 hits per line

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

90.31
/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 - commits' }
1✔
555
GitlabModelImporter >> importCommit: aCommitID ofProject: aGLHProject [
1✔
556

1✔
557
        | result parsedResult |
1✔
558
        (self glhModel allWithType: GLHCommit) asOrderedCollection
1✔
559
                detect: [ :commit | commit id = aCommitID ]
1✔
560
                ifFound: [ :commit | ^ commit ].
1✔
561
        result := self repoApi commits get: aCommitID inProject: aGLHProject id.
1✔
562
        
1✔
563
        parsedResult := self parseCommitResult: result.
1✔
564
        
1✔
565
        self
1✔
566
                addCommits: { parsedResult }
1✔
567
                toRepository: aGLHProject repository.
1✔
568
        ^ parsedResult
1✔
569
]
1✔
570

1✔
571
{ #category : #'import - commits' }
1✔
572
GitlabModelImporter >> importCommitOfProject: anProject withId: anID [
1✔
573

1✔
574
        | commit result |
1✔
575
        anID ifNil: [ ^ nil ].
1✔
576

1✔
577
        ('looking for commit ' , anID printString , ' in project : '
1✔
578
         , anProject id printString) recordInfo.
1✔
579

1✔
580
        commit := (self
1✔
581
                           detectEntityType: GLHCommit
1✔
582
                           overAttribut: #id
1✔
583
                           equalTo: anID) ifNil: [
1✔
584
                          result := self repoApi commits get: anID inProject: anProject id.
1✔
585
                          commit := (self parseCommitsResult: '[' , result , ']')
1✔
586
                                            first.
1✔
587

1✔
588
                          self glhModel add: commit unless: self blockOnIdEquality.
1✔
589
                          commit repository: anProject repository.
1✔
590

1✔
591
                          commit ].
1✔
592

1✔
593
        self withCommitDiffs ifTrue: [ self importDiffOfCommit: commit ].
1✔
594

1✔
595
        ^ commit
1✔
596
]
1✔
597

1✔
598
{ #category : #'import - commits' }
1✔
599
GitlabModelImporter >> importCommits: aGLHProject [
1✔
600
        "limited to the last 20 commits"
1✔
601

1✔
602
        | results parsedResults params |
1✔
603
        params := { 
1✔
604
         #with_stats -> 'true'
1✔
605
        } asDictionary.
1✔
606
        results := self repoApi commits getByPage: 1 perPage: 20 inProject: aGLHProject id withParams: params.
1✔
607
        
1✔
608
        parsedResults := self parseCommitsResult: results.
1✔
609
        self glhModel addAll: parsedResults unless: self blockOnIdEquality.
1✔
610

1✔
611
        parsedResults do: [ :commit |
1✔
612
                commit repository: aGLHProject repository ].
1✔
613

1✔
614
        self withCommitDiffs ifTrue: [
1✔
615
                parsedResults do: [ :commit | self importDiffOfCommit: commit ] ].
1✔
616
        
1✔
617
        ^ parsedResults. 
1✔
618
]
1✔
619

1✔
620
{ #category : #'import - commits' }
1✔
621
GitlabModelImporter >> importCommitsFollowing: aCommit upToDays: aNumberOfDay [
1✔
622
        "import the 'n' commits of a project starting from an initial 'aCommit' commit. 
1✔
623
        Lazy import does not import the entities inside the model"
1✔
624

1✔
625
        | date |
1✔
626
        date := aCommit created_at asDateAndTime.
1✔
627

1✔
628
        ^ self
1✔
629
                  importCommitsOfBranch: aCommit branch
1✔
630
                  forRefName: aCommit branch name
1✔
631
                  since: date
1✔
632
                  until: (date + aNumberOfDay day)
1✔
633
]
1✔
634

1✔
635
{ #category : #commit }
1✔
636
GitlabModelImporter >> importCommitsOf: aGLHProject withStats: aBoolean until: toDate [
1✔
637

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

1✔
665
                newlyFoundCommit := parsedResults reject: [ :commitParsed |
1✔
666
                                            (toDate isNil or: [
1✔
667
                                                     commitParsed committed_date
1✔
668
                                                     < toDate asDateAndTime ]) or: [
1✔
669
                                                    existingCommits anySatisfy: [ :existingCommit |
1✔
670
                                                            existingCommit id = commitParsed id ] ] ].
1✔
671
                aGLHProject mooseModel addAll: newlyFoundCommit.
1✔
672
                aGLHProject repository commits addAll: newlyFoundCommit ].
1✔
673

1✔
674

1✔
675
        self withCommitDiffs ifTrue: [
1✔
676
                aGLHProject repository commits do: [ :commit |
1✔
677
                        self importDiffOfCommit: commit ] ]
1✔
678
]
1✔
679

1✔
680
{ #category : #'import - commits' }
1✔
681
GitlabModelImporter >> importCommitsOfBranch: aGLHBranch [
1✔
682

1✔
683
        | commits |
1✔
684
        "        result := self glhApi
1✔
685
                          commitsOfProject: aGLHBranch repository project id
1✔
686
                          forRefName: aGLHBranch name."
1✔
687
        commits := self
1✔
688
                           importCommitsOfBranch: aGLHBranch
1✔
689
                           forRefName: aGLHBranch name
1✔
690
                           since: withCommitsSince.
1✔
691

1✔
692
        self chainsCommitsFrom: commits.
1✔
693

1✔
694
        commits do: [ :aCommit |
1✔
695
                aCommit repository: aGLHBranch repository.
1✔
696
                self completeImportedCommit: aCommit. 
1✔
697
                 ]
1✔
698
]
1✔
699

1✔
700
{ #category : #'import - commits' }
1✔
701
GitlabModelImporter >> importCommitsOfBranch: aGLHBranch forRefName: refName since: fromDate [
1✔
702

1✔
703
        ^ self
1✔
704
                  importCommitsOfBranch: aGLHBranch
1✔
705
                  forRefName: aGLHBranch name
1✔
706
                  since: fromDate
1✔
707
                  until: nil
1✔
708
]
1✔
709

1✔
710
{ #category : #'import - commits' }
1✔
711
GitlabModelImporter >> importCommitsOfBranch: aGLHBranch forRefName: refName since: fromDate until: toDate [
1✔
712

1✔
713
        | params result allCommits |
1✔
714
        params := { 
1✔
715
          #ref_name -> aGLHBranch name.
1✔
716
          #since ->  (fromDate ifNotNil: [ fromDate asDate asDateAndTime asString ] ifNil: [ '' ]).
1✔
717
          #until -> (toDate ifNotNil: [ toDate asDate asDateAndTime asString ] ifNil: [ '' ]). 
1✔
718

1✔
719
        } asDictionary.
1✔
720
        result := self repoApi commits getAllInProject: aGLHBranch repository project id withParams: params.
1✔
721
        
1✔
722
        allCommits := (result collect: [ :commitsJson | self parseCommitsResult: commitsJson ]) flattened.
1✔
723
        
1✔
724
        aGLHBranch commits
1✔
725
                        addAll: allCommits
1✔
726
                        unless: self blockOnIdEquality.
1✔
727

1✔
728
        self glhModel
1✔
729
                addAll: aGLHBranch commits
1✔
730
                unless: self blockOnIdEquality.
1✔
731

1✔
732
        ^ allCommits
1✔
733
]
1✔
734

1✔
735
{ #category : #'import - commits' }
1✔
736
GitlabModelImporter >> importCommitsOfBranch: aGLHBranch forRefName: refName until: toDate [
1✔
737

1✔
738
        ^ self
1✔
739
                  importCommitsOfBranch: aGLHBranch
1✔
740
                  forRefName: aGLHBranch name
1✔
741
                  since: nil
1✔
742
                  until: toDate
1✔
743
]
1✔
744

1✔
745
{ #category : #'import - commits' }
1✔
746
GitlabModelImporter >> importCommitsOfProject: aProject since: fromDate until: toDate [
1✔
747

1✔
748
        | params results allCommits |
1✔
749
        params := {
1✔
750
                          (#since
1✔
751
                           ->
1✔
752
                           (fromDate
1✔
753
                                    ifNotNil: [ fromDate asDate asDateAndTime asString ]
1✔
754
                                    ifNil: [ '' ])).
1✔
755
                          (#until
1✔
756
                           ->
1✔
757
                           (toDate
1✔
758
                                    ifNotNil: [ toDate asDate asDateAndTime asString ]
1✔
759
                                    ifNil: [ '' ])).
1✔
760
                          (#with_stats -> 'true').
1✔
761
                          (#all -> 'true') } asDictionary.
1✔
762
        results := self repoApi commits
1✔
763
                           getAllInProject: aProject id
1✔
764
                           withParams: params.
1✔
765

1✔
766
        allCommits := (results collect: [ :commitsJson |
1✔
767
                               self parseCommitsResult: commitsJson ]) flattened.
1✔
768

1✔
769
        allCommits:= aProject repository commits
1✔
770
                addAll: allCommits
1✔
771
                unless: self blockOnIdEquality.
1✔
772

1✔
773
        ^ self glhModel addAll: allCommits unless: self blockOnIdEquality
1✔
774
]
1✔
775

1✔
776
{ #category : #'import - projects' }
1✔
777
GitlabModelImporter >> importContributedProjectsOfUser: aGLHUser [
1✔
778

1✔
779
        | remaningProjects params results projects projectsIds |
1✔
780
        params := {
1✔
781
                          (#order_by -> 'last_activity_at').
1✔
782
                          (#simple -> 'true') } asDictionary.
1✔
783
        results := self repoApi projects
1✔
784
                           contributedProjectsOfUser: aGLHUser id
1✔
785
                           withParams: params.
1✔
786

1✔
787
        projectsIds := (results collect: [ :projectsJson |
1✔
788
                             (NeoJSONReader fromString: projectsJson) collect: [:projectJson | projectJson at: #id ] ]) flattened.
1✔
789
        
1✔
790
        projects := self importProjects: projectsIds.
1✔
791
        remaningProjects := self importProjects:
1✔
792
                                    ((projects collect: #id) difference:
1✔
793
                                             ((self userCatalogue atId: aGLHUser id) at:
1✔
794
                                                      #contributedProjects)).
1✔
795

1✔
796

1✔
797
        aGLHUser contributedProjects
1✔
798
                addAll: projects , remaningProjects
1✔
799
                unless: self blockOnIdEquality.
1✔
800

1✔
801
        self userCatalogue
1✔
802
                addUser: aGLHUser
1✔
803
                withProjects: (aGLHUser contributedProjects collect: #id).
1✔
804

1✔
805
        ^ projects
1✔
806
]
1✔
807

1✔
808
{ #category : #'import - commits' }
1✔
809
GitlabModelImporter >> importCreatorOfCommit: aCommit [
1✔
810

1✔
811
        aCommit commitCreator ifNil: [
1✔
812
                aCommit commitCreator:
1✔
813
                        (self importUserByUsername: aCommit author_name) ].
1✔
814
        self userCatalogue
1✔
815
                addUser: aCommit commitCreator
1✔
816
                withProject: aCommit repository project id.
1✔
817
        ^ aCommit commitCreator
1✔
818
]
1✔
819

1✔
820
{ #category : #'import - commits' }
1✔
821
GitlabModelImporter >> importDiffOfCommit: aCommit [
1✔
822

1✔
823
        | result diffsResult |
1✔
824
        aCommit diffs ifNotEmpty: [
1✔
825
                'Diff already importer: ' , aCommit short_id printString recordInfo.
1✔
826
                ^ aCommit diffs ].
1✔
827
        ('Import diff of commit: ' , aCommit short_id printString) recordInfo.
1✔
828

1✔
829
        result := self repoApi commits
1✔
830
                          diffOf: aCommit id
1✔
831
                          inProject: aCommit repository project id
1✔
832
                          uniDiff: true.
1✔
833

1✔
834
        (self isServerError: result) ifTrue: [ ^ {  } ].
1✔
835
        diffsResult := self newParseDiffResult: result.
1✔
836

1✔
837
        aCommit diffs addAll: diffsResult unless: self blockForDiffEquality.
1✔
838
        
1✔
839
        "changes are added into the model during the import"
1✔
840
        aCommit diffs do: [ :diff | self importDiffRangesForDiff: diff ].
1✔
841

1✔
842
        ^ aCommit diffs
1✔
843
]
1✔
844

1✔
845
{ #category : #'import - merge request' }
1✔
846
GitlabModelImporter >> importDiffOfMergeRequest: aMergeRequest [
1✔
847

1✔
848
        | result diffsResult |
1✔
849
        aMergeRequest diffs ifNotEmpty: [
1✔
850
                'Diff of already importer: '
1✔
851
                , aMergeRequest iid printString recordInfo.
1✔
852
                ^ aMergeRequest diffs ].
1✔
853
        ('Import diff commits of MR ' , aMergeRequest iid printString)
1✔
854
                recordInfo.
1✔
855
        result := self repoApi mergeRequests diffsOf: aMergeRequest iid inProject: aMergeRequest project_id.
1✔
856

1✔
857
        diffsResult := self newParseDiffResult: result anyOne.
1✔
858

1✔
859

1✔
860
        aMergeRequest diffs
1✔
861
                addAll: diffsResult
1✔
862
                unless: self blockForDiffEquality.
1✔
863
        self glhModel
1✔
864
                addAll: aMergeRequest diffs
1✔
865
                unless: self blockForDiffEquality.
1✔
866

1✔
867
        aMergeRequest diffs do: [ :diff | self importDiffRangesForDiff: diff ].
1✔
868

1✔
869
        ^ aMergeRequest diffs
1✔
870
]
1✔
871

1✔
872
{ #category : #'import - repositories' }
1✔
873
GitlabModelImporter >> importDirectoryFiles: aDirectoryFile OfBranch: aBranch [
1✔
874

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

1✔
898
{ #category : #'import - repositories' }
1✔
899
GitlabModelImporter >> importFilesOfBranch: aBranch [
1✔
900

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

1✔
923
{ #category : #'import - groups' }
1✔
924
GitlabModelImporter >> importGroup: aGroupID [
1✔
925

1✔
926
        | result groupResult |
1✔
927
        ('Import group: ' , aGroupID printString) recordInfo.
1✔
928

1✔
929
        result := self repoApi groups get: aGroupID.
1✔
930
        
1✔
931
        "group: aGroupID."
1✔
932
        groupResult := self parseGroupResult: result.
1✔
933
        groupResult := self addGroupResultToModel: groupResult.
1✔
934

1✔
935
        groupResult projects do: [ :project |
1✔
936
                self completeImportedProject: project ].
1✔
937

1✔
938
        (self subGroupsOf: aGroupID) do: [ :subGroup |
1✔
939
                
1✔
940
                groupResult subGroups
1✔
941
                        add: (self importGroup: subGroup id)
1✔
942
                        unless: self blockOnIdEquality ].
1✔
943
        ^ groupResult
1✔
944
]
1✔
945

1✔
946
{ #category : #'import - jobs' }
1✔
947
GitlabModelImporter >> importJobsOf: aPipeline [
1✔
948

1✔
949
        | jobs results |
1✔
950
        results := self repoApi jobs
1✔
951
                           getAllForPipeline: aPipeline id
1✔
952
                           inProject: aPipeline project id.
1✔
953
        "jobsOfProject: aPipeline project id
1✔
954
                          ofPipelines: aPipeline id."
1✔
955
        jobs := (results collect: [ :jobsJson |
1✔
956
                         self parseJobsResult: jobsJson ofProject: aPipeline project ])
1✔
957
                        flattened.
1✔
958
        jobs do: [ :job | aPipeline addJob: job ].
1✔
959
        self glhModel addAll: jobs.
1✔
960

1✔
961
        ^ jobs
1✔
962
]
1✔
963

1✔
964
{ #category : #'import - commits' }
1✔
965
GitlabModelImporter >> importLastestCommitsOfProject: aGLHProject [
1✔
966
        "limited to the last 50 commits"
1✔
967

1✔
968
        | results parsedResults params |
1✔
969
        params := { 
1✔
970
                #with_stats -> 'true'.
1✔
971
                #all -> true
1✔
972
         } asDictionary.
1✔
973
        results := self repoApi commits getByPage: 1 perPage: 50 inProject: aGLHProject id withParams: params.
1✔
974

1✔
975
        parsedResults := self parseCommitsResult: results.
1✔
976
        parsedResults := self glhModel
1✔
977
                                 addAll: parsedResults
1✔
978
                                 unless: self blockOnIdEquality.
1✔
979

1✔
980
        aGLHProject repository commits
1✔
981
                addAll: parsedResults
1✔
982
                unless: self blockOnIdEquality.
1✔
983

1✔
984
        self withCommitDiffs ifTrue: [
1✔
985
                parsedResults do: [ :commit | self importDiffOfCommit: commit ] ].
1✔
986

1✔
987
        ^ parsedResults
1✔
988
]
1✔
989

1✔
990
{ #category : #'import - merge request' }
1✔
991
GitlabModelImporter >> importLatestMergeRequestsOfProject: aGLHProject [ 
1✔
992
        
1✔
993
        |results parsedResults|
1✔
994
        results := self repoApi mergeRequests getByPage: 1 perPage: 20  inProject: aGLHProject id. 
1✔
995
        parsedResults := self parseMergeRequestsResult: results. 
1✔
996
        
1✔
997
        parsedResults := glhModel addAll: parsedResults unless: self blockOnIdEquality.
1✔
998
        parsedResults := aGLHProject mergeRequests addAll: parsedResults unless: self blockOnIdEquality.
1✔
999
        ^ parsedResults.
1✔
1000
]
1✔
1001

1✔
1002
{ #category : #'import - pipelines' }
1✔
1003
GitlabModelImporter >> importLatestPipelinesOfProject: aGLHProject [ 
1✔
1004
        (self pipelinesOf: aGLHProject id withLimit:20) do: [ :pipeline |
1✔
1005
                |pip|
1✔
1006
                pip := self glhModel add: pipeline unless: self blockOnIdEquality .
1✔
1007
                pip := aGLHProject pipelines add: pip unless: self blockOnIdEquality.
1✔
1008
                self completeImportedPipeline: pip. 
1✔
1009
                ].
1✔
1010
        
1✔
1011
        ^ aGLHProject pipelines 
1✔
1012
]
1✔
1013

1✔
1014
{ #category : #'import - release' }
1✔
1015
GitlabModelImporter >> importLatestReleaseOfProject: aGLHProject [ 
1✔
1016
        
1✔
1017
        |result foundRelease|
1✔
1018
        result := repoApi releases getLatestOfProject: aGLHProject id.
1✔
1019
        foundRelease := self parseReleaseResult: result. 
1✔
1020

1✔
1021
        foundRelease := glhModel add: foundRelease unless: self blockOnNameEquality.
1✔
1022
        foundRelease := aGLHProject releases add: foundRelease unless: self blockOnNameEquality.
1✔
1023

1✔
1024
        foundRelease author: (self importUser: foundRelease author id). 
1✔
1025
        
1✔
1026
        ^ foundRelease.
1✔
1027
]
1✔
1028

1✔
1029
{ #category : #'import - merge request' }
1✔
1030
GitlabModelImporter >> importMergeRequestCommits: aGLPHEMergeRequest [
1✔
1031

1✔
1032
        | commits result |
1✔
1033
        aGLPHEMergeRequest commits ifNotNil: [ ^ aGLPHEMergeRequest commits ].
1✔
1034
        
1✔
1035
        result := self repoApi mergeRequests commitsOf: aGLPHEMergeRequest iid inProject: aGLPHEMergeRequest project id.
1✔
1036
        
1✔
1037
        commits := (result collect: [ :commitsJson | self parseCommitsResult: commitsJson ]) flattened.
1✔
1038
        commits := commits collect: [ :commit | self importCommit: commit id ofProject: aGLPHEMergeRequest project ].
1✔
1039
        aGLPHEMergeRequest commits: commits.
1✔
1040

1✔
1041

1✔
1042
        ^ commits
1✔
1043
]
1✔
1044

1✔
1045
{ #category : #'import - merge request' }
1✔
1046
GitlabModelImporter >> importMergeRequestMergeCommits: aGLPHEMergeRequest [
1✔
1047

1✔
1048
        | foundCommits |
1✔
1049
        foundCommits := OrderedCollection new.
1✔
1050

1✔
1051
        ('Import commit sha of MR:  ' , aGLPHEMergeRequest iid printString)
1✔
1052
                recordInfo.
1✔
1053
        "the founds commits are added to the model during their respective import"
1✔
1054
        aGLPHEMergeRequest mergeRequestCommit: ((self
1✔
1055
                          importCommitOfProject: aGLPHEMergeRequest project
1✔
1056
                          withId: aGLPHEMergeRequest sha) ifNotNil: [ :commit |
1✔
1057
                         foundCommits add: commit ]).
1✔
1058

1✔
1059
        ('Import commit merge_commit_sha of MR:  '
1✔
1060
         , aGLPHEMergeRequest iid printString) recordInfo.
1✔
1061
        aGLPHEMergeRequest mergedCommit: ((self
1✔
1062
                          importCommitOfProject: aGLPHEMergeRequest project
1✔
1063
                          withId: aGLPHEMergeRequest merge_commit_sha) ifNotNil: [ :commit |
1✔
1064
                         foundCommits add: commit ]).
1✔
1065

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

1✔
1073

1✔
1074
        self chainsCommitsFrom: foundCommits.
1✔
1075
        ^ foundCommits
1✔
1076
]
1✔
1077

1✔
1078
{ #category : #'import - pipelines' }
1✔
1079
GitlabModelImporter >> importMergeRequestPipelines: aGLHMergeRequest [ 
1✔
1080
        "default limit to one page with last 100 pipelines"
1✔
1081
        
1✔
1082
        |results parseResults|
1✔
1083
        
1✔
1084
        results := self repoApi pipelines getByPage: 1 perPage: 100 inProject: aGLHMergeRequest project id forMergerRequestIid: aGLHMergeRequest iid. 
1✔
1085
        
1✔
1086
        parseResults := self parsePipelinesResult: results.
1✔
1087
        
1✔
1088
        parseResults := glhModel addAll: parseResults unless: self blockOnIdEquality.
1✔
1089
        parseResults := aGLHMergeRequest pipelines addAll: parseResults unless: self blockOnIdEquality.
1✔
1090
        ^ parseResults collect: [ :pip | self completeImportedPipeline: pip ]  .
1✔
1091
        
1✔
1092
]
1✔
1093

1✔
1094
{ #category : #'import - merge request' }
1✔
1095
GitlabModelImporter >> importMergeRequests: aGLHProject [
1✔
1096

1✔
1097
        | results parsedResults mrs |
1✔
1098
        ('Import merge request of Project: ' , aGLHProject id printString)
1✔
1099
                recordInfo.
1✔
1100

1✔
1101
        results := self repoApi mergeRequests getAllOfProject: aGLHProject id.
1✔
1102
        parsedResults := (results collect: [ :projectsJson | self parseMergeRequestsResult: projectsJson ]) flattened. 
1✔
1103

1✔
1104
        aGLHProject mergeRequests
1✔
1105
                addAll: parsedResults
1✔
1106
                unless: self blockOnIdEquality.
1✔
1107

1✔
1108
        mrs := self glhModel
1✔
1109
                       addAll: aGLHProject mergeRequests
1✔
1110
                       unless: self blockOnIdEquality.
1✔
1111

1✔
1112

1✔
1113
        "gets it related commits"
1✔
1114
        aGLHProject mergeRequests do: [ :mr |
1✔
1115
                self importMergeRequestMergeCommits: mr ].
1✔
1116

1✔
1117

1✔
1118
        self withCommitDiffs ifTrue: [
1✔
1119
                aGLHProject mergeRequests do: [ :mr |
1✔
1120
                        self importDiffOfMergeRequest: mr ] ].
1✔
1121

1✔
1122
        ^ mrs
1✔
1123
]
1✔
1124

1✔
1125
{ #category : #'import - merge request' }
1✔
1126
GitlabModelImporter >> importMergeRequests: aGLHProject since: fromDate until: toDate [
1✔
1127

1✔
1128
        | params result mergeRequests |
1✔
1129
        ('import MR of Project ' , aGLHProject name) recordInfo.
1✔
1130
        params := {
1✔
1131
                          (#created_after
1✔
1132
                           ->
1✔
1133
                           (fromDate
1✔
1134
                                    ifNotNil: [ fromDate asDateAndTime asString ]
1✔
1135
                                    ifNil: [ '' ])).
1✔
1136
                          (#created_before
1✔
1137
                           ->
1✔
1138
                           (toDate
1✔
1139
                                    ifNotNil: [ toDate asDateAndTime asString ]
1✔
1140
                                    ifNil: [ '' ])).
1✔
1141
                          (#scope -> 'all') } asDictionary.
1✔
1142

1✔
1143
        result := self repoApi mergeRequests
1✔
1144
                          getAllOfProject: aGLHProject id
1✔
1145
                          withParams: params.
1✔
1146
        mergeRequests := (result collect: [ :mergeRequestsJson |
1✔
1147
                                  self parseMergeRequestsResult: mergeRequestsJson ])
1✔
1148
                                 flattened.
1✔
1149

1✔
1150
        aGLHProject mergeRequests
1✔
1151
                addAll: mergeRequests
1✔
1152
                unless: self blockOnIdEquality.
1✔
1153

1✔
1154
        "gets it related commits"
1✔
1155
        aGLHProject mergeRequests do: [ :mr |
1✔
1156
                self importMergeRequestMergeCommits: mr ].
1✔
1157

1✔
1158
        self withCommitDiffs ifTrue: [
1✔
1159
                aGLHProject mergeRequests do: [ :mr |
1✔
1160
                        self importDiffOfMergeRequest: mr ] ].
1✔
1161

1✔
1162
        self glhModel
1✔
1163
                addAll: mergeRequests
1✔
1164
                unless: (self blockEqualityOn: #iid).
1✔
1165

1✔
1166
        ^ mergeRequests
1✔
1167
]
1✔
1168

1✔
1169
{ #category : #'import - merge request' }
1✔
1170
GitlabModelImporter >> importMergeResquestApprovals: aGLPHEMergeRequest [
1✔
1171

1✔
1172
        | results parsedResult |
1✔
1173
        (String streamContents: [ :str |
1✔
1174
                 str << 'Check approvals of '.
1✔
1175
                 aGLPHEMergeRequest printOn: str ]) recordInfo.
1✔
1176
        results := self repoApi mergeRequests approvalsOf: aGLPHEMergeRequest iid inProject: aGLPHEMergeRequest project id.
1✔
1177

1✔
1178
        parsedResult := generalReader
1✔
1179
                                on: results readStream;
1✔
1180
                                next.
1✔
1181

1✔
1182
        (parsedResult at: #approved_by) do: [ :approvedUser |
1✔
1183
                aGLPHEMergeRequest addApproved_by:
1✔
1184
                        (self importUser: ((approvedUser at: #user) at: #id)) ].
1✔
1185
        aGLPHEMergeRequest approved: (parsedResult at: #approved).
1✔
1186
        ^ aGLPHEMergeRequest
1✔
1187
]
1✔
1188

1✔
1189
{ #category : #'import - merge request' }
1✔
1190
GitlabModelImporter >> importMergeResquestAuthor: aGLPHEMergeRequest [
1✔
1191

1✔
1192
        | authorID |
1✔
1193
        aGLPHEMergeRequest author ifNotNil: [ ^ aGLPHEMergeRequest author ].
1✔
1194
        authorID := aGLPHEMergeRequest cacheAt: #authorID ifAbsent: [
1✔
1195
                            | result |
1✔
1196
                            result := self repoApi mergeRequests
1✔
1197
                                              get: aGLPHEMergeRequest iid
1✔
1198
                                              inProject: aGLPHEMergeRequest project_id.
1✔
1199

1✔
1200
                            (generalReader
1✔
1201
                                     on: result readStream;
1✔
1202
                                     next) at: #author at: #id ].
1✔
1203
        ^aGLPHEMergeRequest author: (self importUser: authorID)
1✔
1204
]
1✔
1205

1✔
1206
{ #category : #'import - merge request' }
1✔
1207
GitlabModelImporter >> importMergeResquestMerger: aGLPHEMergeRequest [
1✔
1208

1✔
1209
        | authorID |
1✔
1210
        aGLPHEMergeRequest merge_user ifNotNil: [
1✔
1211
                ^ aGLPHEMergeRequest merge_user ].
1✔
1212
        authorID := aGLPHEMergeRequest cacheAt: #mergeUserID ifAbsent: [
1✔
1213
                            | result |
1✔
1214
                            result := self repoApi mergeRequests
1✔
1215
                                              get: aGLPHEMergeRequest iid
1✔
1216
                                              inProject: aGLPHEMergeRequest project_id.
1✔
1217
                            (generalReader
1✔
1218
                                     on: result readStream;
1✔
1219
                                     next)
1✔
1220
                                    at: #merge_user
1✔
1221
                                    ifPresent: [ :mergeUser |
1✔
1222
                                    mergeUser ifNotNil: [ :mruser | mruser at: #id ] ] ].
1✔
1223
        ^aGLPHEMergeRequest merge_user: (self importUser: authorID)
1✔
1224
]
1✔
1225

1✔
1226
{ #category : #'import - notes' }
1✔
1227
GitlabModelImporter >> importNotesfromMergeRequest: mergeRequest [
1✔
1228
        | results notes |
1✔
1229
        
1✔
1230
        results := self repoApi notes allInMergeRequest: mergeRequest iid ofProject: mergeRequest project id.
1✔
1231
        
1✔
1232
        notes := results collect: [ :note | 
1✔
1233
                self parseNoteJson: note ].
1✔
1234
        "notes := self parseNoteJson: results."
1✔
1235
        notes do: [ :tabNotes | tabNotes do: [ :note |
1✔
1236
                        note author: (self importUser: (note author at: #id)).
1✔
1237
                        note name: note id asString]. ].
1✔
1238
        notes := notes flattened.
1✔
1239
        notes := self glhModel addAll: notes unless: self blockOnIdEquality. 
1✔
1240
        notes := mergeRequest note addAll: notes unless: self blockOnIdEquality. 
1✔
1241
        ^notes
1✔
1242
        
1✔
1243
]
1✔
1244

1✔
1245
{ #category : #'import - commits' }
1✔
1246
GitlabModelImporter >> importParentCommitsOfCommit: aGLHCommit since: aDate [
1✔
1247

1✔
1248
        | parentsIds commits |
1✔
1249
        commits := OrderedCollection new.
1✔
1250
        aGLHCommit created_at asDateAndTime < aDate asDateAndTime ifTrue: [
1✔
1251
                 
1✔
1252
                ^ commits
1✔
1253
                          add: aGLHCommit;
1✔
1254
                          yourself ].
1✔
1255

1✔
1256
        parentsIds := aGLHCommit parent_ids.
1✔
1257

1✔
1258
        commits addAll: (parentsIds collect: [ :id |
1✔
1259
                         self
1✔
1260
                                 importCommitOfProject: aGLHCommit repository project
1✔
1261
                                 withId: id ]).
1✔
1262

1✔
1263

1✔
1264
        ^ (commits collect: [ :parentCommit |
1✔
1265
                   self importParentCommitsOfCommit: parentCommit since: aDate ])
1✔
1266
                  flatten
1✔
1267
]
1✔
1268

1✔
1269
{ #category : #'import - pipelines' }
1✔
1270
GitlabModelImporter >> importPipeline: pipelineId OfProject: aGLHProject [
1✔
1271

1✔
1272
        
1✔
1273
        | result pipeline|
1✔
1274
        
1✔
1275
        aGLHProject pipelines detect: [ :pip | pip id = pipelineId ] ifOne: [ :pip| ^pip ].
1✔
1276
        
1✔
1277
        ('Search pipelines of: ' , aGLHProject id printString) recordInfo.
1✔
1278
        result := self repoApi pipelines get: pipelineId inProject: aGLHProject id.
1✔
1279
        result isString ifTrue: [ ^ self parsePipelineResult: result ].
1✔
1280

1✔
1281
        pipeline :=  self parsePipelineResult: result.
1✔
1282

1✔
1283
        pipeline := self glhModel add: pipeline unless: self blockOnIdEquality .
1✔
1284
        pipeline := aGLHProject pipelines add: pipeline unless: self blockOnIdEquality.
1✔
1285
        
1✔
1286
        ^ self completeImportedPipeline: pipeline. 
1✔
1287
]
1✔
1288

1✔
1289
{ #category : #'import - pipelines' }
1✔
1290
GitlabModelImporter >> importPipelinesOfProject: aGLHProject after: after andBefore: before [
1✔
1291
        ^ (self pipelinesOf: aGLHProject id after: after andBefore: before) collect: [ :pipeline |
1✔
1292
                |pip|
1✔
1293
                pip := self glhModel add: pipeline unless: self blockOnIdEquality .
1✔
1294
                pip := aGLHProject pipelines add: pip unless: self blockOnIdEquality.
1✔
1295
                
1✔
1296
                ].
1✔
1297
        
1✔
1298
]
1✔
1299

1✔
1300
{ #category : #'import - pipelines' }
1✔
1301
GitlabModelImporter >> importPipelinesOfProject: aGLHProject after: after andBefore: before onBranch: aBranch [
1✔
1302
        | result parsedResults|
1✔
1303
        ('Search pipelines of: ' , aGLHProject id printString) recordInfo.
1✔
1304
        
1✔
1305
        result := self repoApi pipelines getAllInProject: aGLHProject id 
1✔
1306
                                                                                                withParams: {        #updated_before -> before.
1✔
1307
                                                                                                                                        #updated_after -> after.
1✔
1308
                                                                                                                                        #ref -> aBranch name} asDictionary .
1✔
1309
        result isString ifTrue: [ ^ self parsePipelinesResult: result ].
1✔
1310

1✔
1311
        parsedResults := (result collect: [ :pipelinesJson |
1✔
1312
                           self parsePipelinesResult: pipelinesJson ]) flattened.
1✔
1313
        
1✔
1314

1✔
1315
        ^ parsedResults collect: [ :pipeline |
1✔
1316
                |pip|
1✔
1317
                pip := self glhModel add: pipeline unless: self blockOnIdEquality .
1✔
1318
                aGLHProject pipelines add: pip unless: self blockOnIdEquality.
1✔
1319
                ].
1✔
1320
        
1✔
1321
]
1✔
1322

1✔
1323
{ #category : #'import - projects' }
1✔
1324
GitlabModelImporter >> importProject: aProjectID [
1✔
1325

1✔
1326
        | result projectResult |
1✔
1327
        ('Import project with id:  ' , aProjectID printString) recordInfo.
1✔
1328

1✔
1329
        (glhModel allWithType: GLHProject)
1✔
1330
                detect: [ :project | project id = aProjectID ]
1✔
1331
                ifFound: [ :project | ^ project ].
1✔
1332

1✔
1333
        result := self repoApi projects get: aProjectID.
1✔
1334
        projectResult := self parseProjectResult: result.
1✔
1335

1✔
1336
        ^ self completeImportedProject: projectResult
1✔
1337
]
1✔
1338

1✔
1339
{ #category : #'import - projects' }
1✔
1340
GitlabModelImporter >> importProjects [
1✔
1341

1✔
1342
        | result projects |
1✔
1343
        ('import all Projects') recordInfo.
1✔
1344

1✔
1345

1✔
1346
        result := self repoApi projects all.
1✔
1347
        projects := (result collect: [ :projectsJson | self parseArrayOfProject: projectsJson ]) flattened.
1✔
1348
        
1✔
1349
        self glhModel addAll: projects unless: self blockOnIdEquality.
1✔
1350

1✔
1351
        ^ projects
1✔
1352
]
1✔
1353

1✔
1354
{ #category : #'import - projects' }
1✔
1355
GitlabModelImporter >> importProjectsSince: since [
1✔
1356
        "heavy import of all projects"
1✔
1357

1✔
1358
        "copy import from commits"
1✔
1359

1✔
1360
        | newlyFoundProjects page foundProject amount |
1✔
1361
        ('import all Projects since: ' , since printString) recordInfo.
1✔
1362

1✔
1363
        "number of projects per page"
1✔
1364
        amount := 100.
1✔
1365
        page := 0.
1✔
1366
        foundProject := OrderedCollection new.
1✔
1367
        newlyFoundProjects := { true }.
1✔
1368
        [ newlyFoundProjects isNotEmpty ] whileTrue: [
1✔
1369
                | results |
1✔
1370
                page := page + 1.
1✔
1371
                ('import projects page #' , page printString) recordInfo.
1✔
1372

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

1✔
1375
                newlyFoundProjects := self glhModel
1✔
1376
                                              addAll: (self parseArrayOfProject: results)
1✔
1377
                                              unless: self blockOnIdEquality.
1✔
1378
                foundProject addAll: newlyFoundProjects ].
1✔
1379
]
1✔
1380

1✔
1381
{ #category : #'import - repositories' }
1✔
1382
GitlabModelImporter >> importRepository: aGLHRepository [
1✔
1383

1✔
1384
        | resultBranches branches |
1✔
1385
        [
1✔
1386
        ('import the repository of project ' , aGLHRepository project name)
1✔
1387
                recordInfo.
1✔
1388

1✔
1389
        resultBranches := self repoApi branches getAllFromProject:
1✔
1390
                                  aGLHRepository project id.
1✔
1391

1✔
1392
        branches := (resultBranches collect: [ :branchesJson |
1✔
1393
                             self parseBranchesResult: branchesJson ]) flattened.
1✔
1394

1✔
1395
        'import the branches of project ' recordInfo.
1✔
1396

1✔
1397
        branches := aGLHRepository branches
1✔
1398
                            addAll: branches
1✔
1399
                            unless: self blockOnNameEquality.
1✔
1400
        branches := self glhModel
1✔
1401
                            addAll: branches
1✔
1402
                            unless: self blockOnNameEquality.
1✔
1403

1✔
1404

1✔
1405
        self withFiles ifTrue: [
1✔
1406
                branches do: [ :branch | self importFilesOfBranch: branch ] ] ]
1✔
1407
                on: NeoJSONParseError
1✔
1408
                do: [
1✔
1409
                self inform: aGLHRepository project name , ' has no repository' ].
1✔
1410
        
1✔
1411
        withInitialCommits ifTrue: [
1✔
1412
                aGLHRepository branches do: [ :branch |
1✔
1413
                        self importCommitsOfBranch: branch ] ]
1✔
1414
]
1✔
1415

1✔
1416
{ #category : #'import - tag' }
1✔
1417
GitlabModelImporter >> importTagsForProject: aProject [ 
1✔
1418
        |results tags |
1✔
1419
        results  := repoApi tags getAllOfProject: aProject id.
1✔
1420
        "get a group of tags"
1✔
1421
        tags := results flatCollect: [ :result |
1✔
1422
                        self parseTagsResult: result. 
1✔
1423
                 ].
1✔
1424

1✔
1425
        tags := glhModel addAll: tags unless: self blockOnNameEquality.
1✔
1426
        tags := aProject repository tags addAll: tags unless: self blockOnNameEquality.
1✔
1427
        
1✔
1428
        "update tag's commit if already imported"
1✔
1429
        tags do: [ :tag |
1✔
1430
                |commit|
1✔
1431
                commit := glhModel add: tag commit unless: self blockOnIdEquality.
1✔
1432
                commit := aProject repository commits add: tag commit unless: self blockOnIdEquality.
1✔
1433
                tag commit: commit. 
1✔
1434
                 ].
1✔
1435
        
1✔
1436
        "update tag's release if already imported"
1✔
1437
        tags do: [ :tag |
1✔
1438
                |release|
1✔
1439
                release ifNotNil: [ 
1✔
1440
                        release := glhModel add: tag release unless: (self blockEqualityOn: #tag_name).
1✔
1441
                        release := aProject releases add: tag release unless: (self blockEqualityOn: #tag_name).
1✔
1442
                        tag release: release. 
1✔
1443
                         ].
1✔
1444
                 ].
1✔
1445
        
1✔
1446
        ^ tags
1✔
1447
]
1✔
1448

1✔
1449
{ #category : #'import - users' }
1✔
1450
GitlabModelImporter >> importUser: aUserID [
1✔
1451

1✔
1452
        | result userResult |
1✔
1453
        (self glhModel allWithType: GLHUser)
1✔
1454
                detect: [ :user | user id = aUserID ]
1✔
1455
                ifFound: [ :user | ^ user ].
1✔
1456
        ('Import user: ' , aUserID printString) recordInfo.
1✔
1457
        
1✔
1458
        result := self repoApi users get: aUserID.
1✔
1459
        userResult := self parseUserResult: result.
1✔
1460
        
1✔
1461
        userResult := self glhModel add: userResult unless: self blockOnIdEquality.
1✔
1462
        userCatalogue addUser: userResult.
1✔
1463
        ^ userResult 
1✔
1464
]
1✔
1465

1✔
1466
{ #category : #'import - users' }
1✔
1467
GitlabModelImporter >> importUserByUsername: anUsername [
1✔
1468

1✔
1469
        | dicUsername resultUser |
1✔
1470
        dicUsername := ((self glhModel allWithType: GLHUser) collect: [ :user |
1✔
1471
                                user username -> user ]) asSet asDictionary.
1✔
1472

1✔
1473
        dicUsername addAll: self userCatalogue collectUsernames.
1✔
1474

1✔
1475

1✔
1476
        resultUser := dicUsername
1✔
1477
                              at: anUsername
1✔
1478
                              ifAbsent: [ "thus we have to import this new user"
1✔
1479
                                      | result userId searchResult params |
1✔
1480
                                      ('Import user with username: '
1✔
1481
                                       , anUsername printString) recordInfo.
1✔
1482
                                      params := { (#search -> anUsername) } asDictionary.
1✔
1483
                                      result := self repoApi users allWithParams: params.
1✔
1484
                                                        
1✔
1485
                                                         "when result is an error"
1✔
1486
                                                         (result isString) ifTrue: [ result := { result } ].
1✔
1487
                                                        
1✔
1488
                                      searchResult := result ifEmpty: [ result ] ifNotEmpty: [(result collect: [ :usersJson |
1✔
1489
                                                               NeoJSONReader fromString: usersJson ]) first].
1✔
1490
                                                         
1✔
1491
                                      (searchResult class = Dictionary and: [
1✔
1492
                                               (searchResult at: #message) includesSubstring:
1✔
1493
                                                       '403 Forbidden' ])
1✔
1494
                                              ifTrue: [ "if the result is an 403 error we fake a new user"
1✔
1495
                                                      self glhModel
1✔
1496
                                                              add: (GLHUser new
1✔
1497
                                                                               username: anUsername;
1✔
1498
                                                                               name: anUsername;
1✔
1499
                                                                               yourself)
1✔
1500
                                                              unless: [ :nu :ou | nu username = ou username ] ]
1✔
1501
                                              ifFalse: [
1✔
1502
                                                      searchResult
1✔
1503
                                                              ifEmpty: [ "results can be empty thus we force a new user with the info we have "
1✔
1504
                                                                      self glhModel
1✔
1505
                                                                              add: (GLHUser new
1✔
1506
                                                                                               username: anUsername;
1✔
1507
                                                                                               name: anUsername;
1✔
1508
                                                                                               yourself)
1✔
1509
                                                                              unless: [ :nu :ou | nu username = ou username ] ]
1✔
1510
                                                              ifNotEmpty: [ "because we may already have the researched user, we look by ID in the model"
1✔
1511
                                                                      userId := searchResult first at: #id.
1✔
1512
                                                                      (self glhModel allWithType: GLHUser)
1✔
1513
                                                                              detect: [ :user | user id = userId ]
1✔
1514
                                                                              ifNone: [ self importUser: userId ] ] ] ].
1✔
1515

1✔
1516
        self userCatalogue addUser: resultUser withName: anUsername.
1✔
1517

1✔
1518
        ^ resultUser
1✔
1519
]
1✔
1520

1✔
1521
{ #category : #initialization }
1✔
1522
GitlabModelImporter >> initReader [
1✔
1523

1✔
1524
        generalReader := NeoJSONReader new.
1✔
1525
        self configureReaderForCommit: generalReader.
1✔
1526
        self configureReaderForGroup: generalReader.
1✔
1527
        self configureReaderForDiffs: generalReader.
1✔
1528
        self configureReaderForMergeRequest: generalReader.
1✔
1529
        self configureReaderForPipeline: generalReader. 
1✔
1530
        self configureReaderForTags: generalReader. 
1✔
1531
        self configureReaderForReleases: generalReader. 
1✔
1532
        self configureReaderForUsers: generalReader. 
1✔
1533
]
1✔
1534

1✔
1535
{ #category : #initialization }
1✔
1536
GitlabModelImporter >> initialize [
1✔
1537

1✔
1538
        super initialize.
1✔
1539
        withCommitDiffs := true.
1✔
1540
        withInitialCommits := false.
1✔
1541
        withInitialMergeRequest := false.
1✔
1542

1✔
1543
        self withCommitsSince: 1 week.
1✔
1544

1✔
1545
        self initReader
1✔
1546
]
1✔
1547

1✔
1548
{ #category : #private }
1✔
1549
GitlabModelImporter >> isServerError: aString [
1✔
1550
        ^ aString = '{"message":"500 Internal Server Error"}'
1✔
1551
]
1✔
1552

1✔
1553
{ #category : #'import - projects' }
1✔
1554
GitlabModelImporter >> loadAllProjectsFromRepositorySoftware [
1✔
1555
        "heavy import that load all the active project inside the model. Only import the project entities"
1✔
1556
        |projects|
1✔
1557
        
1✔
1558
        projects := self repoApi projects. 
1✔
1559
]
1✔
1560

1✔
1561
{ #category : #'private - parsing' }
1✔
1562
GitlabModelImporter >> newParseCommitResult: result [
1✔
1563

1✔
1564
        generalReader  on: result readStream.
1✔
1565

1✔
1566
        ^ generalReader nextAs: GLHCommit
1✔
1567
]
1✔
1568

1✔
1569
{ #category : #'private - parsing' }
1✔
1570
GitlabModelImporter >> newParseDiffResult: result [
1✔
1571

1✔
1572
        generalReader on: result readStream.
1✔
1573
        ^ generalReader nextAs: #ArrayOfDiffs
1✔
1574
]
1✔
1575

1✔
1576
{ #category : #'private - parsing' }
1✔
1577
GitlabModelImporter >> parseArrayOfProject: arrayOfProjects [
1✔
1578

1✔
1579
        | reader |
1✔
1580
        reader := NeoJSONReader on: arrayOfProjects readStream.
1✔
1581
        reader
1✔
1582
                for: #ArrayOfProjects
1✔
1583
                customDo: [ :customMappting |
1✔
1584
                customMappting listOfElementSchema: GLHProject ].
1✔
1585
        reader for: GLHProject do: [ :mapping |
1✔
1586
                mapping mapInstVar: #name to: #name.
1✔
1587
                mapping mapInstVar: #description to: #description.
1✔
1588
                mapping mapInstVar: #id to: #id.
1✔
1589
                mapping mapInstVar: #archived to: #archived.
1✔
1590
                mapping mapInstVar: #web_url to: #html_url.
1✔
1591
                mapping mapInstVar: #topics to: #topics ].
1✔
1592
        ^ reader nextAs: #ArrayOfProjects
1✔
1593
]
1✔
1594

1✔
1595
{ #category : #'private - parsing' }
1✔
1596
GitlabModelImporter >> parseBranchesResult: result [
1✔
1597

1✔
1598
        | reader |
1✔
1599
        reader := NeoJSONReader on: result readStream.
1✔
1600
        reader mapInstVarsFor: GLHBranch.
1✔
1601
        reader
1✔
1602
                for: #ArrayOfBranch
1✔
1603
                customDo: [ :customMappting | 
1✔
1604
                customMappting listOfElementSchema: GLHBranch ].
1✔
1605
        ^ reader nextAs: #ArrayOfBranch
1✔
1606
]
1✔
1607

1✔
1608
{ #category : #'private - parsing' }
1✔
1609
GitlabModelImporter >> parseCommitResult: result [
1✔
1610

1✔
1611
        | reader |
1✔
1612
        reader := NeoJSONReader on: result readStream.
1✔
1613

1✔
1614
        reader for: GLHCommit do: [ :mapping |
1✔
1615
                mapping mapInstVars:
1✔
1616
                        #( id short_id title author_name author_email committer_name
1✔
1617
                           committer_email message web_url ).
1✔
1618
                (mapping mapInstVar: #authored_date) valueSchema: DateAndTime.
1✔
1619
                (mapping mapInstVar: #committed_date) valueSchema: DateAndTime.
1✔
1620
                (mapping mapInstVar: #created_at) valueSchema: DateAndTime.
1✔
1621
                (mapping mapInstVar: #parent_ids) valueSchema: #ArrayOfIds.
1✔
1622
                mapping
1✔
1623
                        mapProperty: 'stats'
1✔
1624
                        getter: [ :el | "Not used" ]
1✔
1625
                        setter: [ :commit :value |
1✔
1626
                                commit deletions: (value at: #deletions).
1✔
1627
                                commit additions: (value at: #additions) ] ].
1✔
1628

1✔
1629
        reader for: DateAndTime customDo: [ :mapping |
1✔
1630
                mapping decoder: [ :string | DateAndTime fromString: string ] ].
1✔
1631

1✔
1632
        reader
1✔
1633
                for: #ArrayOfIds
1✔
1634
                customDo: [ :mapping | mapping decoder: [ :string | string ] ].
1✔
1635

1✔
1636

1✔
1637
        ^ reader nextAs: GLHCommit
1✔
1638
]
1✔
1639

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

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

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

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

1✔
1664
        reader
1✔
1665
                for: #ArrayOfIds
1✔
1666
                customDo: [ :mapping | mapping decoder: [ :string | string ] ].
1✔
1667
  
1✔
1668
        reader
1✔
1669
                for: #ArrayOfCommit
1✔
1670
                customDo: [ :customMappting |
1✔
1671
                customMappting listOfElementSchema: GLHCommit ].
1✔
1672

1✔
1673
        ^ reader nextAs: #ArrayOfCommit
1✔
1674
]
1✔
1675

1✔
1676
{ #category : #private }
1✔
1677
GitlabModelImporter >> parseDiffResult: result [
1✔
1678

1✔
1679
        | reader |
1✔
1680
        self
1✔
1681
                deprecated: 'Use #newParseDiffResult: instead'
1✔
1682
                on: '28 June 2024'
1✔
1683
                in:
1✔
1684
                'Pharo-11.0.0+build.726.sha.aece1b5473acf3830a0e082c1bc3a15d4ff3522b (64 Bit)'.
1✔
1685
        reader := NeoJSONReader on: result readStream.
1✔
1686
        reader for: GLHDiff do: [ :mapping |
1✔
1687
                mapping mapInstVars:
1✔
1688
                        #( deleted_file new_file new_path old_path renamed_file ).
1✔
1689
                mapping mapInstVar: #diffString to: #diff ].
1✔
1690

1✔
1691
        reader
1✔
1692
                for: #ArrayOfDiffs
1✔
1693
                customDo: [ :customMappting |
1✔
1694
                customMappting listOfElementSchema: GLHDiff ].
1✔
1695
        ^ reader nextAs: #ArrayOfDiffs
1✔
1696
]
1✔
1697

1✔
1698
{ #category : #'private - parsing' }
1✔
1699
GitlabModelImporter >> parseFileTreeResult: aResult [
1✔
1700

1✔
1701
        | reader |
1✔
1702
        reader := NeoJSONReader on: aResult readStream.
1✔
1703
        reader mapInstVarsFor: GLHApiFile.
1✔
1704
        reader
1✔
1705
                for: #ArrayOfFile
1✔
1706
                customDo: [ :customMappting | 
1✔
1707
                customMappting listOfElementSchema: GLHApiFile ].
1✔
1708
        ^ reader nextAs: #ArrayOfFile
1✔
1709
]
1✔
1710

1✔
1711
{ #category : #'private - parsing' }
1✔
1712
GitlabModelImporter >> parseGroupResult: aResult [
1✔
1713

1✔
1714
        | reader |
1✔
1715

1✔
1716
        reader := NeoJSONReader on: aResult readStream.
1✔
1717
        reader for: GLHGroup do: [ :mapping |
1✔
1718
                mapping mapInstVars.
1✔
1719
                (mapping mapInstVar: #projects) valueSchema: #ArrayOfProjects ].
1✔
1720
        reader mapInstVarsFor: GLHProject.
1✔
1721
        reader
1✔
1722
                for: #ArrayOfProjects
1✔
1723
                customDo: [ :customMappting |
1✔
1724
                customMappting listOfElementSchema: GLHProject ].
1✔
1725
        ^ reader nextAs: GLHGroup
1✔
1726
]
1✔
1727

1✔
1728
{ #category : #'private - parsing' }
1✔
1729
GitlabModelImporter >> parseJobsResult: result ofProject: aProject [
1✔
1730

1✔
1731
        | reader |
1✔
1732
        reader := NeoJSONReader on: result readStream.
1✔
1733
        reader for: GLHJob do: [ :mapping |
1✔
1734
                mapping mapInstVars: #( id allow_failure web_url name ).
1✔
1735

1✔
1736
                mapping
1✔
1737
                        mapProperty: #user
1✔
1738
                        getter: [ :object | #ignore ]
1✔
1739
                        setter: [ :object :value |
1✔
1740
                        object user: (self importUser: (value at: #id)) ].
1✔
1741

1✔
1742
                mapping
1✔
1743
                        mapProperty: #commit
1✔
1744
                        getter: [ :object | #ignore ]
1✔
1745
                        setter: [ :object :value |
1✔
1746
                                value ifNotNil: [
1✔
1747
                                        object commit:
1✔
1748
                                                (self importCommit: (value at: #id) ofProject: aProject) ] ].
1✔
1749

1✔
1750
                mapping
1✔
1751
                        mapProperty: #duration
1✔
1752
                        getter: [ :object | #ignore ]
1✔
1753
                        setter: [ :object :value |
1✔
1754
                        value ifNotNil: [ object duration: value seconds ] ] ].
1✔
1755

1✔
1756
        reader
1✔
1757
                for: #ArrayOfGLHJob
1✔
1758
                customDo: [ :customMappting |
1✔
1759
                customMappting listOfElementSchema: GLHJob ].
1✔
1760
        ^ reader nextAs: #ArrayOfGLHJob
1✔
1761
]
1✔
1762

1✔
1763
{ #category : #'private - parsing' }
1✔
1764
GitlabModelImporter >> parseMergeRequestsResult: result [
1✔
1765

1✔
1766
        generalReader on: result readStream.
1✔
1767
        ^ generalReader nextAs: #ArrayOfMergeRequest
1✔
1768
]
1✔
1769

1✔
1770
{ #category : #'private - parsing' }
1✔
1771
GitlabModelImporter >> parseNoteJson: results [  
1✔
1772
    | reader |  
1✔
1773

1✔
1774
    "Créer un lecteur JSON"
1✔
1775
    reader := NeoJSONReader on: results readStream.    
1✔
1776

1✔
1777
    "Définir le mapping pour l'objet GLHNote"
1✔
1778
    reader for: GLHNote do: [ :mapping |  
1✔
1779
        mapping mapInstVars: #(id noteable_id attachment system confidential internal  
1✔
1780
                               noteable_iid resolvable imported imported_from  
1✔
1781
                               author body project_id noteable_type).  
1✔
1782

1✔
1783
        (mapping mapInstVar: #created_at) valueSchema: DateAndTime.  
1✔
1784
        (mapping mapInstVar: #updated_at) valueSchema: DateAndTime.  
1✔
1785
    ].    
1✔
1786

1✔
1787
    "Corriger la conversion des dates"
1✔
1788
    reader for: DateAndTime customDo: [ :mapping |  
1✔
1789
        mapping decoder: [ :string | DateAndTime readFrom: string readStream ] ].
1✔
1790

1✔
1791
        reader
1✔
1792
                for: #ArrayOfNote
1✔
1793
                customDo: [ :customMappting | 
1✔
1794
                customMappting listOfElementSchema: GLHNote ].
1✔
1795
         ^ reader nextAs: #ArrayOfNote
1✔
1796

1✔
1797
    "Retourner la Note"
1✔
1798
    "^ reader nextAs: GLHNote"
1✔
1799

1✔
1800

1✔
1801
]
1✔
1802

1✔
1803
{ #category : #'private - parsing' }
1✔
1804
GitlabModelImporter >> parsePipelineResult: result [
1✔
1805

1✔
1806
        | reader |
1✔
1807
        
1✔
1808
        (result includesSubstring: '{"message":"40' )ifTrue: [ ^ {  } ].
1✔
1809
        
1✔
1810
        reader := generalReader on: result readStream.
1✔
1811
        
1✔
1812
        ^ reader nextAs: GLHPipeline
1✔
1813
]
1✔
1814

1✔
1815
{ #category : #'private - parsing' }
1✔
1816
GitlabModelImporter >> parsePipelinesResult: result [
1✔
1817

1✔
1818
        | reader |
1✔
1819
        
1✔
1820
        (result includesSubstring: '{"message":"40' )ifTrue: [ ^ {  } ].
1✔
1821
        
1✔
1822
        reader := generalReader on: result readStream.
1✔
1823
        
1✔
1824
        ^ reader nextAs: #ArrayOfPipelines
1✔
1825
]
1✔
1826

1✔
1827
{ #category : #'private - parsing' }
1✔
1828
GitlabModelImporter >> parseProjectResult: aResult [ 
1✔
1829
                | reader |
1✔
1830
        reader := NeoJSONReader on: aResult readStream.
1✔
1831
        reader for: GLHProject do: [ :mapping |
1✔
1832
                mapping mapInstVars. ].
1✔
1833
"        reader mapInstVarsFor: GLHProject."
1✔
1834

1✔
1835
        ^ reader nextAs: GLHProject
1✔
1836
]
1✔
1837

1838
{ #category : #parsing }
UNCOV
1839
GitlabModelImporter >> parseReleaseResult: result [
×
UNCOV
1840
        |reader|
×
UNCOV
1841
        reader := generalReader on: result readStream.
×
UNCOV
1842
        
×
UNCOV
1843
        ^ reader nextAs: GLHRelease 
×
UNCOV
1844
]
×
1845

1846
{ #category : #parsing }
UNCOV
1847
GitlabModelImporter >> parseReleasesResult: result [
×
UNCOV
1848
        |reader|
×
UNCOV
1849
        reader := generalReader on: result readStream.
×
UNCOV
1850
        
×
UNCOV
1851
        ^ reader nextAs: #ArrayOfReleases
×
UNCOV
1852
]
×
1853

1854
{ #category : #'private - parsing' }
UNCOV
1855
GitlabModelImporter >> parseSubGroupResult: aResult [
×
UNCOV
1856

×
UNCOV
1857
        | reader |
×
UNCOV
1858
        reader := NeoJSONReader on: aResult readStream.
×
UNCOV
1859
        self configureReaderForGroup: reader.
×
UNCOV
1860
        ^ reader nextAs: #ArrayOfGroups
×
1861
]
×
1862

1863
{ #category : #parsing }
1864
GitlabModelImporter >> parseTagsResult: result [
×
1865
        |reader|
×
1866
        reader := generalReader on: result readStream.
×
UNCOV
1867
        
×
UNCOV
1868
        ^ reader nextAs: #ArrayOfTags
×
1869
]
×
1870

1871
{ #category : #'private - parsing' }
1872
GitlabModelImporter >> parseUserResult: result [
1✔
1873

1✔
1874
        | reader |
1✔
1875
        
1✔
1876
        reader := generalReader on: result readStream.
1✔
1877
        
1✔
1878
        ^ reader nextAs: GLHUser
1✔
1879

1✔
1880
        
1✔
1881

1✔
1882
]
1✔
1883

1884
{ #category : #'private - parsing' }
UNCOV
1885
GitlabModelImporter >> parseUsersResult: result [
×
1886

×
1887
        | reader |
×
1888
        
×
1889
        reader := generalReader on: result readStream.
×
1890
        
×
1891
        ^ reader nextAs: #ArrayOfUser
×
UNCOV
1892
        
×
UNCOV
1893
]
×
1894

1895
{ #category : #'import - projects' }
UNCOV
1896
GitlabModelImporter >> partiallyImportProject: aProjectID [
×
UNCOV
1897

×
UNCOV
1898
        | result projectResult |
×
UNCOV
1899
        ('Import project with id:  ' , aProjectID printString) recordInfo.
×
UNCOV
1900

×
UNCOV
1901
        (glhModel allWithType: GLHProject)
×
UNCOV
1902
                detect: [ :project | project id = aProjectID ]
×
UNCOV
1903
                ifFound: [ :project | ^ project ].
×
UNCOV
1904

×
UNCOV
1905
        result := self repoApi projects get: aProjectID.
×
UNCOV
1906
        projectResult := self parseProjectResult: result.
×
1907

×
1908
        projectResult repository: GLHRepository new.
×
1909
        self glhModel add: projectResult repository.
×
1910
        self importRepository: projectResult repository.
×
1911

×
1912
        ^ projectResult
×
1913
]
×
1914

1915
{ #category : #'import - pipelines' }
UNCOV
1916
GitlabModelImporter >> pipelinesOf: aProjectID after: after andBefore: before [
×
UNCOV
1917

×
1918
        | result |
×
1919
        ('Search pipelines of: ' , aProjectID printString) recordInfo.
×
1920
        
×
1921
        result := self repoApi pipelines getAllInProject: aProjectID 
×
1922
                                                                                                withParams: {        #updated_before -> before.
×
1923
                                                                                                                                        #updated_after -> after} asDictionary .
×
1924
        result isString ifTrue: [ ^ self parsePipelinesResult: result ].
×
1925

×
1926
        ^ (result collect: [ :pipelinesJson |
×
1927
                           self parsePipelinesResult: pipelinesJson ]) flattened
×
1928
]
×
1929

1930
{ #category : #'import - pipelines' }
1931
GitlabModelImporter >> pipelinesOf: aProjectID withLimit: aLimit [
1✔
1932

1✔
1933
        | result |
1✔
1934
        ('Search pipelines of: ' , aProjectID printString) recordInfo.
1✔
1935
        result := self repoApi pipelines getByPage: 1 perPage: aLimit inProject: aProjectID.
1✔
1936
        result isString ifTrue: [ ^ self parsePipelinesResult: result ].
1✔
1937

1✔
1938
        ^ (result collect: [ :pipelinesJson |
1✔
1939
                           self parsePipelinesResult: pipelinesJson ]) flattened
1✔
1940
]
1✔
1941

1942
{ #category : #accessing }
1943
GitlabModelImporter >> repoApi: anObject [
1✔
1944
        super repoApi: anObject.
1✔
1945
        self repoApi output: 'json'
1✔
1946
]
1✔
1947

1948
{ #category : #'search - merge request' }
1949
GitlabModelImporter >> searchMergeRequestMentionning: aString [ 
×
1950
        |mergeRequests results|
×
UNCOV
1951
        results := repoApi mergeRequests search: aString.
×
UNCOV
1952
        mergeRequests := self parseMergeRequestsResult: results.
×
UNCOV
1953
        mergeRequests :=        mergeRequests collect: [ :mr |
×
UNCOV
1954
                mr project: (self importProject: mr project_id).
×
UNCOV
1955
                mr
×
UNCOV
1956
                 ].
×
UNCOV
1957
        
×
UNCOV
1958
        ^ glhModel addAll: mergeRequests unless: self blockOnIdEquality. 
×
UNCOV
1959
]
×
1960

1961
{ #category : #private }
UNCOV
1962
GitlabModelImporter >> selectEntityType: aType overAttribut: aSelector equalTo: value [
×
UNCOV
1963

×
UNCOV
1964
        ^ (self glhModel allWithType: aType)
×
UNCOV
1965
                select: [ :entity | (entity perform: aSelector) = value ]
×
UNCOV
1966
]
×
1967

1968
{ #category : #'import - groups' }
1969
GitlabModelImporter >> subGroupsOf: aGroupID [
1✔
1970

1✔
1971
        | results subgroups |
1✔
1972
        ('Search subgroup of: ' , aGroupID printString) recordInfo.
1✔
1973
        results := self repoApi groups subgroupsOf: aGroupID.
1✔
1974
        subgroups := (results collect: [ :subgroupsJson | self parseSubGroupResult: subgroupsJson ]) flattened.
1✔
1975
        
1✔
1976
        ^ subgroups
1✔
1977
]
1✔
1978

1979
{ #category : #accessing }
1980
GitlabModelImporter >> withInitialCommits: boolean [
×
1981
        withInitialCommits := boolean 
×
UNCOV
1982
]
×
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

© 2025 Coveralls, Inc