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

moosetechnology / GitProjectHealth / 15138087322

20 May 2025 12:54PM UTC coverage: 72.626% (-0.6%) from 73.222%
15138087322

Pull #196

github

web-flow
Merge 21b0419a5 into 118855527
Pull Request #196: Pipeline 2

785 of 1734 new or added lines in 15 files covered. (45.27%)

199 existing lines in 4 files now uncovered.

15977 of 21999 relevant lines covered (72.63%)

0.73 hits per line

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

53.78
/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' }
NEW
40
GitlabModelImporter >> allPipelinesOf: aProjectID [
×
NEW
41

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

×
NEW
47
        ^ (result collect: [ :pipelinesJson |
×
NEW
48
                           self parsePipelinesResult: pipelinesJson ]) flattened
×
NEW
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' }
UNCOV
96
GitlabModelImporter >> completeImportProject: aGLHProject [
×
UNCOV
97

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

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

×
NEW
107
        self importLatestPipelinesOfProject: importedProject.
×
UNCOV
108

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

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

×
UNCOV
114

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

×
UNCOV
119

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

×
UNCOV
126
        ^ importedProject
×
UNCOV
127
        
×
UNCOV
128

×
UNCOV
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' }
NEW
147
GitlabModelImporter >> completeImportedPipeline: aGLHPipeline [ 
×
NEW
148
        |result parsedResults|
×
NEW
149
        
×
NEW
150
        result := self repoApi pipelines get: aGLHPipeline id inProject: aGLHPipeline project id. 
×
NEW
151
        parsedResults := self parsePipelineResult: result. 
×
NEW
152
        
×
NEW
153
        "aGLHPipeline methods".
×
NEW
154
        { #'created_at:' . #'status:' . #'finished_at:' . #'duration:' . #'started_at:' . #'updated_at:' . "#'ref:'" } do: [ :m |
×
NEW
155
                aGLHPipeline perform: m asSymbol with: (parsedResults perform: (m withoutSuffix: ':') asSymbol )
×
NEW
156
                 ].
×
NEW
157
        
×
NEW
158
        aGLHPipeline. 
×
NEW
159
]
×
160

161
{ #category : #'import - projects' }
162
GitlabModelImporter >> completeImportedProject: aGLHProject [
1✔
163

1✔
164
        | importedProject |
1✔
165
        ('Complete import of project: ' , aGLHProject id printString)
1✔
166
                recordInfo.
1✔
167
        aGLHProject repository ifNotNil: [ ^ aGLHProject ].
1✔
168

1✔
169
        importedProject := self glhModel
1✔
170
                                   add: aGLHProject
1✔
171
                                   unless: self blockOnIdEquality.
1✔
172

1✔
173
        self importLatestPipelinesOfProject: importedProject.
1✔
174

1✔
175
        "aGLHProject creator: (self importUser: aGLHProject creator_id)."
1✔
176

1✔
177
        (self importUser: importedProject creator_id) addCreatedProject:
1✔
178
                importedProject.
1✔
179

1✔
180

1✔
181
        importedProject repository: GLHRepository new.
1✔
182
        self glhModel add: importedProject repository.
1✔
183
        self importRepository: importedProject repository.
1✔
184

1✔
185

1✔
186
        withInitialMergeRequest ifTrue: [
1✔
187
                self
1✔
188
                        importMergeRequests: importedProject
1✔
189
                        since: DateAndTime today
1✔
190
                        until: DateAndTime now ].
1✔
191

1✔
192
        ^ importedProject
1✔
193
        
1✔
194

1✔
195
]
1✔
196

197
{ #category : #'private - configure reader' }
198
GitlabModelImporter >> configureReaderForCommit: reader [
1✔
199

1✔
200
          reader for: GLHCommit do: [ :mapping |
1✔
201
                mapping mapInstVars:
1✔
202
                        #( id short_id title author_name author_email committer_name
1✔
203
                           committer_email message web_url ).
1✔
204
                (mapping mapInstVar: #authored_date) valueSchema: DateAndTime.
1✔
205
                (mapping mapInstVar: #committed_date) valueSchema: DateAndTime.
1✔
206
                (mapping mapInstVar: #created_at) valueSchema: DateAndTime.
1✔
207
                (mapping mapInstVar: #parent_ids) valueSchema: #ArrayOfIds.
1✔
208
                mapping
1✔
209
                        mapProperty: 'stats'
1✔
210
                        getter: [ :el | "Not used" ]
1✔
211
                        setter: [ :commit :value |
1✔
212
                                commit deletions: (value at: #deletions).
1✔
213
                                commit additions: (value at: #additions) ] ].
1✔
214

1✔
215
        reader for: DateAndTime customDo: [ :mapping |
1✔
216
                mapping decoder: [ :string | DateAndTime fromString: string ] ].
1✔
217

1✔
218
        reader
1✔
219
                for: #ArrayOfIds
1✔
220
                customDo: [ :mapping | mapping decoder: [ :string | string ] ].
1✔
221
  
1✔
222
        reader
1✔
223
                for: #ArrayOfCommit
1✔
224
                customDo: [ :customMappting |
1✔
225
                customMappting listOfElementSchema: GLHCommit ].
1✔
226

1✔
227
]
1✔
228

229
{ #category : #'private - configure reader' }
230
GitlabModelImporter >> configureReaderForDiffs: reader [
1✔
231

1✔
232
        reader for: GLHDiff do: [ :mapping |
1✔
233
                mapping mapInstVars:
1✔
234
                        #( deleted_file new_file new_path old_path renamed_file ).
1✔
235
                mapping mapInstVar: #diffString to: #diff ].
1✔
236

1✔
237
        reader
1✔
238
                for: #ArrayOfDiffs
1✔
239
                customDo: [ :customMappting |
1✔
240
                customMappting listOfElementSchema: GLHDiff ].
1✔
241
        ^ reader
1✔
242
]
1✔
243

244
{ #category : #'private - configure reader' }
245
GitlabModelImporter >> configureReaderForGroup: reader [
1✔
246

1✔
247
        reader for: GLHGroup do: [ :mapping |
1✔
248
                mapping mapInstVars.
1✔
249
                (mapping mapInstVar: #projects) valueSchema: #ArrayOfProjects ].
1✔
250
        reader mapInstVarsFor: GLHProject.
1✔
251
        reader
1✔
252
                for: #ArrayOfProjects
1✔
253
                customDo: [ :customMappting |
1✔
254
                customMappting listOfElementSchema: GLHProject ].
1✔
255
        reader
1✔
256
                for: #ArrayOfGroups
1✔
257
                customDo: [ :customMappting |
1✔
258
                customMappting listOfElementSchema: GLHGroup ]
1✔
259
]
1✔
260

261
{ #category : #'private - configure reader' }
262
GitlabModelImporter >> configureReaderForMergeRequest: reader [
1✔
263
        "declare quil y a un array a mapper"
1✔
264

1✔
265
        reader for: #ArrayOfMergeRequest customDo: [ :customMappting |
1✔
266
                customMappting listOfElementSchema: GLHMergeRequest ].
1✔
267

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

1✔
302
        "(mapping mapInstVar: #closed_by) valueSchema: GLHUser.
1✔
303
        (mapping mapInstVar: #mergeCommit) valueSchema: GLHCommit."
1✔
304
        "indique ce que doit faire le reader lorsqu'il parse une DateAndTime object"
1✔
305
        reader for: DateAndTime customDo: [ :mapping |
1✔
306
                mapping decoder: [ :string |
1✔
307
                        string ifNil: [ nil ] ifNotNil: [ DateAndTime fromString: string ] ] ]
1✔
308
]
1✔
309

310
{ #category : #'private - configure reader' }
311
GitlabModelImporter >> configureReaderForPipeline: reader [
1✔
312

1✔
313
        reader mapInstVarsFor: GLHPipeline.
1✔
314
        
1✔
315
        reader for: GLHPipeline do: [ :mapping |
1✔
316

1✔
317
                mapping
1✔
318
                        mapProperty: #created_at
1✔
319
                        getter: [ :object | #ignore ]
1✔
320
                        setter: [ :object :value |
1✔
321
                        object created_at: (DateAndTime fromString: value).
1✔
322
                        object runDate: (DateAndTime fromString: value) ].
1✔
323
                
1✔
324
                mapping
1✔
325
                        mapProperty: #updated_at
1✔
326
                        getter: [ :object | #ignore ]
1✔
327
                        setter: [ :object :value |
1✔
328
                        object updated_at: (DateAndTime fromString: value).
1✔
329
                        ].
1✔
330
                
1✔
331
                mapping
1✔
332
                        mapProperty: #finished_at
1✔
333
                        getter: [ :object | #ignore ]
1✔
334
                        setter: [ :object :value |
1✔
335
                        object finished_at: (DateAndTime fromString: value).
1✔
336
                        ].
1✔
337
                
1✔
338
                mapping
1✔
339
                        mapProperty: #started_at  
1✔
340
                        getter: [ :object | #ignore ]
1✔
341
                        setter: [ :object :value |
1✔
342
                        object started_at: (DateAndTime fromString: value).
1✔
343
                        ].
1✔
344
                
1✔
345
                mapping
1✔
346
                        mapProperty: #source
1✔
347
                        getter: [ :object | #ignore ]
1✔
348
                        setter: [ :object :value |
1✔
349
                        object sourceEvent: value.
1✔
350
                        ].
1✔
351
                
1✔
352
                mapping
1✔
353
                        mapProperty: #duration
1✔
354
                        getter: [ :object | #ignore ]
1✔
355
                        setter: [ :object :value |
1✔
356
                        object duration: value asDuration .
1✔
357
                        ].
1✔
358
                
1✔
359
                 ].
1✔
360
        
1✔
361
        reader
1✔
362
                for: #ArrayOfPipelines
1✔
363
                customDo: [ :customMappting |
1✔
364
                customMappting listOfElementSchema: GLHPipeline ].
1✔
365
]
1✔
366

367
{ #category : #private }
368
GitlabModelImporter >> convertApiFileAsFile: aAPIFile [
×
369

×
370
        aAPIFile type = 'tree' ifTrue: [ 
×
371
                ^ GLHFileDirectory new
×
372
                          name: aAPIFile name;
×
373
                          yourself ].
×
374
        ^ GLHFileBlob new
×
375
                  name: aAPIFile name;
×
376
                  yourself
×
377
]
×
378

379
{ #category : #private }
380
GitlabModelImporter >> detectEntityType: aType overAttribut: aSelector equalTo: value [
1✔
381

1✔
382
        ^ (self glhModel allWithType: aType) detect: [ :entity |
1✔
383
                  (entity perform: aSelector) = value ] ifNone: [ nil ]. 
1✔
384
]
1✔
385

386
{ #category : #accessing }
387
GitlabModelImporter >> glhApi [
×
388

×
389
        self
×
390
                deprecated: 'Use #repoApi instead'
×
391
                on: '7 October 2024'
×
392
                in:
×
393
                'Pharo-11.0.0+build.726.sha.aece1b5473acf3830a0e082c1bc3a15d4ff3522b (64 Bit)'.
×
394

×
395
        ^ repoApi
×
396
]
×
397

398
{ #category : #accessing }
399
GitlabModelImporter >> glhApi: anObject [
×
400

×
401
        self
×
402
                deprecated: 'Use #repoApi: instead'
×
403
                on: '7 October 2024'
×
404
                in:
×
405
                'Pharo-11.0.0+build.726.sha.aece1b5473acf3830a0e082c1bc3a15d4ff3522b (64 Bit)'.
×
406

×
407
        repoApi := anObject
×
408
]
×
409

410
{ #category : #accessing }
411
GitlabModelImporter >> glhModel [
1✔
412

1✔
413
        ^ glhModel
1✔
414
]
1✔
415

416
{ #category : #accessing }
417
GitlabModelImporter >> glhModel: anObject [
1✔
418

1✔
419
        glhModel := anObject
1✔
420
]
1✔
421

422
{ #category : #'import - users' }
423
GitlabModelImporter >> importActiveHumanUsers [
×
424

×
425
        | params result users |
×
426
        params := { 
×
427
                #humans -> 'true'.
×
428
                #active -> 'true'.
×
429
                #without_project_bots -> 'true'
×
430
        } asDictionary.
×
431
        result := self repoApi users allWithParams: params.
×
432
        users := (result collect: [ :usersJson | self parseUsersResult: usersJson ]) flattened.
×
433
        
×
434
        self glhModel
×
435
                                 addAll: users
×
436
                                 unless: self blockOnIdEquality.
×
437

×
438
        ^ users
×
439
]
×
440

441
{ #category : #'import - groups' }
442
GitlabModelImporter >> importAllGroups [
×
443

×
444
        | params results groups |
×
445
        
×
446
        params := { 
×
447
                        #top_level_only -> 'true'
×
448
        } asDictionary.
×
449
        results := self repoApi groups getAllWithParams: params.
×
450
        
×
451
        groups := (results collect: [ :groupsJson | generalReader
×
452
                                            on: groupsJson readStream;
×
453
                                            nextAs: #ArrayOfGroups. ]) flattened.
×
454
        ^ groups
×
455
]
×
456

457
{ #category : #'import - pipelines' }
NEW
458
GitlabModelImporter >> importAllPipelinesOfProject: aGLHProject [
×
NEW
459

×
NEW
460
        (self allPipelinesOf: aGLHProject id) do: [ :pipeline |
×
NEW
461
                |pip|
×
NEW
462
                pip := self glhModel add: pipeline unless: self blockOnIdEquality .
×
NEW
463
                pip := aGLHProject pipelines add: pip unless: self blockOnIdEquality.
×
NEW
464
                self completeImportedPipeline: pip. 
×
NEW
465
                ].
×
NEW
466
        
×
NEW
467
        ^ aGLHProject pipelines
×
NEW
468
]
×
469

470
{ #category : #'import - commits' }
471
GitlabModelImporter >> importAndLoadLatestsCommitsOfProject: aGLHProject [
×
472

×
473
        | commits completedProject |
×
NEW
474
        completedProject := self completeImportedProject: aGLHProject.
×
475
        commits := self importLastestCommitsOfProject: completedProject.
×
476
        commits do: [ :commit | self completeImportedCommit: commit ].
×
477
        self chainsCommitsFrom: commits.
×
478
        ^ commits
×
479
]
×
480

481
{ #category : #'import - commits' }
482
GitlabModelImporter >> importCommit: aCommitID ofProject: aGLHProject [
×
483

×
484
        | result parsedResult |
×
485
        (self glhModel allWithType: GLHCommit) asOrderedCollection
×
486
                detect: [ :commit | commit id = aCommitID ]
×
487
                ifFound: [ :commit | ^ commit ].
×
488
        result := self repoApi commits get: aCommitID inProject: aGLHProject id.
×
489
        
×
490
        parsedResult := self parseCommitResult: result.
×
491
        
×
492
        self
×
493
                addCommits: { parsedResult }
×
494
                toRepository: aGLHProject repository.
×
495
        ^ parsedResult
×
496
]
×
497

498
{ #category : #'import - commits' }
499
GitlabModelImporter >> importCommitOfProject: anProject withId: anID [
1✔
500

1✔
501
        | commit result |
1✔
502
        anID ifNil: [ ^ nil ].
1✔
503

1✔
504
        ('looking for commit ' , anID printString , ' in project : '
1✔
505
         , anProject id printString) recordInfo.
1✔
506

1✔
507
        commit := (self
1✔
508
                           detectEntityType: GLHCommit
1✔
509
                           overAttribut: #id
1✔
510
                           equalTo: anID) ifNil: [
1✔
511
                          result := self repoApi commits get: anID inProject: anProject id.
1✔
512
                          commit := (self parseCommitsResult: '[' , result , ']')
1✔
513
                                            first.
1✔
514

1✔
515
                          self glhModel add: commit unless: self blockOnIdEquality.
1✔
516
                          commit repository: anProject repository.
1✔
517

1✔
518
                          commit ].
1✔
519

1✔
520
        self withCommitDiffs ifTrue: [ self importDiffOfCommit: commit ].
1✔
521

1✔
522
        ^ commit
1✔
523
]
1✔
524

525
{ #category : #'import - commits' }
526
GitlabModelImporter >> importCommits: aGLHProject [
×
527
        "limited to the last 20 commits"
×
528

×
529
        | results parsedResults params |
×
530
        params := { 
×
531
         #with_stats -> 'true'
×
532
        } asDictionary.
×
533
        results := self repoApi commits getByPage: 1 perPage: 20 inProject: aGLHProject id withParams: params.
×
534
        
×
535
        parsedResults := self parseCommitsResult: results.
×
536
        self glhModel addAll: parsedResults unless: self blockOnIdEquality.
×
537

×
538
        parsedResults do: [ :commit |
×
539
                commit repository: aGLHProject repository ].
×
540

×
541
        self withCommitDiffs ifTrue: [
×
542
                parsedResults do: [ :commit | self importDiffOfCommit: commit ] ].
×
543
        
×
544
        ^ parsedResults. 
×
545
]
×
546

547
{ #category : #'import - commits' }
548
GitlabModelImporter >> importCommitsFollowing: aCommit upToDays: aNumberOfDay [
×
549
        "import the 'n' commits of a project starting from an initial 'aCommit' commit. 
×
550
        Lazy import does not import the entities inside the model"
×
551

×
552
        | date |
×
553
        date := aCommit created_at asDateAndTime.
×
554

×
555
        ^ self
×
556
                  importCommitsOfBranch: aCommit branch
×
557
                  forRefName: aCommit branch name
×
558
                  since: date
×
559
                  until: (date + aNumberOfDay day)
×
560
]
×
561

562
{ #category : #commit }
563
GitlabModelImporter >> importCommitsOf: aGLHProject withStats: aBoolean until: toDate [
×
564

×
565
        | newlyFoundCommit page |
×
566
        
×
567
        self deprecated: [  ] .
×
568
        
×
569
        page := 0.
×
570
        newlyFoundCommit := { true }.
×
571
        [ newlyFoundCommit isNotEmpty ] whileTrue: [
×
572
                | results parsedResults existingCommits |
×
573
                page := page + 1.
×
574
                ('import commit page ' , page printString) recordInfo.
×
575
                results := self repoApi
×
576
                                   commitsOfProject: aGLHProject id
×
577
                                   forRefName: nil
×
578
                                   since: nil
×
579
                                   until: nil
×
580
                                   path: nil
×
581
                                   author: nil
×
582
                                   all: nil
×
583
                                   with_stats: aBoolean
×
584
                                   firstParent: nil
×
585
                                   order: nil
×
586
                                   trailers: nil
×
587
                                   perPage: 100
×
588
                                   page: page.
×
589
                parsedResults := self parseCommitsResult: results.
×
590
                existingCommits := aGLHProject mooseModel allWithType: GLHCommit.
×
591

×
592
                newlyFoundCommit := parsedResults reject: [ :commitParsed |
×
593
                                            (toDate isNil or: [
×
594
                                                     commitParsed committed_date
×
595
                                                     < toDate asDateAndTime ]) or: [
×
596
                                                    existingCommits anySatisfy: [ :existingCommit |
×
597
                                                            existingCommit id = commitParsed id ] ] ].
×
598
                aGLHProject mooseModel addAll: newlyFoundCommit.
×
599
                aGLHProject repository commits addAll: newlyFoundCommit ].
×
600

×
601

×
602
        self withCommitDiffs ifTrue: [
×
603
                aGLHProject repository commits do: [ :commit |
×
604
                        self importDiffOfCommit: commit ] ]
×
605
]
×
606

607
{ #category : #'import - commits' }
608
GitlabModelImporter >> importCommitsOfBranch: aGLHBranch [
×
609

×
610
        | commits |
×
611
        "        result := self glhApi
×
612
                          commitsOfProject: aGLHBranch repository project id
×
613
                          forRefName: aGLHBranch name."
×
614
        commits := self
×
615
                           importCommitsOfBranch: aGLHBranch
×
616
                           forRefName: aGLHBranch name
×
617
                           since: withCommitsSince.
×
618

×
619
        self chainsCommitsFrom: commits.
×
620

×
621
        commits do: [ :aCommit |
×
622
                aCommit repository: aGLHBranch repository.
×
623
                self completeImportedCommit: aCommit. 
×
624
                 ]
×
625
]
×
626

627
{ #category : #'import - commits' }
628
GitlabModelImporter >> importCommitsOfBranch: aGLHBranch forRefName: refName since: fromDate [
×
629

×
630
        ^ self
×
631
                  importCommitsOfBranch: aGLHBranch
×
632
                  forRefName: aGLHBranch name
×
633
                  since: fromDate
×
634
                  until: nil
×
635
]
×
636

637
{ #category : #'import - commits' }
638
GitlabModelImporter >> importCommitsOfBranch: aGLHBranch forRefName: refName since: fromDate until: toDate [
×
639

×
640
        | params result allCommits |
×
641
        params := { 
×
642
          #ref_name -> aGLHBranch name.
×
643
          #since ->  (fromDate ifNotNil: [ fromDate asDate asDateAndTime asString ] ifNil: [ '' ]).
×
644
          #until -> (toDate ifNotNil: [ toDate asDate asDateAndTime asString ] ifNil: [ '' ]). 
×
645

×
646
        } asDictionary.
×
647
        result := self repoApi commits getAllInProject: aGLHBranch repository project id withParams: params.
×
648
        
×
649
        allCommits := (result collect: [ :commitsJson | self parseCommitsResult: commitsJson ]) flattened.
×
650
        
×
651
        aGLHBranch commits
×
652
                        addAll: allCommits
×
653
                        unless: self blockOnIdEquality.
×
654

×
655
        self glhModel
×
656
                addAll: aGLHBranch commits
×
657
                unless: self blockOnIdEquality.
×
658

×
659
        ^ allCommits
×
660
]
×
661

662
{ #category : #'import - commits' }
663
GitlabModelImporter >> importCommitsOfBranch: aGLHBranch forRefName: refName until: toDate [
×
664

×
665
        ^ self
×
666
                  importCommitsOfBranch: aGLHBranch
×
667
                  forRefName: aGLHBranch name
×
668
                  since: nil
×
669
                  until: toDate
×
670
]
×
671

672
{ #category : #'import - commits' }
673
GitlabModelImporter >> importCommitsOfProject: aProject since: fromDate until: toDate [
1✔
674

1✔
675
        | params results allCommits |
1✔
676
        params := {
1✔
677
                          (#since
1✔
678
                           ->
1✔
679
                           (fromDate
1✔
680
                                    ifNotNil: [ fromDate asDate asDateAndTime asString ]
1✔
681
                                    ifNil: [ '' ])).
1✔
682
                          (#until
1✔
683
                           ->
1✔
684
                           (toDate
1✔
685
                                    ifNotNil: [ toDate asDate asDateAndTime asString ]
1✔
686
                                    ifNil: [ '' ])).
1✔
687
                          (#with_stats -> 'true').
1✔
688
                          (#all -> 'true') } asDictionary.
1✔
689
        results := self repoApi commits
1✔
690
                           getAllInProject: aProject id
1✔
691
                           withParams: params.
1✔
692

1✔
693
        allCommits := (results collect: [ :commitsJson |
1✔
694
                               self parseCommitsResult: commitsJson ]) flattened.
1✔
695

1✔
696
        allCommits:= aProject repository commits
1✔
697
                addAll: allCommits
1✔
698
                unless: self blockOnIdEquality.
1✔
699

1✔
700
        ^ self glhModel addAll: allCommits unless: self blockOnIdEquality
1✔
701
]
1✔
702

703
{ #category : #'import - projects' }
704
GitlabModelImporter >> importContributedProjectsOfUser: aGLHUser [
×
705

×
706
        | remaningProjects params results projects projectsIds |
×
707
        params := {
×
708
                          (#order_by -> 'last_activity_at').
×
709
                          (#simple -> 'true') } asDictionary.
×
710
        results := self repoApi projects
×
711
                           contributedProjectsOfUser: aGLHUser id
×
712
                           withParams: params.
×
713

×
714
        projectsIds := (results collect: [ :projectsJson |
×
715
                             (NeoJSONReader fromString: projectsJson) collect: [:projectJson | projectJson at: #id ] ]) flattened.
×
716
        
×
717
        projects := self importProjects: projectsIds.
×
718
        remaningProjects := self importProjects:
×
719
                                    ((projects collect: #id) difference:
×
720
                                             ((self userCatalogue atId: aGLHUser id) at:
×
721
                                                      #contributedProjects)).
×
722

×
723

×
724
        aGLHUser contributedProjects
×
725
                addAll: projects , remaningProjects
×
726
                unless: self blockOnIdEquality.
×
727

×
728
        self userCatalogue
×
729
                addUser: aGLHUser
×
730
                withProjects: (aGLHUser contributedProjects collect: #id).
×
731

×
732
        ^ projects
×
733
]
×
734

735
{ #category : #'import - commits' }
736
GitlabModelImporter >> importCreatorOfCommit: aCommit [
1✔
737

1✔
738
        aCommit commitCreator ifNil: [
1✔
739
                aCommit commitCreator:
1✔
740
                        (self importUserByUsername: aCommit author_name) ].
1✔
741
        self userCatalogue
1✔
742
                addUser: aCommit commitCreator
1✔
743
                withProject: aCommit repository project id.
1✔
744
        ^ aCommit commitCreator
1✔
745
]
1✔
746

747
{ #category : #'import - commits' }
748
GitlabModelImporter >> importDiffOfCommit: aCommit [
1✔
749

1✔
750
        | result diffsResult |
1✔
751
        aCommit diffs ifNotEmpty: [
1✔
752
                'Diff already importer: ' , aCommit short_id printString recordInfo.
1✔
753
                ^ aCommit diffs ].
1✔
754
        ('Import diff of commit: ' , aCommit short_id printString) recordInfo.
1✔
755

1✔
756
        result := self repoApi commits
1✔
757
                          diffOf: aCommit id
1✔
758
                          inProject: aCommit repository project id
1✔
759
                          uniDiff: true.
1✔
760

1✔
761
        (self isServerError: result) ifTrue: [ ^ {  } ].
1✔
762
        diffsResult := self newParseDiffResult: result.
1✔
763

1✔
764
        aCommit diffs addAll: diffsResult unless: self blockForDiffEquality.
1✔
765
        
1✔
766
        "changes are added into the model during the import"
1✔
767
        aCommit diffs do: [ :diff | self importDiffRangesForDiff: diff ].
1✔
768

1✔
769
        ^ aCommit diffs
1✔
770
]
1✔
771

772
{ #category : #'import - merge request' }
773
GitlabModelImporter >> importDiffOfMergeRequest: aMergeRequest [
1✔
774

1✔
775
        | result diffsResult |
1✔
776
        aMergeRequest diffs ifNotEmpty: [
1✔
777
                'Diff of already importer: '
1✔
778
                , aMergeRequest iid printString recordInfo.
1✔
779
                ^ aMergeRequest diffs ].
1✔
780
        ('Import diff commits of MR ' , aMergeRequest iid printString)
1✔
781
                recordInfo.
1✔
782
        result := self repoApi mergeRequests diffsOf: aMergeRequest iid inProject: aMergeRequest project_id.
1✔
783

1✔
784
        diffsResult := self newParseDiffResult: result.
1✔
785

1✔
786

1✔
787
        aMergeRequest diffs
1✔
788
                addAll: diffsResult
1✔
789
                unless: self blockForDiffEquality.
1✔
790
        self glhModel
1✔
791
                addAll: aMergeRequest diffs
1✔
792
                unless: self blockForDiffEquality.
1✔
793

1✔
794
        aMergeRequest diffs do: [ :diff | self importDiffRangesForDiff: diff ].
1✔
795

1✔
796
        ^ aMergeRequest diffs
1✔
797
]
1✔
798

799
{ #category : #'import - repositories' }
800
GitlabModelImporter >> importDirectoryFiles: aDirectoryFile OfBranch: aBranch [
×
801

×
802
        | result files apiFiles params |
×
803
        params := { 
×
804
                #ref -> aBranch name.
×
805
                #path -> (aDirectoryFile path , '/')
×
806
        } asDictionary.
×
807
        result := self repoApi repositories repositoryTreeOfProject: aBranch repository project id withParams: params.
×
808
                         " treeOfRepository: aBranch repository project id
×
809
                          ofBranch: aBranch name
×
810
                          andPath: aDirectoryFile path , '/'."
×
811
        apiFiles := (result collect: [ :treeJson | self parseFileTreeResult: treeJson ]) flattened.
×
812
        files := apiFiles collect: [ :apiFile |
×
813
                         self convertApiFileAsFile: apiFile ].
×
814
        
×
815
        files do: [ :file |
×
816
                self glhModel add: file.
×
817
                aDirectoryFile addFile: file ].
×
818
        
×
819
        files
×
820
                select: [ :file | file isKindOf: GLHFileDirectory ]
×
821
                thenCollect: [ :file |
×
822
                self importDirectoryFiles: file OfBranch: aBranch ]
×
823
]
×
824

825
{ #category : #'import - repositories' }
826
GitlabModelImporter >> importFilesOfBranch: aBranch [
×
827

×
828
        | result files apiFiles params |
×
829
        params := { 
×
830
                #ref -> aBranch name.
×
831
        } asDictionary.
×
832
        
×
833
        result := self repoApi repositories repositoryTreeOfProject: aBranch repository project id withParams: params.
×
834
        
×
835
                          "treeOfRepository: aBranch repository project id
×
836
                          ofBranch: aBranch name
×
837
                          andPath: nil."
×
838
        apiFiles := (result collect: [ :filesJson | self parseFileTreeResult: filesJson  ]) flattened.
×
839
        files := apiFiles collect: [ :apiFile | 
×
840
                         self convertApiFileAsFile: apiFile ].
×
841
        files do: [ :file | 
×
842
                self glhModel add: file.
×
843
                aBranch addFile: file ].
×
844
        files
×
845
                select: [ :file | file isKindOf: GLHFileDirectory ]
×
846
                thenCollect: [ :file | 
×
847
                self importDirectoryFiles: file OfBranch: aBranch ]
×
848
]
×
849

850
{ #category : #'import - groups' }
851
GitlabModelImporter >> importGroup: aGroupID [
1✔
852

1✔
853
        | result groupResult |
1✔
854
        ('Import group: ' , aGroupID printString) recordInfo.
1✔
855

1✔
856
        result := self repoApi groups get: aGroupID.
1✔
857
        
1✔
858
        "group: aGroupID."
1✔
859
        groupResult := self parseGroupResult: result.
1✔
860
        groupResult := self addGroupResultToModel: groupResult.
1✔
861

1✔
862
        groupResult projects do: [ :project |
1✔
863
                self completeImportedProject: project ].
1✔
864

1✔
865
        (self subGroupsOf: aGroupID) do: [ :subGroup |
1✔
866
                
1✔
867
                groupResult subGroups
1✔
868
                        add: (self importGroup: subGroup id)
1✔
869
                        unless: self blockOnIdEquality ].
1✔
870
        ^ groupResult
1✔
871
]
1✔
872

873
{ #category : #'import - jobs' }
874
GitlabModelImporter >> importJobsOf: aPipeline [
×
875

×
876
        | jobs results |
×
NEW
877
        results := self repoApi jobs
×
NEW
878
                           getAllForPipeline: aPipeline id
×
NEW
879
                           inProject: aPipeline project id.
×
NEW
880
        "jobsOfProject: aPipeline project id
×
881
                          ofPipelines: aPipeline id."
×
NEW
882
        jobs := (results collect: [ :jobsJson |
×
NEW
883
                         self parseJobsResult: jobsJson ofProject: aPipeline project ])
×
NEW
884
                        flattened.
×
885
        jobs do: [ :job | aPipeline addJob: job ].
×
886
        self glhModel addAll: jobs.
×
887

×
NEW
888
        ^ jobs
×
UNCOV
889
]
×
890

891
{ #category : #'import - commits' }
892
GitlabModelImporter >> importLastestCommitsOfProject: aGLHProject [
1✔
893
        "limited to the last 50 commits"
1✔
894

1✔
895
        | results parsedResults params |
1✔
896
        params := { 
1✔
897
                #with_stats -> 'true'.
1✔
898
                #all -> true
1✔
899
         } asDictionary.
1✔
900
        results := self repoApi commits getByPage: 1 perPage: 50 inProject: aGLHProject id withParams: params.
1✔
901

1✔
902
        parsedResults := self parseCommitsResult: results.
1✔
903
        parsedResults := self glhModel
1✔
904
                                 addAll: parsedResults
1✔
905
                                 unless: self blockOnIdEquality.
1✔
906

1✔
907
        aGLHProject repository commits
1✔
908
                addAll: parsedResults
1✔
909
                unless: self blockOnIdEquality.
1✔
910

1✔
911
        self withCommitDiffs ifTrue: [
1✔
912
                parsedResults do: [ :commit | self importDiffOfCommit: commit ] ].
1✔
913

1✔
914
        ^ parsedResults
1✔
915
]
1✔
916

917
{ #category : #'import - merge request' }
NEW
918
GitlabModelImporter >> importLatestMergeRequestsOfProject: aGLHProject [ 
×
NEW
919
        
×
NEW
920
        |results parsedResults|
×
NEW
921
        results := self repoApi mergeRequests getByPage: 1 perPage: 20  inProject: aGLHProject id. 
×
NEW
922
        parsedResults := self parseMergeRequestsResult: results. 
×
NEW
923
        
×
NEW
924
        parsedResults := glhModel addAll: parsedResults unless: self blockOnIdEquality.
×
NEW
925
        parsedResults := aGLHProject mergeRequests addAll: parsedResults unless: self blockOnIdEquality.
×
NEW
926
        ^ parsedResults.
×
NEW
927
]
×
928

929
{ #category : #'import - pipelines' }
930
GitlabModelImporter >> importLatestPipelinesOfProject: aGLHProject [ 
1✔
931
        (self pipelinesOf: aGLHProject id withLimit:30) do: [ :pipeline |
1✔
932
                |pip|
1✔
933
                pip := self glhModel add: pipeline unless: self blockOnIdEquality .
1✔
934
                pip := aGLHProject pipelines add: pip unless: self blockOnIdEquality.
1✔
935
                self completeImportedPipeline: pip. 
1✔
936
                ].
1✔
937
        
1✔
938
        ^ aGLHProject pipelines 
1✔
939
]
1✔
940

941
{ #category : #'import - merge request' }
942
GitlabModelImporter >> importMergeRequestCommits: aGLPHEMergeRequest [
×
943

×
944
        | commits result |
×
945
        aGLPHEMergeRequest commits ifNotNil: [ ^ aGLPHEMergeRequest commits ].
×
946
        
×
947
        result := self repoApi mergeRequests commitsOf: aGLPHEMergeRequest iid inProject: aGLPHEMergeRequest project id.
×
948
        
×
949
        commits := (result collect: [ :commitsJson | self parseCommitsResult: commitsJson ]) flattened.
×
950
        commits := commits collect: [ :commit | self importCommit: commit id ofProject: aGLPHEMergeRequest project ].
×
951
        aGLPHEMergeRequest commits: commits.
×
952

×
953

×
954
        ^ commits
×
955
]
×
956

957
{ #category : #'import - merge request' }
958
GitlabModelImporter >> importMergeRequestMergeCommits: aGLPHEMergeRequest [
1✔
959

1✔
960
        | foundCommits |
1✔
961
        foundCommits := OrderedCollection new.
1✔
962

1✔
963
        ('Import commit sha of MR:  ' , aGLPHEMergeRequest iid printString)
1✔
964
                recordInfo.
1✔
965
        "the founds commits are added to the model during their respective import"
1✔
966
        aGLPHEMergeRequest mergeRequestCommit: ((self
1✔
967
                          importCommitOfProject: aGLPHEMergeRequest project
1✔
968
                          withId: aGLPHEMergeRequest sha) ifNotNil: [ :commit |
1✔
969
                         foundCommits add: commit ]).
1✔
970

1✔
971
        ('Import commit merge_commit_sha of MR:  '
1✔
972
         , aGLPHEMergeRequest iid printString) recordInfo.
1✔
973
        aGLPHEMergeRequest mergedCommit: ((self
1✔
974
                          importCommitOfProject: aGLPHEMergeRequest project
1✔
975
                          withId: aGLPHEMergeRequest merge_commit_sha) ifNotNil: [ :commit |
1✔
976
                         foundCommits add: commit ]).
1✔
977

1✔
978
        ('Import commit squash_commit_sha of MR:  '
1✔
979
         , aGLPHEMergeRequest iid printString) recordInfo.
1✔
980
        aGLPHEMergeRequest squashCommit: ((self
1✔
981
                          importCommitOfProject: aGLPHEMergeRequest project
1✔
982
                          withId: aGLPHEMergeRequest squash_commit_sha) ifNotNil: [ :commit |
1✔
983
                         foundCommits add: commit ]).
1✔
984

1✔
985

1✔
986
        self chainsCommitsFrom: foundCommits.
1✔
987
        ^ foundCommits
1✔
988
]
1✔
989

990
{ #category : #'import - pipelines' }
NEW
991
GitlabModelImporter >> importMergeRequestPipelines: aGLHMergeRequest [ 
×
NEW
992
        "default limit to one page with last 20 pipelines"
×
NEW
993
        
×
NEW
994
        |results parseResults|
×
NEW
995
        
×
NEW
996
        results := self repoApi pipelines getByPage: 1 perPage: 20 inProject: aGLHMergeRequest project id forMergerRequestIid: aGLHMergeRequest iid. 
×
NEW
997
        
×
NEW
998
        parseResults := self parsePipelinesResult: results.
×
NEW
999
        
×
NEW
1000
        parseResults := glhModel addAll: parseResults unless: self blockOnIdEquality.
×
NEW
1001
        parseResults := aGLHMergeRequest pipelines addAll: parseResults unless: self blockOnIdEquality.
×
NEW
1002
        ^ parseResults collect: [ :pip | self completeImportedPipeline: pip ]  .
×
NEW
1003
        
×
NEW
1004
]
×
1005

1006
{ #category : #'import - merge request' }
1007
GitlabModelImporter >> importMergeRequests: aGLHProject [
1✔
1008

1✔
1009
        | results parsedResults mrs |
1✔
1010
        ('Import merge request of Project: ' , aGLHProject id printString)
1✔
1011
                recordInfo.
1✔
1012

1✔
1013
        results := self repoApi mergeRequests allOfProject: aGLHProject id.
1✔
1014
        parsedResults := (results collect: [ :projectsJson | self parseMergeRequestsResult: projectsJson ]) flattened. 
1✔
1015

1✔
1016
        aGLHProject mergeRequests
1✔
1017
                addAll: parsedResults
1✔
1018
                unless: self blockOnIdEquality.
1✔
1019

1✔
1020
        mrs := self glhModel
1✔
1021
                       addAll: aGLHProject mergeRequests
1✔
1022
                       unless: self blockOnIdEquality.
1✔
1023

1✔
1024

1✔
1025
        "gets it related commits"
1✔
1026
        aGLHProject mergeRequests do: [ :mr |
1✔
1027
                self importMergeRequestMergeCommits: mr ].
1✔
1028

1✔
1029

1✔
1030
        self withCommitDiffs ifTrue: [
1✔
1031
                aGLHProject mergeRequests do: [ :mr |
1✔
1032
                        self importDiffOfMergeRequest: mr ] ].
1✔
1033

1✔
1034
        ^ mrs
1✔
1035
]
1✔
1036

1037
{ #category : #'import - merge request' }
1038
GitlabModelImporter >> importMergeRequests: aGLHProject since: fromDate until: toDate [
×
1039

×
1040
        | params result mergeRequests |
×
1041
        ('import MR of Project ' , aGLHProject name) recordInfo.
×
1042
        params := {
×
1043
                          (#created_after
×
1044
                           ->
×
1045
                           (fromDate
×
1046
                                    ifNotNil: [ fromDate asDateAndTime asString ]
×
1047
                                    ifNil: [ '' ])).
×
1048
                          (#created_before
×
1049
                           ->
×
1050
                           (toDate
×
1051
                                    ifNotNil: [ toDate asDateAndTime asString ]
×
1052
                                    ifNil: [ '' ])).
×
1053
                          (#scope -> 'all') } asDictionary.
×
1054

×
1055
        result := self repoApi mergeRequests
×
1056
                          allOfProject: aGLHProject id
×
1057
                          withParams: params.
×
1058
        mergeRequests := (result collect: [ :mergeRequestsJson |
×
NEW
1059
                                  self parseMergeRequestsResult: mergeRequestsJson ])
×
1060
                                 flattened.
×
1061

×
1062
        aGLHProject mergeRequests
×
1063
                addAll: mergeRequests
×
1064
                unless: self blockOnIdEquality.
×
1065

×
1066
        "gets it related commits"
×
1067
        aGLHProject mergeRequests do: [ :mr |
×
1068
                self importMergeRequestMergeCommits: mr ].
×
1069

×
1070
        self withCommitDiffs ifTrue: [
×
1071
                aGLHProject mergeRequests do: [ :mr |
×
1072
                        self importDiffOfMergeRequest: mr ] ].
×
1073

×
1074
        self glhModel
×
1075
                addAll: mergeRequests
×
1076
                unless: (self blockEqualityOn: #iid).
×
1077

×
1078
        ^ mergeRequests
×
1079
]
×
1080

1081
{ #category : #'import - merge request' }
1082
GitlabModelImporter >> importMergeResquestApprovals: aGLPHEMergeRequest [
×
1083

×
1084
        | results parsedResult |
×
1085
        (String streamContents: [ :str |
×
1086
                 str << 'Check approvals of '.
×
1087
                 aGLPHEMergeRequest printOn: str ]) recordInfo.
×
1088
        results := self repoApi mergeRequests approvalsOf: aGLPHEMergeRequest iid inProject: aGLPHEMergeRequest project id.
×
1089

×
1090
        parsedResult := generalReader
×
1091
                                on: results readStream;
×
1092
                                next.
×
1093

×
1094
        (parsedResult at: #approved_by) do: [ :approvedUser |
×
1095
                aGLPHEMergeRequest addApproved_by:
×
1096
                        (self importUser: ((approvedUser at: #user) at: #id)) ].
×
1097
        aGLPHEMergeRequest approved: (parsedResult at: #approved).
×
1098
        ^ aGLPHEMergeRequest
×
1099
]
×
1100

1101
{ #category : #'import - merge request' }
1102
GitlabModelImporter >> importMergeResquestAuthor: aGLPHEMergeRequest [
1✔
1103

1✔
1104
        | authorID |
1✔
1105
        aGLPHEMergeRequest author ifNotNil: [ ^ aGLPHEMergeRequest author ].
1✔
1106
        authorID := aGLPHEMergeRequest cacheAt: #authorID ifAbsent: [
1✔
1107
                            | result |
1✔
1108
                            result := self repoApi mergeRequests
1✔
1109
                                              get: aGLPHEMergeRequest iid
1✔
1110
                                              inProject: aGLPHEMergeRequest project_id.
1✔
1111

1✔
1112
                            (generalReader
1✔
1113
                                     on: result readStream;
1✔
1114
                                     next) at: #author at: #id ].
1✔
1115
        ^aGLPHEMergeRequest author: (self importUser: authorID)
1✔
1116
]
1✔
1117

1118
{ #category : #'import - merge request' }
1119
GitlabModelImporter >> importMergeResquestMerger: aGLPHEMergeRequest [
1✔
1120

1✔
1121
        | authorID |
1✔
1122
        aGLPHEMergeRequest merge_user ifNotNil: [
1✔
1123
                ^ aGLPHEMergeRequest merge_user ].
1✔
1124
        authorID := aGLPHEMergeRequest cacheAt: #mergeUserID ifAbsent: [
1✔
1125
                            | result |
1✔
1126
                            result := self repoApi mergeRequests
1✔
1127
                                              get: aGLPHEMergeRequest iid
1✔
1128
                                              inProject: aGLPHEMergeRequest project_id.
1✔
1129
                            (generalReader
1✔
1130
                                     on: result readStream;
1✔
1131
                                     next)
1✔
1132
                                    at: #merge_user
1✔
1133
                                    ifPresent: [ :mergeUser |
1✔
1134
                                    mergeUser ifNotNil: [ :mruser | mruser at: #id ] ] ].
1✔
1135
        ^aGLPHEMergeRequest merge_user: (self importUser: authorID)
1✔
1136
]
1✔
1137

1138
{ #category : #'import - notes' }
1139
GitlabModelImporter >> importNotesfromMergeRequest: mergeRequest [
×
1140
        | results notes |
×
1141
        
×
1142
        results := self repoApi notes allInMergeRequest: mergeRequest iid ofProject: mergeRequest project id.
×
1143
        
×
1144
        notes := results collect: [ :note | 
×
1145
                self parseNoteJson: note ].
×
1146
        "notes := self parseNoteJson: results."
×
1147
        notes do: [ :tabNotes | tabNotes do: [ :note |
×
1148
                        note author: (self importUser: (note author at: #id)).
×
1149
                        note name: note id asString]. ].
×
1150
        notes := notes flattened.
×
1151
        notes := self glhModel addAll: notes unless: self blockOnIdEquality. 
×
1152
        notes := mergeRequest note addAll: notes unless: self blockOnIdEquality. 
×
1153
        ^notes
×
1154
        
×
1155
]
×
1156

1157
{ #category : #'import - commits' }
1158
GitlabModelImporter >> importParentCommitsOfCommit: aGLHCommit since: aDate [
×
1159

×
1160
        | parentsIds commits |
×
1161
        commits := OrderedCollection new.
×
1162
        aGLHCommit created_at asDateAndTime < aDate asDateAndTime ifTrue: [
×
1163
                 
×
1164
                ^ commits
×
1165
                          add: aGLHCommit;
×
1166
                          yourself ].
×
1167

×
1168
        parentsIds := aGLHCommit parent_ids.
×
1169

×
1170
        commits addAll: (parentsIds collect: [ :id |
×
1171
                         self
×
1172
                                 importCommitOfProject: aGLHCommit repository project
×
1173
                                 withId: id ]).
×
1174

×
1175

×
1176
        ^ (commits collect: [ :parentCommit |
×
1177
                   self importParentCommitsOfCommit: parentCommit since: aDate ])
×
1178
                  flatten
×
1179
]
×
1180

1181
{ #category : #'import - pipelines' }
NEW
1182
GitlabModelImporter >> importPipeline: pipelineId OfProject: aGLHProject [
×
UNCOV
1183

×
NEW
1184
        
×
NEW
1185
        | result pipeline|
×
NEW
1186
        
×
NEW
1187
        aGLHProject pipelines detect: [ :pip | pip id = pipelineId ] ifOne: [ :pip| ^pip ].
×
NEW
1188
        
×
NEW
1189
        ('Search pipelines of: ' , aGLHProject id printString) recordInfo.
×
NEW
1190
        result := self repoApi pipelines get: pipelineId inProject: aGLHProject id.
×
NEW
1191
        result isString ifTrue: [ ^ self parsePipelineResult: result ].
×
NEW
1192

×
NEW
1193
        pipeline :=  self parsePipelineResult: result.
×
NEW
1194

×
NEW
1195
        pipeline := self glhModel add: pipeline unless: self blockOnIdEquality .
×
NEW
1196
        pipeline := aGLHProject pipelines add: pipeline unless: self blockOnIdEquality.
×
NEW
1197
        
×
NEW
1198
        ^ self completeImportedPipeline: pipeline. 
×
UNCOV
1199
]
×
1200

1201
{ #category : #'import - projects' }
1202
GitlabModelImporter >> importProject: aProjectID [
1✔
1203

1✔
1204
        | result projectResult |
1✔
1205
        ('Import project with id:  ' , aProjectID printString) recordInfo.
1✔
1206

1✔
1207
        (glhModel allWithType: GLHProject)
1✔
1208
                detect: [ :project | project id = aProjectID ]
1✔
1209
                ifFound: [ :project | ^ project ].
1✔
1210

1✔
1211
        result := self repoApi projects get: aProjectID.
1✔
1212
        projectResult := self parseProjectResult: result.
1✔
1213

1✔
1214
        ^ self completeImportedProject: projectResult
1✔
1215
]
1✔
1216

1217
{ #category : #'import - projects' }
1218
GitlabModelImporter >> importProjects [
×
1219

×
1220
        | result projects |
×
1221
        ('import all Projects') recordInfo.
×
1222

×
1223

×
1224
        result := self repoApi projects all.
×
1225
        projects := (result collect: [ :projectsJson | self parseArrayOfProject: projectsJson ]) flattened.
×
1226
        
×
1227
        self glhModel addAll: projects unless: self blockOnIdEquality.
×
1228

×
1229
        ^ projects
×
1230
]
×
1231

1232
{ #category : #imports }
1233
GitlabModelImporter >> importProjectsSince: since [
×
1234
        "heavy import of all projects"
×
1235

×
1236
        "copy import from commits"
×
1237

×
1238
        | newlyFoundProjects page foundProject amount |
×
1239
        ('import all Projects since: ' , since printString) recordInfo.
×
1240

×
1241
        "number of projects per page"
×
1242
        amount := 100.
×
1243
        page := 0.
×
1244
        foundProject := OrderedCollection new.
×
1245
        newlyFoundProjects := { true }.
×
1246
        [ newlyFoundProjects isNotEmpty ] whileTrue: [
×
1247
                | results |
×
1248
                page := page + 1.
×
1249
                ('import projects page #' , page printString) recordInfo.
×
1250

×
1251
                results := self repoApi projects: amount since: since page: page.
×
1252

×
1253
                newlyFoundProjects := self glhModel
×
1254
                                              addAll: (self parseArrayOfProject: results)
×
1255
                                              unless: self blockOnIdEquality.
×
1256
                foundProject addAll: newlyFoundProjects ].
×
1257
]
×
1258

1259
{ #category : #'import - repositories' }
1260
GitlabModelImporter >> importRepository: aGLHRepository [
1✔
1261

1✔
1262
        | resultBranches branches |
1✔
1263
        [
1✔
1264
        ('import the repository of project ' , aGLHRepository project name)
1✔
1265
                recordInfo.
1✔
1266

1✔
1267
        resultBranches := self repoApi branches getAllFromProject:
1✔
1268
                                  aGLHRepository project id.
1✔
1269

1✔
1270
        branches := (resultBranches collect: [ :branchesJson |
1✔
1271
                             self parseBranchesResult: branchesJson ]) flattened.
1✔
1272

1✔
1273
        'import the branches of project ' recordInfo.
1✔
1274

1✔
1275
        branches := aGLHRepository branches
1✔
1276
                            addAll: branches
1✔
1277
                            unless: self blockOnNameEquality.
1✔
1278
        branches := self glhModel
1✔
1279
                            addAll: branches
1✔
1280
                            unless: self blockOnNameEquality.
1✔
1281

1✔
1282

1✔
1283
        self withFiles ifTrue: [
1✔
1284
                branches do: [ :branch | self importFilesOfBranch: branch ] ] ]
1✔
1285
                on: NeoJSONParseError
1✔
1286
                do: [
1✔
1287
                self inform: aGLHRepository project name , ' has no repository' ].
1✔
1288
        
1✔
1289
        withInitialCommits ifTrue: [
1✔
1290
                aGLHRepository branches do: [ :branch |
1✔
1291
                        self importCommitsOfBranch: branch ] ]
1✔
1292
]
1✔
1293

1294
{ #category : #'import - users' }
1295
GitlabModelImporter >> importUser: aUserID [
1✔
1296

1✔
1297
        | result userResult |
1✔
1298
        (self glhModel allWithType: GLHUser)
1✔
1299
                detect: [ :user | user id = aUserID ]
1✔
1300
                ifFound: [ :user | ^ user ].
1✔
1301
        ('Import user: ' , aUserID printString) recordInfo.
1✔
1302
        
1✔
1303
        result := self repoApi users get: aUserID.
1✔
1304
        userResult := self parseUserResult: result.
1✔
1305
        
1✔
1306
        userResult := self glhModel add: userResult unless: self blockOnIdEquality.
1✔
1307
        userCatalogue addUser: userResult.
1✔
1308
        ^ userResult 
1✔
1309
]
1✔
1310

1311
{ #category : #'import - users' }
1312
GitlabModelImporter >> importUserByUsername: anUsername [
1✔
1313

1✔
1314
        | dicUsername resultUser |
1✔
1315
        dicUsername := ((self glhModel allWithType: GLHUser) collect: [ :user |
1✔
1316
                                user username -> user ]) asSet asDictionary.
1✔
1317

1✔
1318
        dicUsername addAll: self userCatalogue collectUsernames.
1✔
1319

1✔
1320

1✔
1321
        resultUser := dicUsername
1✔
1322
                              at: anUsername
1✔
1323
                              ifAbsent: [ "thus we have to import this new user"
1✔
1324
                                      | result userId searchResult params |
1✔
1325
                                      ('Import user with username: '
1✔
1326
                                       , anUsername printString) recordInfo.
1✔
1327
                                      params := { (#search -> anUsername) } asDictionary.
1✔
1328
                                      result := self repoApi users allWithParams: params.
1✔
1329
                                                        
1✔
1330
                                                         "when result is an error"
1✔
1331
                                                         (result isString) ifTrue: [ result := { result } ].
1✔
1332
                                                        
1✔
1333
                                      searchResult := result ifEmpty: [ result ] ifNotEmpty: [(result collect: [ :usersJson |
1✔
1334
                                                               NeoJSONReader fromString: usersJson ]) first].
1✔
1335
                                                         
1✔
1336
                                      (searchResult class = Dictionary and: [
1✔
1337
                                               (searchResult at: #message) includesSubstring:
1✔
1338
                                                       '403 Forbidden' ])
1✔
1339
                                              ifTrue: [ "if the result is an 403 error we fake a new user"
1✔
1340
                                                      self glhModel
1✔
1341
                                                              add: (GLHUser new
1✔
1342
                                                                               username: anUsername;
1✔
1343
                                                                               name: anUsername;
1✔
1344
                                                                               yourself)
1✔
1345
                                                              unless: [ :nu :ou | nu username = ou username ] ]
1✔
1346
                                              ifFalse: [
1✔
1347
                                                      searchResult
1✔
1348
                                                              ifEmpty: [ "results can be empty thus we force a new user with the info we have "
1✔
1349
                                                                      self glhModel
1✔
1350
                                                                              add: (GLHUser new
1✔
1351
                                                                                               username: anUsername;
1✔
1352
                                                                                               name: anUsername;
1✔
1353
                                                                                               yourself)
1✔
1354
                                                                              unless: [ :nu :ou | nu username = ou username ] ]
1✔
1355
                                                              ifNotEmpty: [ "because we may already have the researched user, we look by ID in the model"
1✔
1356
                                                                      userId := searchResult first at: #id.
1✔
1357
                                                                      (self glhModel allWithType: GLHUser)
1✔
1358
                                                                              detect: [ :user | user id = userId ]
1✔
1359
                                                                              ifNone: [ self importUser: userId ] ] ] ].
1✔
1360

1✔
1361
        self userCatalogue addUser: resultUser withName: anUsername.
1✔
1362

1✔
1363
        ^ resultUser
1✔
1364
]
1✔
1365

1366
{ #category : #initialization }
1367
GitlabModelImporter >> initReader [
1✔
1368

1✔
1369
        generalReader := NeoJSONReader new.
1✔
1370
        self configureReaderForCommit: generalReader.
1✔
1371
        self configureReaderForGroup: generalReader.
1✔
1372
        self configureReaderForDiffs: generalReader.
1✔
1373
        self configureReaderForMergeRequest: generalReader.
1✔
1374
        self configureReaderForPipeline: generalReader. 
1✔
1375
]
1✔
1376

1377
{ #category : #initialization }
1378
GitlabModelImporter >> initialize [
1✔
1379

1✔
1380
        super initialize.
1✔
1381
        withCommitDiffs := true.
1✔
1382
        withInitialCommits := false.
1✔
1383
        withInitialMergeRequest := false.
1✔
1384

1✔
1385
        self withCommitsSince: 1 week.
1✔
1386

1✔
1387
        self initReader
1✔
1388
]
1✔
1389

1390
{ #category : #private }
1391
GitlabModelImporter >> isServerError: aString [
1✔
1392
        ^ aString = '{"message":"500 Internal Server Error"}'
1✔
1393
]
1✔
1394

1395
{ #category : #'import - projects' }
1396
GitlabModelImporter >> loadAllProjectsFromRepositorySoftware [
×
1397
        "heavy import that load all the active project inside the model. Only import the project entities"
×
1398
        |projects|
×
1399
        
×
1400
        projects := self repoApi projects. 
×
1401
]
×
1402

1403
{ #category : #'private - parsing' }
1404
GitlabModelImporter >> newParseCommitResult: result [
×
1405

×
1406
        generalReader  on: result readStream.
×
1407

×
1408
        ^ generalReader nextAs: GLHCommit
×
1409
]
×
1410

1411
{ #category : #'private - parsing' }
1412
GitlabModelImporter >> newParseDiffResult: result [
1✔
1413

1✔
1414
        generalReader on: result readStream.
1✔
1415
        ^ generalReader nextAs: #ArrayOfDiffs
1✔
1416
]
1✔
1417

1418
{ #category : #'private - parsing' }
1419
GitlabModelImporter >> parseArrayOfProject: arrayOfProjects [
×
1420

×
1421
        | reader |
×
1422
        reader := NeoJSONReader on: arrayOfProjects readStream.
×
1423
        reader
×
1424
                for: #ArrayOfProjects
×
1425
                customDo: [ :customMappting |
×
1426
                customMappting listOfElementSchema: GLHProject ].
×
1427
        reader for: GLHProject do: [ :mapping |
×
1428
                mapping mapInstVar: #name to: #name.
×
1429
                mapping mapInstVar: #description to: #description.
×
1430
                mapping mapInstVar: #id to: #id.
×
1431
                mapping mapInstVar: #archived to: #archived.
×
1432
                mapping mapInstVar: #web_url to: #html_url.
×
1433
                mapping mapInstVar: #topics to: #topics ].
×
1434
        ^ reader nextAs: #ArrayOfProjects
×
1435
]
×
1436

1437
{ #category : #'private - parsing' }
1438
GitlabModelImporter >> parseBranchesResult: result [
1✔
1439

1✔
1440
        | reader |
1✔
1441
        reader := NeoJSONReader on: result readStream.
1✔
1442
        reader mapInstVarsFor: GLHBranch.
1✔
1443
        reader
1✔
1444
                for: #ArrayOfBranch
1✔
1445
                customDo: [ :customMappting | 
1✔
1446
                customMappting listOfElementSchema: GLHBranch ].
1✔
1447
        ^ reader nextAs: #ArrayOfBranch
1✔
1448
]
1✔
1449

1450
{ #category : #'private - parsing' }
1451
GitlabModelImporter >> parseCommitResult: result [
×
1452

×
1453
        | reader |
×
1454
        reader := NeoJSONReader on: result readStream.
×
1455

×
1456
        reader for: GLHCommit do: [ :mapping |
×
1457
                mapping mapInstVars:
×
1458
                        #( id short_id title author_name author_email committer_name
×
1459
                           committer_email message web_url ).
×
1460
                (mapping mapInstVar: #authored_date) valueSchema: DateAndTime.
×
1461
                (mapping mapInstVar: #committed_date) valueSchema: DateAndTime.
×
1462
                (mapping mapInstVar: #created_at) valueSchema: DateAndTime.
×
1463
                (mapping mapInstVar: #parent_ids) valueSchema: #ArrayOfIds.
×
1464
                mapping
×
1465
                        mapProperty: 'stats'
×
1466
                        getter: [ :el | "Not used" ]
×
1467
                        setter: [ :commit :value |
×
1468
                                commit deletions: (value at: #deletions).
×
1469
                                commit additions: (value at: #additions) ] ].
×
1470

×
1471
        reader for: DateAndTime customDo: [ :mapping |
×
1472
                mapping decoder: [ :string | DateAndTime fromString: string ] ].
×
1473

×
1474
        reader
×
1475
                for: #ArrayOfIds
×
1476
                customDo: [ :mapping | mapping decoder: [ :string | string ] ].
×
1477

×
1478

×
1479
        ^ reader nextAs: GLHCommit
×
1480
]
×
1481

1482
{ #category : #'private - parsing' }
1483
GitlabModelImporter >> parseCommitsResult: result [
1✔
1484

1✔
1485
        | reader |
1✔
1486
        reader := NeoJSONReader on: result readStream.
1✔
1487

1✔
1488
          reader for: GLHCommit do: [ :mapping |
1✔
1489
                mapping mapInstVars:
1✔
1490
                        #( id short_id title author_name author_email committer_name
1✔
1491
                           committer_email message web_url ).
1✔
1492
                (mapping mapInstVar: #authored_date) valueSchema: DateAndTime.
1✔
1493
                (mapping mapInstVar: #committed_date) valueSchema: DateAndTime.
1✔
1494
                (mapping mapInstVar: #created_at) valueSchema: DateAndTime.
1✔
1495
                (mapping mapInstVar: #parent_ids) valueSchema: #ArrayOfIds.
1✔
1496
                mapping
1✔
1497
                        mapProperty: 'stats'
1✔
1498
                        getter: [ :el | "Not used" ]
1✔
1499
                        setter: [ :commit :value |
1✔
1500
                                commit deletions: (value at: #deletions).
1✔
1501
                                commit additions: (value at: #additions) ] ].
1✔
1502

1✔
1503
        reader for: DateAndTime customDo: [ :mapping |
1✔
1504
                mapping decoder: [ :string | DateAndTime fromString: string ] ].
1✔
1505

1✔
1506
        reader
1✔
1507
                for: #ArrayOfIds
1✔
1508
                customDo: [ :mapping | mapping decoder: [ :string | string ] ].
1✔
1509
  
1✔
1510
        reader
1✔
1511
                for: #ArrayOfCommit
1✔
1512
                customDo: [ :customMappting |
1✔
1513
                customMappting listOfElementSchema: GLHCommit ].
1✔
1514

1✔
1515
        ^ reader nextAs: #ArrayOfCommit
1✔
1516
]
1✔
1517

1518
{ #category : #private }
1519
GitlabModelImporter >> parseDiffResult: result [
×
1520

×
1521
        | reader |
×
1522
        self
×
1523
                deprecated: 'Use #newParseDiffResult: instead'
×
1524
                on: '28 June 2024'
×
1525
                in:
×
1526
                'Pharo-11.0.0+build.726.sha.aece1b5473acf3830a0e082c1bc3a15d4ff3522b (64 Bit)'.
×
1527
        reader := NeoJSONReader on: result readStream.
×
1528
        reader for: GLHDiff do: [ :mapping |
×
1529
                mapping mapInstVars:
×
1530
                        #( deleted_file new_file new_path old_path renamed_file ).
×
1531
                mapping mapInstVar: #diffString to: #diff ].
×
1532

×
1533
        reader
×
1534
                for: #ArrayOfDiffs
×
1535
                customDo: [ :customMappting |
×
1536
                customMappting listOfElementSchema: GLHDiff ].
×
1537
        ^ reader nextAs: #ArrayOfDiffs
×
1538
]
×
1539

1540
{ #category : #'private - parsing' }
1541
GitlabModelImporter >> parseFileTreeResult: aResult [
×
1542

×
1543
        | reader |
×
1544
        reader := NeoJSONReader on: aResult readStream.
×
1545
        reader mapInstVarsFor: GLHApiFile.
×
1546
        reader
×
1547
                for: #ArrayOfFile
×
1548
                customDo: [ :customMappting | 
×
1549
                customMappting listOfElementSchema: GLHApiFile ].
×
1550
        ^ reader nextAs: #ArrayOfFile
×
1551
]
×
1552

1553
{ #category : #'private - parsing' }
1554
GitlabModelImporter >> parseGroupResult: aResult [
1✔
1555

1✔
1556
        | reader |
1✔
1557

1✔
1558
        reader := NeoJSONReader on: aResult readStream.
1✔
1559
        reader for: GLHGroup do: [ :mapping |
1✔
1560
                mapping mapInstVars.
1✔
1561
                (mapping mapInstVar: #projects) valueSchema: #ArrayOfProjects ].
1✔
1562
        reader mapInstVarsFor: GLHProject.
1✔
1563
        reader
1✔
1564
                for: #ArrayOfProjects
1✔
1565
                customDo: [ :customMappting |
1✔
1566
                customMappting listOfElementSchema: GLHProject ].
1✔
1567
        ^ reader nextAs: GLHGroup
1✔
1568
]
1✔
1569

1570
{ #category : #'private - parsing' }
1571
GitlabModelImporter >> parseJobsResult: result ofProject: aProject [
×
1572

×
1573
        | reader |
×
1574
        reader := NeoJSONReader on: result readStream.
×
1575
        reader for: GLHJob do: [ :mapping |
×
1576
                mapping mapInstVars: #( id allow_failure web_url name ).
×
1577

×
1578
                mapping
×
1579
                        mapProperty: #user
×
1580
                        getter: [ :object | #ignore ]
×
1581
                        setter: [ :object :value |
×
1582
                        object user: (self importUser: (value at: #id)) ].
×
1583

×
1584
                mapping
×
1585
                        mapProperty: #commit
×
1586
                        getter: [ :object | #ignore ]
×
1587
                        setter: [ :object :value |
×
1588
                                value ifNotNil: [
×
1589
                                        object commit:
×
1590
                                                (self importCommit: (value at: #id) ofProject: aProject) ] ].
×
1591

×
1592
                mapping
×
1593
                        mapProperty: #duration
×
1594
                        getter: [ :object | #ignore ]
×
1595
                        setter: [ :object :value |
×
1596
                        value ifNotNil: [ object duration: value seconds ] ] ].
×
1597

×
1598
        reader
×
1599
                for: #ArrayOfGLHJob
×
1600
                customDo: [ :customMappting |
×
1601
                customMappting listOfElementSchema: GLHJob ].
×
1602
        ^ reader nextAs: #ArrayOfGLHJob
×
1603
]
×
1604

1605
{ #category : #'private - parsing' }
1606
GitlabModelImporter >> parseMergeRequestsResult: result [
1✔
1607

1✔
1608
        generalReader on: result readStream.
1✔
1609
        ^ generalReader nextAs: #ArrayOfMergeRequest
1✔
1610
]
1✔
1611

1612
{ #category : #'private - parsing' }
1613
GitlabModelImporter >> parseNoteJson: results [  
1✔
1614
    | reader |  
1✔
1615

1✔
1616
    "Créer un lecteur JSON"
1✔
1617
    reader := NeoJSONReader on: results readStream.    
1✔
1618

1✔
1619
    "Définir le mapping pour l'objet GLHNote"
1✔
1620
    reader for: GLHNote do: [ :mapping |  
1✔
1621
        mapping mapInstVars: #(id noteable_id attachment system confidential internal  
1✔
1622
                               noteable_iid resolvable imported imported_from  
1✔
1623
                               author body project_id noteable_type).  
1✔
1624

1✔
1625
        (mapping mapInstVar: #created_at) valueSchema: DateAndTime.  
1✔
1626
        (mapping mapInstVar: #updated_at) valueSchema: DateAndTime.  
1✔
1627
    ].    
1✔
1628

1✔
1629
    "Corriger la conversion des dates"
1✔
1630
    reader for: DateAndTime customDo: [ :mapping |  
1✔
1631
        mapping decoder: [ :string | DateAndTime readFrom: string readStream ] ].
1✔
1632

1✔
1633
        reader
1✔
1634
                for: #ArrayOfNote
1✔
1635
                customDo: [ :customMappting | 
1✔
1636
                customMappting listOfElementSchema: GLHNote ].
1✔
1637
         ^ reader nextAs: #ArrayOfNote
1✔
1638

1✔
1639
    "Retourner la Note"
1✔
1640
    "^ reader nextAs: GLHNote"
1✔
1641

1✔
1642

1✔
1643
]
1✔
1644

1645
{ #category : #'private - parsing' }
NEW
1646
GitlabModelImporter >> parsePipelineResult: result [
×
NEW
1647

×
NEW
1648
        | reader |
×
NEW
1649
        
×
NEW
1650
        (result includesSubstring: '{"message":"40' )ifTrue: [ ^ {  } ].
×
NEW
1651
        
×
NEW
1652
        reader := generalReader on: result readStream.
×
NEW
1653
        
×
NEW
1654
        ^ reader nextAs: GLHPipeline
×
NEW
1655
]
×
1656

1657
{ #category : #'private - parsing' }
1658
GitlabModelImporter >> parsePipelinesResult: result [
1✔
1659

1✔
1660
        | reader |
1✔
1661
        
1✔
1662
        (result includesSubstring: '{"message":"40' )ifTrue: [ ^ {  } ].
1✔
1663
        
1✔
1664
        reader := generalReader on: result readStream.
1✔
1665
        
1✔
1666
        ^ reader nextAs: #ArrayOfPipelines
1✔
1667
]
1✔
1668

1669
{ #category : #'private - parsing' }
1670
GitlabModelImporter >> parseProjectResult: aResult [ 
1✔
1671
                | reader |
1✔
1672
        reader := NeoJSONReader on: aResult readStream.
1✔
1673
        reader for: GLHProject do: [ :mapping |
1✔
1674
                mapping mapInstVars. ].
1✔
1675
"        reader mapInstVarsFor: GLHProject."
1✔
1676

1✔
1677
        ^ reader nextAs: GLHProject
1✔
1678
]
1✔
1679

1✔
1680
{ #category : #'private - parsing' }
1✔
1681
GitlabModelImporter >> parseSubGroupResult: aResult [
1✔
1682

1✔
1683
        | reader |
1✔
1684
        reader := NeoJSONReader on: aResult readStream.
1✔
1685
        self configureReaderForGroup: reader.
1✔
1686
        ^ reader nextAs: #ArrayOfGroups
1✔
1687
]
1✔
1688

1✔
1689
{ #category : #'private - parsing' }
1✔
1690
GitlabModelImporter >> parseUserResult: result [
1✔
1691

1✔
1692
        | reader |
1✔
1693
        reader := NeoJSONReader on: result readStream.
1✔
1694
        reader mapInstVarsFor: GLHUser.
1✔
1695
        ^ reader nextAs: GLHUser
1✔
1696
]
1✔
1697

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

1✔
1701
        | reader |
1✔
1702
        reader := NeoJSONReader on: result readStream.
1✔
1703

1✔
1704
        reader mapInstVarsFor: GLHUser.
1✔
1705

1✔
1706
        reader
1✔
1707
                for: #ArrayOfUser
1✔
1708
                customDo: [ :customMappting |
1✔
1709
                customMappting listOfElementSchema: GLHUser ].
1✔
1710

1✔
1711
        ^ reader nextAs: #ArrayOfUser
1✔
1712
]
1✔
1713

1✔
1714
{ #category : #'import - projects' }
1✔
1715
GitlabModelImporter >> partiallyImportProject: aProjectID [
1✔
1716

1✔
1717
        | result projectResult |
1✔
1718
        ('Import project with id:  ' , aProjectID printString) recordInfo.
1✔
1719

1✔
1720
        (glhModel allWithType: GLHProject)
1✔
1721
                detect: [ :project | project id = aProjectID ]
1✔
1722
                ifFound: [ :project | ^ project ].
1✔
1723

1✔
1724
        result := self repoApi projects get: aProjectID.
1✔
1725
        projectResult := self parseProjectResult: result.
1✔
1726

1✔
1727
        projectResult repository: GLHRepository new.
1✔
1728
        self glhModel add: projectResult repository.
1✔
1729
        self importRepository: projectResult repository.
1✔
1730

1✔
1731
        ^ projectResult
1✔
1732
]
1✔
1733

1✔
1734
{ #category : #'import - pipelines' }
1✔
1735
GitlabModelImporter >> pipelinesOf: aProjectID withLimit: aLimit [
1✔
1736

1✔
1737
        | result |
1✔
1738
        ('Search pipelines of: ' , aProjectID printString) recordInfo.
1✔
1739
        result := self repoApi pipelines getByPage: 1 perPage: aLimit inProject: aProjectID.
1✔
1740
        result isString ifTrue: [ ^ self parsePipelinesResult: result ].
1✔
1741

1✔
1742
        ^ (result collect: [ :pipelinesJson |
1✔
1743
                           self parsePipelinesResult: pipelinesJson ]) flattened
1✔
1744
]
1✔
1745

1✔
1746
{ #category : #accessing }
1✔
1747
GitlabModelImporter >> repoApi: anObject [
1✔
1748
        super repoApi: anObject.
1✔
1749
        self repoApi output: 'json'
1✔
1750
]
1✔
1751

1✔
1752
{ #category : #private }
1✔
1753
GitlabModelImporter >> selectEntityType: aType overAttribut: aSelector equalTo: value [
1✔
1754

1✔
1755
        ^ (self glhModel allWithType: aType)
1✔
1756
                select: [ :entity | (entity perform: aSelector) = value ]
1✔
1757
]
1✔
1758

1✔
1759
{ #category : #'import - groups' }
1✔
1760
GitlabModelImporter >> subGroupsOf: aGroupID [
1✔
1761

1✔
1762
        | results subgroups |
1✔
1763
        ('Search subgroup of: ' , aGroupID printString) recordInfo.
1✔
1764
        results := self repoApi groups subgroupsOf: aGroupID.
1✔
1765
        subgroups := (results collect: [ :subgroupsJson | self parseSubGroupResult: subgroupsJson ]) flattened.
1✔
1766
        
1✔
1767
        ^ subgroups
1✔
1768
]
1✔
1769

1✔
1770
{ #category : #accessing }
1✔
1771
GitlabModelImporter >> withInitialCommits: boolean [
1✔
1772
        withInitialCommits := boolean 
1✔
1773
]
1✔
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