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

moosetechnology / GitProjectHealth / 15488438209

06 Jun 2025 10:27AM UTC coverage: 72.472% (-0.8%) from 73.222%
15488438209

Pull #202

github

web-flow
Merge pull request #203 from moosetechnology/fix-loading-issue-jira

fix baseline
Pull Request #202: Update Main

938 of 1987 new or added lines in 20 files covered. (47.21%)

38 existing lines in 2 files now uncovered.

16141 of 22272 relevant lines covered (72.47%)

0.72 hits per line

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

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

167
{ #category : #'import - pipelines' }
NEW
168
GitlabModelImporter >> completeImportedPipelines: aCollectionOfGLHPipeline [
×
NEW
169
        ^ aCollectionOfGLHPipeline collect: [ :pipeline | self completeImportedPipeline: pipeline ].  
×
NEW
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
                        (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 }
386
GitlabModelImporter >> convertApiFileAsFile: aAPIFile [
×
387

×
388
        aAPIFile type = 'tree' ifTrue: [ 
×
389
                ^ GLHFileDirectory new
×
390
                          name: aAPIFile name;
×
391
                          yourself ].
×
392
        ^ GLHFileBlob new
×
393
                  name: aAPIFile name;
×
394
                  yourself
×
395
]
×
396

397
{ #category : #private }
398
GitlabModelImporter >> detectEntityType: aType overAttribut: aSelector equalTo: value [
1✔
399

1✔
400
        ^ (self glhModel allWithType: aType) detect: [ :entity |
1✔
401
                  (entity perform: aSelector) = value ] ifNone: [ nil ]. 
1✔
402
]
1✔
403

404
{ #category : #accessing }
405
GitlabModelImporter >> glhApi [
×
406

×
407
        self
×
408
                deprecated: 'Use #repoApi instead'
×
409
                on: '7 October 2024'
×
410
                in:
×
411
                'Pharo-11.0.0+build.726.sha.aece1b5473acf3830a0e082c1bc3a15d4ff3522b (64 Bit)'.
×
412

×
413
        ^ repoApi
×
414
]
×
415

416
{ #category : #accessing }
417
GitlabModelImporter >> glhApi: anObject [
×
418

×
419
        self
×
420
                deprecated: 'Use #repoApi: instead'
×
421
                on: '7 October 2024'
×
422
                in:
×
423
                'Pharo-11.0.0+build.726.sha.aece1b5473acf3830a0e082c1bc3a15d4ff3522b (64 Bit)'.
×
424

×
425
        repoApi := anObject
×
426
]
×
427

428
{ #category : #accessing }
429
GitlabModelImporter >> glhModel [
1✔
430

1✔
431
        ^ glhModel
1✔
432
]
1✔
433

434
{ #category : #accessing }
435
GitlabModelImporter >> glhModel: anObject [
1✔
436

1✔
437
        glhModel := anObject
1✔
438
]
1✔
439

440
{ #category : #'import - users' }
441
GitlabModelImporter >> importActiveHumanUsers [
×
442

×
443
        | params result users |
×
444
        params := { 
×
445
                #humans -> 'true'.
×
446
                #active -> 'true'.
×
447
                #without_project_bots -> 'true'
×
448
        } asDictionary.
×
449
        result := self repoApi users allWithParams: params.
×
450
        users := (result collect: [ :usersJson | self parseUsersResult: usersJson ]) flattened.
×
451
        
×
452
        self glhModel
×
453
                                 addAll: users
×
454
                                 unless: self blockOnIdEquality.
×
455

×
456
        ^ users
×
457
]
×
458

459
{ #category : #'import - groups' }
460
GitlabModelImporter >> importAllGroups [
×
461

×
462
        | params results groups |
×
463
        
×
464
        params := { 
×
465
                        #top_level_only -> 'true'
×
466
        } asDictionary.
×
467
        results := self repoApi groups getAllWithParams: params.
×
468
        
×
469
        groups := (results collect: [ :groupsJson | generalReader
×
470
                                            on: groupsJson readStream;
×
471
                                            nextAs: #ArrayOfGroups. ]) flattened.
×
472
        ^ groups
×
473
]
×
474

475
{ #category : #'import - pipelines' }
NEW
476
GitlabModelImporter >> importAllPipelinesOfProject: aGLHProject [
×
NEW
477

×
NEW
478
        (self allPipelinesOf: aGLHProject id) do: [ :pipeline |
×
NEW
479
                |pip|
×
NEW
480
                pip := self glhModel add: pipeline unless: self blockOnIdEquality .
×
NEW
481
                pip := aGLHProject pipelines add: pip unless: self blockOnIdEquality.
×
NEW
482
                self completeImportedPipeline: pip. 
×
NEW
483
                ].
×
NEW
484
        
×
NEW
485
        ^ aGLHProject pipelines
×
NEW
486
]
×
487

488
{ #category : #'import - commits' }
489
GitlabModelImporter >> importAndLoadLatestsCommitsOfProject: aGLHProject [
×
490

×
491
        | commits completedProject |
×
NEW
492
        completedProject := self completeImportedProject: aGLHProject.
×
493
        commits := self importLastestCommitsOfProject: completedProject.
×
494
        commits do: [ :commit | self completeImportedCommit: commit ].
×
495
        self chainsCommitsFrom: commits.
×
496
        ^ commits
×
497
]
×
498

499
{ #category : #'import - commits' }
500
GitlabModelImporter >> importCommit: aCommitID ofProject: aGLHProject [
×
501

×
502
        | result parsedResult |
×
503
        (self glhModel allWithType: GLHCommit) asOrderedCollection
×
504
                detect: [ :commit | commit id = aCommitID ]
×
505
                ifFound: [ :commit | ^ commit ].
×
506
        result := self repoApi commits get: aCommitID inProject: aGLHProject id.
×
507
        
×
508
        parsedResult := self parseCommitResult: result.
×
509
        
×
510
        self
×
511
                addCommits: { parsedResult }
×
512
                toRepository: aGLHProject repository.
×
513
        ^ parsedResult
×
514
]
×
515

516
{ #category : #'import - commits' }
517
GitlabModelImporter >> importCommitOfProject: anProject withId: anID [
1✔
518

1✔
519
        | commit result |
1✔
520
        anID ifNil: [ ^ nil ].
1✔
521

1✔
522
        ('looking for commit ' , anID printString , ' in project : '
1✔
523
         , anProject id printString) recordInfo.
1✔
524

1✔
525
        commit := (self
1✔
526
                           detectEntityType: GLHCommit
1✔
527
                           overAttribut: #id
1✔
528
                           equalTo: anID) ifNil: [
1✔
529
                          result := self repoApi commits get: anID inProject: anProject id.
1✔
530
                          commit := (self parseCommitsResult: '[' , result , ']')
1✔
531
                                            first.
1✔
532

1✔
533
                          self glhModel add: commit unless: self blockOnIdEquality.
1✔
534
                          commit repository: anProject repository.
1✔
535

1✔
536
                          commit ].
1✔
537

1✔
538
        self withCommitDiffs ifTrue: [ self importDiffOfCommit: commit ].
1✔
539

1✔
540
        ^ commit
1✔
541
]
1✔
542

543
{ #category : #'import - commits' }
544
GitlabModelImporter >> importCommits: aGLHProject [
×
545
        "limited to the last 20 commits"
×
546

×
547
        | results parsedResults params |
×
548
        params := { 
×
549
         #with_stats -> 'true'
×
550
        } asDictionary.
×
551
        results := self repoApi commits getByPage: 1 perPage: 20 inProject: aGLHProject id withParams: params.
×
552
        
×
553
        parsedResults := self parseCommitsResult: results.
×
554
        self glhModel addAll: parsedResults unless: self blockOnIdEquality.
×
555

×
556
        parsedResults do: [ :commit |
×
557
                commit repository: aGLHProject repository ].
×
558

×
559
        self withCommitDiffs ifTrue: [
×
560
                parsedResults do: [ :commit | self importDiffOfCommit: commit ] ].
×
561
        
×
562
        ^ parsedResults. 
×
563
]
×
564

565
{ #category : #'import - commits' }
566
GitlabModelImporter >> importCommitsFollowing: aCommit upToDays: aNumberOfDay [
×
567
        "import the 'n' commits of a project starting from an initial 'aCommit' commit. 
×
568
        Lazy import does not import the entities inside the model"
×
569

×
570
        | date |
×
571
        date := aCommit created_at asDateAndTime.
×
572

×
573
        ^ self
×
574
                  importCommitsOfBranch: aCommit branch
×
575
                  forRefName: aCommit branch name
×
576
                  since: date
×
577
                  until: (date + aNumberOfDay day)
×
578
]
×
579

580
{ #category : #commit }
581
GitlabModelImporter >> importCommitsOf: aGLHProject withStats: aBoolean until: toDate [
×
582

×
583
        | newlyFoundCommit page |
×
584
        
×
585
        self deprecated: [  ] .
×
586
        
×
587
        page := 0.
×
588
        newlyFoundCommit := { true }.
×
589
        [ newlyFoundCommit isNotEmpty ] whileTrue: [
×
590
                | results parsedResults existingCommits |
×
591
                page := page + 1.
×
592
                ('import commit page ' , page printString) recordInfo.
×
593
                results := self repoApi
×
594
                                   commitsOfProject: aGLHProject id
×
595
                                   forRefName: nil
×
596
                                   since: nil
×
597
                                   until: nil
×
598
                                   path: nil
×
599
                                   author: nil
×
600
                                   all: nil
×
601
                                   with_stats: aBoolean
×
602
                                   firstParent: nil
×
603
                                   order: nil
×
604
                                   trailers: nil
×
605
                                   perPage: 100
×
606
                                   page: page.
×
607
                parsedResults := self parseCommitsResult: results.
×
608
                existingCommits := aGLHProject mooseModel allWithType: GLHCommit.
×
609

×
610
                newlyFoundCommit := parsedResults reject: [ :commitParsed |
×
611
                                            (toDate isNil or: [
×
612
                                                     commitParsed committed_date
×
613
                                                     < toDate asDateAndTime ]) or: [
×
614
                                                    existingCommits anySatisfy: [ :existingCommit |
×
615
                                                            existingCommit id = commitParsed id ] ] ].
×
616
                aGLHProject mooseModel addAll: newlyFoundCommit.
×
617
                aGLHProject repository commits addAll: newlyFoundCommit ].
×
618

×
619

×
620
        self withCommitDiffs ifTrue: [
×
621
                aGLHProject repository commits do: [ :commit |
×
622
                        self importDiffOfCommit: commit ] ]
×
623
]
×
624

625
{ #category : #'import - commits' }
626
GitlabModelImporter >> importCommitsOfBranch: aGLHBranch [
×
627

×
628
        | commits |
×
629
        "        result := self glhApi
×
630
                          commitsOfProject: aGLHBranch repository project id
×
631
                          forRefName: aGLHBranch name."
×
632
        commits := self
×
633
                           importCommitsOfBranch: aGLHBranch
×
634
                           forRefName: aGLHBranch name
×
635
                           since: withCommitsSince.
×
636

×
637
        self chainsCommitsFrom: commits.
×
638

×
639
        commits do: [ :aCommit |
×
640
                aCommit repository: aGLHBranch repository.
×
641
                self completeImportedCommit: aCommit. 
×
642
                 ]
×
643
]
×
644

645
{ #category : #'import - commits' }
646
GitlabModelImporter >> importCommitsOfBranch: aGLHBranch forRefName: refName since: fromDate [
×
647

×
648
        ^ self
×
649
                  importCommitsOfBranch: aGLHBranch
×
650
                  forRefName: aGLHBranch name
×
651
                  since: fromDate
×
652
                  until: nil
×
653
]
×
654

655
{ #category : #'import - commits' }
656
GitlabModelImporter >> importCommitsOfBranch: aGLHBranch forRefName: refName since: fromDate until: toDate [
×
657

×
658
        | params result allCommits |
×
659
        params := { 
×
660
          #ref_name -> aGLHBranch name.
×
661
          #since ->  (fromDate ifNotNil: [ fromDate asDate asDateAndTime asString ] ifNil: [ '' ]).
×
662
          #until -> (toDate ifNotNil: [ toDate asDate asDateAndTime asString ] ifNil: [ '' ]). 
×
663

×
664
        } asDictionary.
×
665
        result := self repoApi commits getAllInProject: aGLHBranch repository project id withParams: params.
×
666
        
×
667
        allCommits := (result collect: [ :commitsJson | self parseCommitsResult: commitsJson ]) flattened.
×
668
        
×
669
        aGLHBranch commits
×
670
                        addAll: allCommits
×
671
                        unless: self blockOnIdEquality.
×
672

×
673
        self glhModel
×
674
                addAll: aGLHBranch commits
×
675
                unless: self blockOnIdEquality.
×
676

×
677
        ^ allCommits
×
678
]
×
679

680
{ #category : #'import - commits' }
681
GitlabModelImporter >> importCommitsOfBranch: aGLHBranch forRefName: refName until: toDate [
×
682

×
683
        ^ self
×
684
                  importCommitsOfBranch: aGLHBranch
×
685
                  forRefName: aGLHBranch name
×
686
                  since: nil
×
687
                  until: toDate
×
688
]
×
689

690
{ #category : #'import - commits' }
691
GitlabModelImporter >> importCommitsOfProject: aProject since: fromDate until: toDate [
1✔
692

1✔
693
        | params results allCommits |
1✔
694
        params := {
1✔
695
                          (#since
1✔
696
                           ->
1✔
697
                           (fromDate
1✔
698
                                    ifNotNil: [ fromDate asDate asDateAndTime asString ]
1✔
699
                                    ifNil: [ '' ])).
1✔
700
                          (#until
1✔
701
                           ->
1✔
702
                           (toDate
1✔
703
                                    ifNotNil: [ toDate asDate asDateAndTime asString ]
1✔
704
                                    ifNil: [ '' ])).
1✔
705
                          (#with_stats -> 'true').
1✔
706
                          (#all -> 'true') } asDictionary.
1✔
707
        results := self repoApi commits
1✔
708
                           getAllInProject: aProject id
1✔
709
                           withParams: params.
1✔
710

1✔
711
        allCommits := (results collect: [ :commitsJson |
1✔
712
                               self parseCommitsResult: commitsJson ]) flattened.
1✔
713

1✔
714
        allCommits:= aProject repository commits
1✔
715
                addAll: allCommits
1✔
716
                unless: self blockOnIdEquality.
1✔
717

1✔
718
        ^ self glhModel addAll: allCommits unless: self blockOnIdEquality
1✔
719
]
1✔
720

721
{ #category : #'import - projects' }
722
GitlabModelImporter >> importContributedProjectsOfUser: aGLHUser [
×
723

×
724
        | remaningProjects params results projects projectsIds |
×
725
        params := {
×
726
                          (#order_by -> 'last_activity_at').
×
727
                          (#simple -> 'true') } asDictionary.
×
728
        results := self repoApi projects
×
729
                           contributedProjectsOfUser: aGLHUser id
×
730
                           withParams: params.
×
731

×
732
        projectsIds := (results collect: [ :projectsJson |
×
733
                             (NeoJSONReader fromString: projectsJson) collect: [:projectJson | projectJson at: #id ] ]) flattened.
×
734
        
×
735
        projects := self importProjects: projectsIds.
×
736
        remaningProjects := self importProjects:
×
737
                                    ((projects collect: #id) difference:
×
738
                                             ((self userCatalogue atId: aGLHUser id) at:
×
739
                                                      #contributedProjects)).
×
740

×
741

×
742
        aGLHUser contributedProjects
×
743
                addAll: projects , remaningProjects
×
744
                unless: self blockOnIdEquality.
×
745

×
746
        self userCatalogue
×
747
                addUser: aGLHUser
×
748
                withProjects: (aGLHUser contributedProjects collect: #id).
×
749

×
750
        ^ projects
×
751
]
×
752

753
{ #category : #'import - commits' }
754
GitlabModelImporter >> importCreatorOfCommit: aCommit [
1✔
755

1✔
756
        aCommit commitCreator ifNil: [
1✔
757
                aCommit commitCreator:
1✔
758
                        (self importUserByUsername: aCommit author_name) ].
1✔
759
        self userCatalogue
1✔
760
                addUser: aCommit commitCreator
1✔
761
                withProject: aCommit repository project id.
1✔
762
        ^ aCommit commitCreator
1✔
763
]
1✔
764

765
{ #category : #'import - commits' }
766
GitlabModelImporter >> importDiffOfCommit: aCommit [
1✔
767

1✔
768
        | result diffsResult |
1✔
769
        aCommit diffs ifNotEmpty: [
1✔
770
                'Diff already importer: ' , aCommit short_id printString recordInfo.
1✔
771
                ^ aCommit diffs ].
1✔
772
        ('Import diff of commit: ' , aCommit short_id printString) recordInfo.
1✔
773

1✔
774
        result := self repoApi commits
1✔
775
                          diffOf: aCommit id
1✔
776
                          inProject: aCommit repository project id
1✔
777
                          uniDiff: true.
1✔
778

1✔
779
        (self isServerError: result) ifTrue: [ ^ {  } ].
1✔
780
        diffsResult := self newParseDiffResult: result.
1✔
781

1✔
782
        aCommit diffs addAll: diffsResult unless: self blockForDiffEquality.
1✔
783
        
1✔
784
        "changes are added into the model during the import"
1✔
785
        aCommit diffs do: [ :diff | self importDiffRangesForDiff: diff ].
1✔
786

1✔
787
        ^ aCommit diffs
1✔
788
]
1✔
789

790
{ #category : #'import - merge request' }
791
GitlabModelImporter >> importDiffOfMergeRequest: aMergeRequest [
1✔
792

1✔
793
        | result diffsResult |
1✔
794
        aMergeRequest diffs ifNotEmpty: [
1✔
795
                'Diff of already importer: '
1✔
796
                , aMergeRequest iid printString recordInfo.
1✔
797
                ^ aMergeRequest diffs ].
1✔
798
        ('Import diff commits of MR ' , aMergeRequest iid printString)
1✔
799
                recordInfo.
1✔
800
        result := self repoApi mergeRequests diffsOf: aMergeRequest iid inProject: aMergeRequest project_id.
1✔
801

1✔
802
        diffsResult := self newParseDiffResult: result.
1✔
803

1✔
804

1✔
805
        aMergeRequest diffs
1✔
806
                addAll: diffsResult
1✔
807
                unless: self blockForDiffEquality.
1✔
808
        self glhModel
1✔
809
                addAll: aMergeRequest diffs
1✔
810
                unless: self blockForDiffEquality.
1✔
811

1✔
812
        aMergeRequest diffs do: [ :diff | self importDiffRangesForDiff: diff ].
1✔
813

1✔
814
        ^ aMergeRequest diffs
1✔
815
]
1✔
816

817
{ #category : #'import - repositories' }
818
GitlabModelImporter >> importDirectoryFiles: aDirectoryFile OfBranch: aBranch [
×
819

×
820
        | result files apiFiles params |
×
821
        params := { 
×
822
                #ref -> aBranch name.
×
823
                #path -> (aDirectoryFile path , '/')
×
824
        } asDictionary.
×
825
        result := self repoApi repositories repositoryTreeOfProject: aBranch repository project id withParams: params.
×
826
                         " treeOfRepository: aBranch repository project id
×
827
                          ofBranch: aBranch name
×
828
                          andPath: aDirectoryFile path , '/'."
×
829
        apiFiles := (result collect: [ :treeJson | self parseFileTreeResult: treeJson ]) flattened.
×
830
        files := apiFiles collect: [ :apiFile |
×
831
                         self convertApiFileAsFile: apiFile ].
×
832
        
×
833
        files do: [ :file |
×
834
                self glhModel add: file.
×
835
                aDirectoryFile addFile: file ].
×
836
        
×
837
        files
×
838
                select: [ :file | file isKindOf: GLHFileDirectory ]
×
839
                thenCollect: [ :file |
×
840
                self importDirectoryFiles: file OfBranch: aBranch ]
×
841
]
×
842

843
{ #category : #'import - repositories' }
844
GitlabModelImporter >> importFilesOfBranch: aBranch [
×
845

×
846
        | result files apiFiles params |
×
847
        params := { 
×
848
                #ref -> aBranch name.
×
849
        } asDictionary.
×
850
        
×
851
        result := self repoApi repositories repositoryTreeOfProject: aBranch repository project id withParams: params.
×
852
        
×
853
                          "treeOfRepository: aBranch repository project id
×
854
                          ofBranch: aBranch name
×
855
                          andPath: nil."
×
856
        apiFiles := (result collect: [ :filesJson | self parseFileTreeResult: filesJson  ]) flattened.
×
857
        files := apiFiles collect: [ :apiFile | 
×
858
                         self convertApiFileAsFile: apiFile ].
×
859
        files do: [ :file | 
×
860
                self glhModel add: file.
×
861
                aBranch addFile: file ].
×
862
        files
×
863
                select: [ :file | file isKindOf: GLHFileDirectory ]
×
864
                thenCollect: [ :file | 
×
865
                self importDirectoryFiles: file OfBranch: aBranch ]
×
866
]
×
867

868
{ #category : #'import - groups' }
869
GitlabModelImporter >> importGroup: aGroupID [
1✔
870

1✔
871
        | result groupResult |
1✔
872
        ('Import group: ' , aGroupID printString) recordInfo.
1✔
873

1✔
874
        result := self repoApi groups get: aGroupID.
1✔
875
        
1✔
876
        "group: aGroupID."
1✔
877
        groupResult := self parseGroupResult: result.
1✔
878
        groupResult := self addGroupResultToModel: groupResult.
1✔
879

1✔
880
        groupResult projects do: [ :project |
1✔
881
                self completeImportedProject: project ].
1✔
882

1✔
883
        (self subGroupsOf: aGroupID) do: [ :subGroup |
1✔
884
                
1✔
885
                groupResult subGroups
1✔
886
                        add: (self importGroup: subGroup id)
1✔
887
                        unless: self blockOnIdEquality ].
1✔
888
        ^ groupResult
1✔
889
]
1✔
890

891
{ #category : #'import - jobs' }
892
GitlabModelImporter >> importJobsOf: aPipeline [
×
893

×
894
        | jobs results |
×
NEW
895
        results := self repoApi jobs
×
NEW
896
                           getAllForPipeline: aPipeline id
×
NEW
897
                           inProject: aPipeline project id.
×
NEW
898
        "jobsOfProject: aPipeline project id
×
899
                          ofPipelines: aPipeline id."
×
NEW
900
        jobs := (results collect: [ :jobsJson |
×
NEW
901
                         self parseJobsResult: jobsJson ofProject: aPipeline project ])
×
NEW
902
                        flattened.
×
903
        jobs do: [ :job | aPipeline addJob: job ].
×
904
        self glhModel addAll: jobs.
×
905

×
NEW
906
        ^ jobs
×
UNCOV
907
]
×
908

909
{ #category : #'import - commits' }
910
GitlabModelImporter >> importLastestCommitsOfProject: aGLHProject [
1✔
911
        "limited to the last 50 commits"
1✔
912

1✔
913
        | results parsedResults params |
1✔
914
        params := { 
1✔
915
                #with_stats -> 'true'.
1✔
916
                #all -> true
1✔
917
         } asDictionary.
1✔
918
        results := self repoApi commits getByPage: 1 perPage: 50 inProject: aGLHProject id withParams: params.
1✔
919

1✔
920
        parsedResults := self parseCommitsResult: results.
1✔
921
        parsedResults := self glhModel
1✔
922
                                 addAll: parsedResults
1✔
923
                                 unless: self blockOnIdEquality.
1✔
924

1✔
925
        aGLHProject repository commits
1✔
926
                addAll: parsedResults
1✔
927
                unless: self blockOnIdEquality.
1✔
928

1✔
929
        self withCommitDiffs ifTrue: [
1✔
930
                parsedResults do: [ :commit | self importDiffOfCommit: commit ] ].
1✔
931

1✔
932
        ^ parsedResults
1✔
933
]
1✔
934

935
{ #category : #'import - merge request' }
NEW
936
GitlabModelImporter >> importLatestMergeRequestsOfProject: aGLHProject [ 
×
NEW
937
        
×
NEW
938
        |results parsedResults|
×
NEW
939
        results := self repoApi mergeRequests getByPage: 1 perPage: 20  inProject: aGLHProject id. 
×
NEW
940
        parsedResults := self parseMergeRequestsResult: results. 
×
NEW
941
        
×
NEW
942
        parsedResults := glhModel addAll: parsedResults unless: self blockOnIdEquality.
×
NEW
943
        parsedResults := aGLHProject mergeRequests addAll: parsedResults unless: self blockOnIdEquality.
×
NEW
944
        ^ parsedResults.
×
NEW
945
]
×
946

947
{ #category : #'import - pipelines' }
948
GitlabModelImporter >> importLatestPipelinesOfProject: aGLHProject [ 
1✔
949
        (self pipelinesOf: aGLHProject id withLimit:20) do: [ :pipeline |
1✔
950
                |pip|
1✔
951
                pip := self glhModel add: pipeline unless: self blockOnIdEquality .
1✔
952
                pip := aGLHProject pipelines add: pip unless: self blockOnIdEquality.
1✔
953
                self completeImportedPipeline: pip. 
1✔
954
                ].
1✔
955
        
1✔
956
        ^ aGLHProject pipelines 
1✔
957
]
1✔
958

959
{ #category : #'import - merge request' }
960
GitlabModelImporter >> importMergeRequestCommits: aGLPHEMergeRequest [
×
961

×
962
        | commits result |
×
963
        aGLPHEMergeRequest commits ifNotNil: [ ^ aGLPHEMergeRequest commits ].
×
964
        
×
965
        result := self repoApi mergeRequests commitsOf: aGLPHEMergeRequest iid inProject: aGLPHEMergeRequest project id.
×
966
        
×
967
        commits := (result collect: [ :commitsJson | self parseCommitsResult: commitsJson ]) flattened.
×
968
        commits := commits collect: [ :commit | self importCommit: commit id ofProject: aGLPHEMergeRequest project ].
×
969
        aGLPHEMergeRequest commits: commits.
×
970

×
971

×
972
        ^ commits
×
973
]
×
974

975
{ #category : #'import - merge request' }
976
GitlabModelImporter >> importMergeRequestMergeCommits: aGLPHEMergeRequest [
1✔
977

1✔
978
        | foundCommits |
1✔
979
        foundCommits := OrderedCollection new.
1✔
980

1✔
981
        ('Import commit sha of MR:  ' , aGLPHEMergeRequest iid printString)
1✔
982
                recordInfo.
1✔
983
        "the founds commits are added to the model during their respective import"
1✔
984
        aGLPHEMergeRequest mergeRequestCommit: ((self
1✔
985
                          importCommitOfProject: aGLPHEMergeRequest project
1✔
986
                          withId: aGLPHEMergeRequest sha) ifNotNil: [ :commit |
1✔
987
                         foundCommits add: commit ]).
1✔
988

1✔
989
        ('Import commit merge_commit_sha of MR:  '
1✔
990
         , aGLPHEMergeRequest iid printString) recordInfo.
1✔
991
        aGLPHEMergeRequest mergedCommit: ((self
1✔
992
                          importCommitOfProject: aGLPHEMergeRequest project
1✔
993
                          withId: aGLPHEMergeRequest merge_commit_sha) ifNotNil: [ :commit |
1✔
994
                         foundCommits add: commit ]).
1✔
995

1✔
996
        ('Import commit squash_commit_sha of MR:  '
1✔
997
         , aGLPHEMergeRequest iid printString) recordInfo.
1✔
998
        aGLPHEMergeRequest squashCommit: ((self
1✔
999
                          importCommitOfProject: aGLPHEMergeRequest project
1✔
1000
                          withId: aGLPHEMergeRequest squash_commit_sha) ifNotNil: [ :commit |
1✔
1001
                         foundCommits add: commit ]).
1✔
1002

1✔
1003

1✔
1004
        self chainsCommitsFrom: foundCommits.
1✔
1005
        ^ foundCommits
1✔
1006
]
1✔
1007

1008
{ #category : #'import - pipelines' }
NEW
1009
GitlabModelImporter >> importMergeRequestPipelines: aGLHMergeRequest [ 
×
NEW
1010
        "default limit to one page with last 100 pipelines"
×
NEW
1011
        
×
NEW
1012
        |results parseResults|
×
NEW
1013
        
×
NEW
1014
        results := self repoApi pipelines getByPage: 1 perPage: 100 inProject: aGLHMergeRequest project id forMergerRequestIid: aGLHMergeRequest iid. 
×
NEW
1015
        
×
NEW
1016
        parseResults := self parsePipelinesResult: results.
×
NEW
1017
        
×
NEW
1018
        parseResults := glhModel addAll: parseResults unless: self blockOnIdEquality.
×
NEW
1019
        parseResults := aGLHMergeRequest pipelines addAll: parseResults unless: self blockOnIdEquality.
×
NEW
1020
        ^ parseResults collect: [ :pip | self completeImportedPipeline: pip ]  .
×
NEW
1021
        
×
NEW
1022
]
×
1023

1024
{ #category : #'import - merge request' }
1025
GitlabModelImporter >> importMergeRequests: aGLHProject [
1✔
1026

1✔
1027
        | results parsedResults mrs |
1✔
1028
        ('Import merge request of Project: ' , aGLHProject id printString)
1✔
1029
                recordInfo.
1✔
1030

1✔
1031
        results := self repoApi mergeRequests allOfProject: aGLHProject id.
1✔
1032
        parsedResults := (results collect: [ :projectsJson | self parseMergeRequestsResult: projectsJson ]) flattened. 
1✔
1033

1✔
1034
        aGLHProject mergeRequests
1✔
1035
                addAll: parsedResults
1✔
1036
                unless: self blockOnIdEquality.
1✔
1037

1✔
1038
        mrs := self glhModel
1✔
1039
                       addAll: aGLHProject mergeRequests
1✔
1040
                       unless: self blockOnIdEquality.
1✔
1041

1✔
1042

1✔
1043
        "gets it related commits"
1✔
1044
        aGLHProject mergeRequests do: [ :mr |
1✔
1045
                self importMergeRequestMergeCommits: mr ].
1✔
1046

1✔
1047

1✔
1048
        self withCommitDiffs ifTrue: [
1✔
1049
                aGLHProject mergeRequests do: [ :mr |
1✔
1050
                        self importDiffOfMergeRequest: mr ] ].
1✔
1051

1✔
1052
        ^ mrs
1✔
1053
]
1✔
1054

1055
{ #category : #'import - merge request' }
1056
GitlabModelImporter >> importMergeRequests: aGLHProject since: fromDate until: toDate [
×
1057

×
1058
        | params result mergeRequests |
×
1059
        ('import MR of Project ' , aGLHProject name) recordInfo.
×
1060
        params := {
×
1061
                          (#created_after
×
1062
                           ->
×
1063
                           (fromDate
×
1064
                                    ifNotNil: [ fromDate asDateAndTime asString ]
×
1065
                                    ifNil: [ '' ])).
×
1066
                          (#created_before
×
1067
                           ->
×
1068
                           (toDate
×
1069
                                    ifNotNil: [ toDate asDateAndTime asString ]
×
1070
                                    ifNil: [ '' ])).
×
1071
                          (#scope -> 'all') } asDictionary.
×
1072

×
1073
        result := self repoApi mergeRequests
×
1074
                          allOfProject: aGLHProject id
×
1075
                          withParams: params.
×
1076
        mergeRequests := (result collect: [ :mergeRequestsJson |
×
NEW
1077
                                  self parseMergeRequestsResult: mergeRequestsJson ])
×
1078
                                 flattened.
×
1079

×
1080
        aGLHProject mergeRequests
×
1081
                addAll: mergeRequests
×
1082
                unless: self blockOnIdEquality.
×
1083

×
1084
        "gets it related commits"
×
1085
        aGLHProject mergeRequests do: [ :mr |
×
1086
                self importMergeRequestMergeCommits: mr ].
×
1087

×
1088
        self withCommitDiffs ifTrue: [
×
1089
                aGLHProject mergeRequests do: [ :mr |
×
1090
                        self importDiffOfMergeRequest: mr ] ].
×
1091

×
1092
        self glhModel
×
1093
                addAll: mergeRequests
×
1094
                unless: (self blockEqualityOn: #iid).
×
1095

×
1096
        ^ mergeRequests
×
1097
]
×
1098

1099
{ #category : #'import - merge request' }
1100
GitlabModelImporter >> importMergeResquestApprovals: aGLPHEMergeRequest [
×
1101

×
1102
        | results parsedResult |
×
1103
        (String streamContents: [ :str |
×
1104
                 str << 'Check approvals of '.
×
1105
                 aGLPHEMergeRequest printOn: str ]) recordInfo.
×
1106
        results := self repoApi mergeRequests approvalsOf: aGLPHEMergeRequest iid inProject: aGLPHEMergeRequest project id.
×
1107

×
1108
        parsedResult := generalReader
×
1109
                                on: results readStream;
×
1110
                                next.
×
1111

×
1112
        (parsedResult at: #approved_by) do: [ :approvedUser |
×
1113
                aGLPHEMergeRequest addApproved_by:
×
1114
                        (self importUser: ((approvedUser at: #user) at: #id)) ].
×
1115
        aGLPHEMergeRequest approved: (parsedResult at: #approved).
×
1116
        ^ aGLPHEMergeRequest
×
1117
]
×
1118

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

1✔
1122
        | authorID |
1✔
1123
        aGLPHEMergeRequest author ifNotNil: [ ^ aGLPHEMergeRequest author ].
1✔
1124
        authorID := aGLPHEMergeRequest cacheAt: #authorID ifAbsent: [
1✔
1125
                            | result |
1✔
1126
                            result := self repoApi mergeRequests
1✔
1127
                                              get: aGLPHEMergeRequest iid
1✔
1128
                                              inProject: aGLPHEMergeRequest project_id.
1✔
1129

1✔
1130
                            (generalReader
1✔
1131
                                     on: result readStream;
1✔
1132
                                     next) at: #author at: #id ].
1✔
1133
        ^aGLPHEMergeRequest author: (self importUser: authorID)
1✔
1134
]
1✔
1135

1136
{ #category : #'import - merge request' }
1137
GitlabModelImporter >> importMergeResquestMerger: aGLPHEMergeRequest [
1✔
1138

1✔
1139
        | authorID |
1✔
1140
        aGLPHEMergeRequest merge_user ifNotNil: [
1✔
1141
                ^ aGLPHEMergeRequest merge_user ].
1✔
1142
        authorID := aGLPHEMergeRequest cacheAt: #mergeUserID ifAbsent: [
1✔
1143
                            | result |
1✔
1144
                            result := self repoApi mergeRequests
1✔
1145
                                              get: aGLPHEMergeRequest iid
1✔
1146
                                              inProject: aGLPHEMergeRequest project_id.
1✔
1147
                            (generalReader
1✔
1148
                                     on: result readStream;
1✔
1149
                                     next)
1✔
1150
                                    at: #merge_user
1✔
1151
                                    ifPresent: [ :mergeUser |
1✔
1152
                                    mergeUser ifNotNil: [ :mruser | mruser at: #id ] ] ].
1✔
1153
        ^aGLPHEMergeRequest merge_user: (self importUser: authorID)
1✔
1154
]
1✔
1155

1156
{ #category : #'import - notes' }
1157
GitlabModelImporter >> importNotesfromMergeRequest: mergeRequest [
×
1158
        | results notes |
×
1159
        
×
1160
        results := self repoApi notes allInMergeRequest: mergeRequest iid ofProject: mergeRequest project id.
×
1161
        
×
1162
        notes := results collect: [ :note | 
×
1163
                self parseNoteJson: note ].
×
1164
        "notes := self parseNoteJson: results."
×
1165
        notes do: [ :tabNotes | tabNotes do: [ :note |
×
1166
                        note author: (self importUser: (note author at: #id)).
×
1167
                        note name: note id asString]. ].
×
1168
        notes := notes flattened.
×
1169
        notes := self glhModel addAll: notes unless: self blockOnIdEquality. 
×
1170
        notes := mergeRequest note addAll: notes unless: self blockOnIdEquality. 
×
1171
        ^notes
×
1172
        
×
1173
]
×
1174

1175
{ #category : #'import - commits' }
1176
GitlabModelImporter >> importParentCommitsOfCommit: aGLHCommit since: aDate [
×
1177

×
1178
        | parentsIds commits |
×
1179
        commits := OrderedCollection new.
×
1180
        aGLHCommit created_at asDateAndTime < aDate asDateAndTime ifTrue: [
×
1181
                 
×
1182
                ^ commits
×
1183
                          add: aGLHCommit;
×
1184
                          yourself ].
×
1185

×
1186
        parentsIds := aGLHCommit parent_ids.
×
1187

×
1188
        commits addAll: (parentsIds collect: [ :id |
×
1189
                         self
×
1190
                                 importCommitOfProject: aGLHCommit repository project
×
1191
                                 withId: id ]).
×
1192

×
1193

×
1194
        ^ (commits collect: [ :parentCommit |
×
1195
                   self importParentCommitsOfCommit: parentCommit since: aDate ])
×
1196
                  flatten
×
1197
]
×
1198

1199
{ #category : #'import - pipelines' }
NEW
1200
GitlabModelImporter >> importPipeline: pipelineId OfProject: aGLHProject [
×
NEW
1201

×
NEW
1202
        
×
NEW
1203
        | result pipeline|
×
NEW
1204
        
×
NEW
1205
        aGLHProject pipelines detect: [ :pip | pip id = pipelineId ] ifOne: [ :pip| ^pip ].
×
NEW
1206
        
×
NEW
1207
        ('Search pipelines of: ' , aGLHProject id printString) recordInfo.
×
NEW
1208
        result := self repoApi pipelines get: pipelineId inProject: aGLHProject id.
×
NEW
1209
        result isString ifTrue: [ ^ self parsePipelineResult: result ].
×
NEW
1210

×
NEW
1211
        pipeline :=  self parsePipelineResult: result.
×
NEW
1212

×
NEW
1213
        pipeline := self glhModel add: pipeline unless: self blockOnIdEquality .
×
NEW
1214
        pipeline := aGLHProject pipelines add: pipeline unless: self blockOnIdEquality.
×
NEW
1215
        
×
NEW
1216
        ^ self completeImportedPipeline: pipeline. 
×
NEW
1217
]
×
1218

1219
{ #category : #'import - pipelines' }
NEW
1220
GitlabModelImporter >> importPipelinesOfProject: aGLHProject after: after andBefore: before [
×
NEW
1221
        ^ (self pipelinesOf: aGLHProject id after: after andBefore: before) collect: [ :pipeline |
×
NEW
1222
                |pip|
×
NEW
1223
                pip := self glhModel add: pipeline unless: self blockOnIdEquality .
×
NEW
1224
                pip := aGLHProject pipelines add: pip unless: self blockOnIdEquality.
×
NEW
1225
                
×
NEW
1226
                ].
×
NEW
1227
        
×
NEW
1228
]
×
1229

1230
{ #category : #'import - pipelines' }
NEW
1231
GitlabModelImporter >> importPipelinesOfProject: aGLHProject after: after andBefore: before onBranch: aBranch [
×
NEW
1232
        | result parsedResults|
×
NEW
1233
        ('Search pipelines of: ' , aGLHProject id printString) recordInfo.
×
NEW
1234
        
×
NEW
1235
        result := self repoApi pipelines getAllInProject: aGLHProject id 
×
NEW
1236
                                                                                                withParams: {        #updated_before -> before.
×
NEW
1237
                                                                                                                                        #updated_after -> after.
×
NEW
1238
                                                                                                                                        #ref -> aBranch name} asDictionary .
×
NEW
1239
        result isString ifTrue: [ ^ self parsePipelinesResult: result ].
×
UNCOV
1240

×
NEW
1241
        parsedResults := (result collect: [ :pipelinesJson |
×
NEW
1242
                           self parsePipelinesResult: pipelinesJson ]) flattened.
×
NEW
1243
        
×
NEW
1244

×
NEW
1245
        ^ parsedResults collect: [ :pipeline |
×
NEW
1246
                |pip|
×
NEW
1247
                pip := self glhModel add: pipeline unless: self blockOnIdEquality .
×
NEW
1248
                aGLHProject pipelines add: pip unless: self blockOnIdEquality.
×
NEW
1249
                ].
×
NEW
1250
        
×
UNCOV
1251
]
×
1252

1253
{ #category : #'import - projects' }
1254
GitlabModelImporter >> importProject: aProjectID [
1✔
1255

1✔
1256
        | result projectResult |
1✔
1257
        ('Import project with id:  ' , aProjectID printString) recordInfo.
1✔
1258

1✔
1259
        (glhModel allWithType: GLHProject)
1✔
1260
                detect: [ :project | project id = aProjectID ]
1✔
1261
                ifFound: [ :project | ^ project ].
1✔
1262

1✔
1263
        result := self repoApi projects get: aProjectID.
1✔
1264
        projectResult := self parseProjectResult: result.
1✔
1265

1✔
1266
        ^ self completeImportedProject: projectResult
1✔
1267
]
1✔
1268

1269
{ #category : #'import - projects' }
1270
GitlabModelImporter >> importProjects [
×
1271

×
1272
        | result projects |
×
1273
        ('import all Projects') recordInfo.
×
1274

×
1275

×
1276
        result := self repoApi projects all.
×
1277
        projects := (result collect: [ :projectsJson | self parseArrayOfProject: projectsJson ]) flattened.
×
1278
        
×
1279
        self glhModel addAll: projects unless: self blockOnIdEquality.
×
1280

×
1281
        ^ projects
×
1282
]
×
1283

1284
{ #category : #'import - projects' }
1285
GitlabModelImporter >> importProjectsSince: since [
×
1286
        "heavy import of all projects"
×
1287

×
1288
        "copy import from commits"
×
1289

×
1290
        | newlyFoundProjects page foundProject amount |
×
1291
        ('import all Projects since: ' , since printString) recordInfo.
×
1292

×
1293
        "number of projects per page"
×
1294
        amount := 100.
×
1295
        page := 0.
×
1296
        foundProject := OrderedCollection new.
×
1297
        newlyFoundProjects := { true }.
×
1298
        [ newlyFoundProjects isNotEmpty ] whileTrue: [
×
1299
                | results |
×
1300
                page := page + 1.
×
1301
                ('import projects page #' , page printString) recordInfo.
×
1302

×
NEW
1303
                results := self repoApi projects allWithParams: {#since -> since} asDictionary .
×
1304

×
1305
                newlyFoundProjects := self glhModel
×
1306
                                              addAll: (self parseArrayOfProject: results)
×
1307
                                              unless: self blockOnIdEquality.
×
1308
                foundProject addAll: newlyFoundProjects ].
×
1309
]
×
1310

1311
{ #category : #'import - repositories' }
1312
GitlabModelImporter >> importRepository: aGLHRepository [
1✔
1313

1✔
1314
        | resultBranches branches |
1✔
1315
        [
1✔
1316
        ('import the repository of project ' , aGLHRepository project name)
1✔
1317
                recordInfo.
1✔
1318

1✔
1319
        resultBranches := self repoApi branches getAllFromProject:
1✔
1320
                                  aGLHRepository project id.
1✔
1321

1✔
1322
        branches := (resultBranches collect: [ :branchesJson |
1✔
1323
                             self parseBranchesResult: branchesJson ]) flattened.
1✔
1324

1✔
1325
        'import the branches of project ' recordInfo.
1✔
1326

1✔
1327
        branches := aGLHRepository branches
1✔
1328
                            addAll: branches
1✔
1329
                            unless: self blockOnNameEquality.
1✔
1330
        branches := self glhModel
1✔
1331
                            addAll: branches
1✔
1332
                            unless: self blockOnNameEquality.
1✔
1333

1✔
1334

1✔
1335
        self withFiles ifTrue: [
1✔
1336
                branches do: [ :branch | self importFilesOfBranch: branch ] ] ]
1✔
1337
                on: NeoJSONParseError
1✔
1338
                do: [
1✔
1339
                self inform: aGLHRepository project name , ' has no repository' ].
1✔
1340
        
1✔
1341
        withInitialCommits ifTrue: [
1✔
1342
                aGLHRepository branches do: [ :branch |
1✔
1343
                        self importCommitsOfBranch: branch ] ]
1✔
1344
]
1✔
1345

1346
{ #category : #'import - users' }
1347
GitlabModelImporter >> importUser: aUserID [
1✔
1348

1✔
1349
        | result userResult |
1✔
1350
        (self glhModel allWithType: GLHUser)
1✔
1351
                detect: [ :user | user id = aUserID ]
1✔
1352
                ifFound: [ :user | ^ user ].
1✔
1353
        ('Import user: ' , aUserID printString) recordInfo.
1✔
1354
        
1✔
1355
        result := self repoApi users get: aUserID.
1✔
1356
        userResult := self parseUserResult: result.
1✔
1357
        
1✔
1358
        userResult := self glhModel add: userResult unless: self blockOnIdEquality.
1✔
1359
        userCatalogue addUser: userResult.
1✔
1360
        ^ userResult 
1✔
1361
]
1✔
1362

1363
{ #category : #'import - users' }
1364
GitlabModelImporter >> importUserByUsername: anUsername [
1✔
1365

1✔
1366
        | dicUsername resultUser |
1✔
1367
        dicUsername := ((self glhModel allWithType: GLHUser) collect: [ :user |
1✔
1368
                                user username -> user ]) asSet asDictionary.
1✔
1369

1✔
1370
        dicUsername addAll: self userCatalogue collectUsernames.
1✔
1371

1✔
1372

1✔
1373
        resultUser := dicUsername
1✔
1374
                              at: anUsername
1✔
1375
                              ifAbsent: [ "thus we have to import this new user"
1✔
1376
                                      | result userId searchResult params |
1✔
1377
                                      ('Import user with username: '
1✔
1378
                                       , anUsername printString) recordInfo.
1✔
1379
                                      params := { (#search -> anUsername) } asDictionary.
1✔
1380
                                      result := self repoApi users allWithParams: params.
1✔
1381
                                                        
1✔
1382
                                                         "when result is an error"
1✔
1383
                                                         (result isString) ifTrue: [ result := { result } ].
1✔
1384
                                                        
1✔
1385
                                      searchResult := result ifEmpty: [ result ] ifNotEmpty: [(result collect: [ :usersJson |
1✔
1386
                                                               NeoJSONReader fromString: usersJson ]) first].
1✔
1387
                                                         
1✔
1388
                                      (searchResult class = Dictionary and: [
1✔
1389
                                               (searchResult at: #message) includesSubstring:
1✔
1390
                                                       '403 Forbidden' ])
1✔
1391
                                              ifTrue: [ "if the result is an 403 error we fake a new user"
1✔
1392
                                                      self glhModel
1✔
1393
                                                              add: (GLHUser new
1✔
1394
                                                                               username: anUsername;
1✔
1395
                                                                               name: anUsername;
1✔
1396
                                                                               yourself)
1✔
1397
                                                              unless: [ :nu :ou | nu username = ou username ] ]
1✔
1398
                                              ifFalse: [
1✔
1399
                                                      searchResult
1✔
1400
                                                              ifEmpty: [ "results can be empty thus we force a new user with the info we have "
1✔
1401
                                                                      self glhModel
1✔
1402
                                                                              add: (GLHUser new
1✔
1403
                                                                                               username: anUsername;
1✔
1404
                                                                                               name: anUsername;
1✔
1405
                                                                                               yourself)
1✔
1406
                                                                              unless: [ :nu :ou | nu username = ou username ] ]
1✔
1407
                                                              ifNotEmpty: [ "because we may already have the researched user, we look by ID in the model"
1✔
1408
                                                                      userId := searchResult first at: #id.
1✔
1409
                                                                      (self glhModel allWithType: GLHUser)
1✔
1410
                                                                              detect: [ :user | user id = userId ]
1✔
1411
                                                                              ifNone: [ self importUser: userId ] ] ] ].
1✔
1412

1✔
1413
        self userCatalogue addUser: resultUser withName: anUsername.
1✔
1414

1✔
1415
        ^ resultUser
1✔
1416
]
1✔
1417

1418
{ #category : #initialization }
1419
GitlabModelImporter >> initReader [
1✔
1420

1✔
1421
        generalReader := NeoJSONReader new.
1✔
1422
        self configureReaderForCommit: generalReader.
1✔
1423
        self configureReaderForGroup: generalReader.
1✔
1424
        self configureReaderForDiffs: generalReader.
1✔
1425
        self configureReaderForMergeRequest: generalReader.
1✔
1426
        self configureReaderForPipeline: generalReader. 
1✔
1427
]
1✔
1428

1429
{ #category : #initialization }
1430
GitlabModelImporter >> initialize [
1✔
1431

1✔
1432
        super initialize.
1✔
1433
        withCommitDiffs := true.
1✔
1434
        withInitialCommits := false.
1✔
1435
        withInitialMergeRequest := false.
1✔
1436

1✔
1437
        self withCommitsSince: 1 week.
1✔
1438

1✔
1439
        self initReader
1✔
1440
]
1✔
1441

1442
{ #category : #private }
1443
GitlabModelImporter >> isServerError: aString [
1✔
1444
        ^ aString = '{"message":"500 Internal Server Error"}'
1✔
1445
]
1✔
1446

1447
{ #category : #'import - projects' }
1448
GitlabModelImporter >> loadAllProjectsFromRepositorySoftware [
×
1449
        "heavy import that load all the active project inside the model. Only import the project entities"
×
1450
        |projects|
×
1451
        
×
1452
        projects := self repoApi projects. 
×
1453
]
×
1454

1455
{ #category : #'private - parsing' }
1456
GitlabModelImporter >> newParseCommitResult: result [
×
1457

×
1458
        generalReader  on: result readStream.
×
1459

×
1460
        ^ generalReader nextAs: GLHCommit
×
1461
]
×
1462

1463
{ #category : #'private - parsing' }
1464
GitlabModelImporter >> newParseDiffResult: result [
1✔
1465

1✔
1466
        generalReader on: result readStream.
1✔
1467
        ^ generalReader nextAs: #ArrayOfDiffs
1✔
1468
]
1✔
1469

1470
{ #category : #'private - parsing' }
1471
GitlabModelImporter >> parseArrayOfProject: arrayOfProjects [
×
1472

×
1473
        | reader |
×
1474
        reader := NeoJSONReader on: arrayOfProjects readStream.
×
1475
        reader
×
1476
                for: #ArrayOfProjects
×
1477
                customDo: [ :customMappting |
×
1478
                customMappting listOfElementSchema: GLHProject ].
×
1479
        reader for: GLHProject do: [ :mapping |
×
1480
                mapping mapInstVar: #name to: #name.
×
1481
                mapping mapInstVar: #description to: #description.
×
1482
                mapping mapInstVar: #id to: #id.
×
1483
                mapping mapInstVar: #archived to: #archived.
×
1484
                mapping mapInstVar: #web_url to: #html_url.
×
1485
                mapping mapInstVar: #topics to: #topics ].
×
1486
        ^ reader nextAs: #ArrayOfProjects
×
1487
]
×
1488

1489
{ #category : #'private - parsing' }
1490
GitlabModelImporter >> parseBranchesResult: result [
1✔
1491

1✔
1492
        | reader |
1✔
1493
        reader := NeoJSONReader on: result readStream.
1✔
1494
        reader mapInstVarsFor: GLHBranch.
1✔
1495
        reader
1✔
1496
                for: #ArrayOfBranch
1✔
1497
                customDo: [ :customMappting | 
1✔
1498
                customMappting listOfElementSchema: GLHBranch ].
1✔
1499
        ^ reader nextAs: #ArrayOfBranch
1✔
1500
]
1✔
1501

1502
{ #category : #'private - parsing' }
1503
GitlabModelImporter >> parseCommitResult: result [
×
1504

×
1505
        | reader |
×
1506
        reader := NeoJSONReader on: result readStream.
×
1507

×
1508
        reader for: GLHCommit do: [ :mapping |
×
1509
                mapping mapInstVars:
×
1510
                        #( id short_id title author_name author_email committer_name
×
1511
                           committer_email message web_url ).
×
1512
                (mapping mapInstVar: #authored_date) valueSchema: DateAndTime.
×
1513
                (mapping mapInstVar: #committed_date) valueSchema: DateAndTime.
×
1514
                (mapping mapInstVar: #created_at) valueSchema: DateAndTime.
×
1515
                (mapping mapInstVar: #parent_ids) valueSchema: #ArrayOfIds.
×
1516
                mapping
×
1517
                        mapProperty: 'stats'
×
1518
                        getter: [ :el | "Not used" ]
×
1519
                        setter: [ :commit :value |
×
1520
                                commit deletions: (value at: #deletions).
×
1521
                                commit additions: (value at: #additions) ] ].
×
1522

×
1523
        reader for: DateAndTime customDo: [ :mapping |
×
1524
                mapping decoder: [ :string | DateAndTime fromString: string ] ].
×
1525

×
1526
        reader
×
1527
                for: #ArrayOfIds
×
1528
                customDo: [ :mapping | mapping decoder: [ :string | string ] ].
×
1529

×
1530

×
1531
        ^ reader nextAs: GLHCommit
×
1532
]
×
1533

1534
{ #category : #'private - parsing' }
1535
GitlabModelImporter >> parseCommitsResult: result [
1✔
1536

1✔
1537
        | reader |
1✔
1538
        reader := NeoJSONReader on: result readStream.
1✔
1539

1✔
1540
          reader for: GLHCommit do: [ :mapping |
1✔
1541
                mapping mapInstVars:
1✔
1542
                        #( id short_id title author_name author_email committer_name
1✔
1543
                           committer_email message web_url ).
1✔
1544
                (mapping mapInstVar: #authored_date) valueSchema: DateAndTime.
1✔
1545
                (mapping mapInstVar: #committed_date) valueSchema: DateAndTime.
1✔
1546
                (mapping mapInstVar: #created_at) valueSchema: DateAndTime.
1✔
1547
                (mapping mapInstVar: #parent_ids) valueSchema: #ArrayOfIds.
1✔
1548
                mapping
1✔
1549
                        mapProperty: 'stats'
1✔
1550
                        getter: [ :el | "Not used" ]
1✔
1551
                        setter: [ :commit :value |
1✔
1552
                                commit deletions: (value at: #deletions).
1✔
1553
                                commit additions: (value at: #additions) ] ].
1✔
1554

1✔
1555
        reader for: DateAndTime customDo: [ :mapping |
1✔
1556
                mapping decoder: [ :string | DateAndTime fromString: string ] ].
1✔
1557

1✔
1558
        reader
1✔
1559
                for: #ArrayOfIds
1✔
1560
                customDo: [ :mapping | mapping decoder: [ :string | string ] ].
1✔
1561
  
1✔
1562
        reader
1✔
1563
                for: #ArrayOfCommit
1✔
1564
                customDo: [ :customMappting |
1✔
1565
                customMappting listOfElementSchema: GLHCommit ].
1✔
1566

1✔
1567
        ^ reader nextAs: #ArrayOfCommit
1✔
1568
]
1✔
1569

1570
{ #category : #private }
1571
GitlabModelImporter >> parseDiffResult: result [
×
1572

×
1573
        | reader |
×
1574
        self
×
1575
                deprecated: 'Use #newParseDiffResult: instead'
×
1576
                on: '28 June 2024'
×
1577
                in:
×
1578
                'Pharo-11.0.0+build.726.sha.aece1b5473acf3830a0e082c1bc3a15d4ff3522b (64 Bit)'.
×
1579
        reader := NeoJSONReader on: result readStream.
×
1580
        reader for: GLHDiff do: [ :mapping |
×
1581
                mapping mapInstVars:
×
1582
                        #( deleted_file new_file new_path old_path renamed_file ).
×
1583
                mapping mapInstVar: #diffString to: #diff ].
×
1584

×
1585
        reader
×
1586
                for: #ArrayOfDiffs
×
1587
                customDo: [ :customMappting |
×
1588
                customMappting listOfElementSchema: GLHDiff ].
×
1589
        ^ reader nextAs: #ArrayOfDiffs
×
1590
]
×
1591

1592
{ #category : #'private - parsing' }
1593
GitlabModelImporter >> parseFileTreeResult: aResult [
×
1594

×
1595
        | reader |
×
1596
        reader := NeoJSONReader on: aResult readStream.
×
1597
        reader mapInstVarsFor: GLHApiFile.
×
1598
        reader
×
1599
                for: #ArrayOfFile
×
1600
                customDo: [ :customMappting | 
×
1601
                customMappting listOfElementSchema: GLHApiFile ].
×
1602
        ^ reader nextAs: #ArrayOfFile
×
1603
]
×
1604

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

1✔
1608
        | reader |
1✔
1609

1✔
1610
        reader := NeoJSONReader on: aResult readStream.
1✔
1611
        reader for: GLHGroup do: [ :mapping |
1✔
1612
                mapping mapInstVars.
1✔
1613
                (mapping mapInstVar: #projects) valueSchema: #ArrayOfProjects ].
1✔
1614
        reader mapInstVarsFor: GLHProject.
1✔
1615
        reader
1✔
1616
                for: #ArrayOfProjects
1✔
1617
                customDo: [ :customMappting |
1✔
1618
                customMappting listOfElementSchema: GLHProject ].
1✔
1619
        ^ reader nextAs: GLHGroup
1✔
1620
]
1✔
1621

1622
{ #category : #'private - parsing' }
1623
GitlabModelImporter >> parseJobsResult: result ofProject: aProject [
×
1624

×
1625
        | reader |
×
1626
        reader := NeoJSONReader on: result readStream.
×
1627
        reader for: GLHJob do: [ :mapping |
×
1628
                mapping mapInstVars: #( id allow_failure web_url name ).
×
1629

×
1630
                mapping
×
1631
                        mapProperty: #user
×
1632
                        getter: [ :object | #ignore ]
×
1633
                        setter: [ :object :value |
×
1634
                        object user: (self importUser: (value at: #id)) ].
×
1635

×
1636
                mapping
×
1637
                        mapProperty: #commit
×
1638
                        getter: [ :object | #ignore ]
×
1639
                        setter: [ :object :value |
×
1640
                                value ifNotNil: [
×
1641
                                        object commit:
×
1642
                                                (self importCommit: (value at: #id) ofProject: aProject) ] ].
×
1643

×
1644
                mapping
×
1645
                        mapProperty: #duration
×
1646
                        getter: [ :object | #ignore ]
×
1647
                        setter: [ :object :value |
×
1648
                        value ifNotNil: [ object duration: value seconds ] ] ].
×
1649

×
1650
        reader
×
1651
                for: #ArrayOfGLHJob
×
1652
                customDo: [ :customMappting |
×
1653
                customMappting listOfElementSchema: GLHJob ].
×
1654
        ^ reader nextAs: #ArrayOfGLHJob
×
1655
]
×
1656

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

1✔
1660
        generalReader on: result readStream.
1✔
1661
        ^ generalReader nextAs: #ArrayOfMergeRequest
1✔
1662
]
1✔
1663

1664
{ #category : #'private - parsing' }
1665
GitlabModelImporter >> parseNoteJson: results [  
1✔
1666
    | reader |  
1✔
1667

1✔
1668
    "Créer un lecteur JSON"
1✔
1669
    reader := NeoJSONReader on: results readStream.    
1✔
1670

1✔
1671
    "Définir le mapping pour l'objet GLHNote"
1✔
1672
    reader for: GLHNote do: [ :mapping |  
1✔
1673
        mapping mapInstVars: #(id noteable_id attachment system confidential internal  
1✔
1674
                               noteable_iid resolvable imported imported_from  
1✔
1675
                               author body project_id noteable_type).  
1✔
1676

1✔
1677
        (mapping mapInstVar: #created_at) valueSchema: DateAndTime.  
1✔
1678
        (mapping mapInstVar: #updated_at) valueSchema: DateAndTime.  
1✔
1679
    ].    
1✔
1680

1✔
1681
    "Corriger la conversion des dates"
1✔
1682
    reader for: DateAndTime customDo: [ :mapping |  
1✔
1683
        mapping decoder: [ :string | DateAndTime readFrom: string readStream ] ].
1✔
1684

1✔
1685
        reader
1✔
1686
                for: #ArrayOfNote
1✔
1687
                customDo: [ :customMappting | 
1✔
1688
                customMappting listOfElementSchema: GLHNote ].
1✔
1689
         ^ reader nextAs: #ArrayOfNote
1✔
1690

1✔
1691
    "Retourner la Note"
1✔
1692
    "^ reader nextAs: GLHNote"
1✔
1693

1✔
1694

1✔
1695
]
1✔
1696

1697
{ #category : #'private - parsing' }
NEW
1698
GitlabModelImporter >> parsePipelineResult: result [
×
NEW
1699

×
NEW
1700
        | reader |
×
NEW
1701
        
×
NEW
1702
        (result includesSubstring: '{"message":"40' )ifTrue: [ ^ {  } ].
×
NEW
1703
        
×
NEW
1704
        reader := generalReader on: result readStream.
×
NEW
1705
        
×
NEW
1706
        ^ reader nextAs: GLHPipeline
×
NEW
1707
]
×
1708

1709
{ #category : #'private - parsing' }
1710
GitlabModelImporter >> parsePipelinesResult: result [
1✔
1711

1✔
1712
        | reader |
1✔
1713
        
1✔
1714
        (result includesSubstring: '{"message":"40' )ifTrue: [ ^ {  } ].
1✔
1715
        
1✔
1716
        reader := generalReader on: result readStream.
1✔
1717
        
1✔
1718
        ^ reader nextAs: #ArrayOfPipelines
1✔
1719
]
1✔
1720

1721
{ #category : #'private - parsing' }
1722
GitlabModelImporter >> parseProjectResult: aResult [ 
1✔
1723
                | reader |
1✔
1724
        reader := NeoJSONReader on: aResult readStream.
1✔
1725
        reader for: GLHProject do: [ :mapping |
1✔
1726
                mapping mapInstVars. ].
1✔
1727
"        reader mapInstVarsFor: GLHProject."
1✔
1728

1✔
1729
        ^ reader nextAs: GLHProject
1✔
1730
]
1✔
1731

1✔
1732
{ #category : #'private - parsing' }
1✔
1733
GitlabModelImporter >> parseSubGroupResult: aResult [
1✔
1734

1✔
1735
        | reader |
1✔
1736
        reader := NeoJSONReader on: aResult readStream.
1✔
1737
        self configureReaderForGroup: reader.
1✔
1738
        ^ reader nextAs: #ArrayOfGroups
1✔
1739
]
1✔
1740

1✔
1741
{ #category : #'private - parsing' }
1✔
1742
GitlabModelImporter >> parseUserResult: result [
1✔
1743

1✔
1744
        | reader |
1✔
1745
        reader := NeoJSONReader on: result readStream.
1✔
1746
        reader mapInstVarsFor: GLHUser.
1✔
1747
        ^ reader nextAs: GLHUser
1✔
1748
]
1✔
1749

1✔
1750
{ #category : #'private - parsing' }
1✔
1751
GitlabModelImporter >> parseUsersResult: result [
1✔
1752

1✔
1753
        | reader |
1✔
1754
        reader := NeoJSONReader on: result readStream.
1✔
1755

1✔
1756
        reader mapInstVarsFor: GLHUser.
1✔
1757

1✔
1758
        reader
1✔
1759
                for: #ArrayOfUser
1✔
1760
                customDo: [ :customMappting |
1✔
1761
                customMappting listOfElementSchema: GLHUser ].
1✔
1762

1✔
1763
        ^ reader nextAs: #ArrayOfUser
1✔
1764
]
1✔
1765

1✔
1766
{ #category : #'import - projects' }
1✔
1767
GitlabModelImporter >> partiallyImportProject: aProjectID [
1✔
1768

1✔
1769
        | result projectResult |
1✔
1770
        ('Import project with id:  ' , aProjectID printString) recordInfo.
1✔
1771

1✔
1772
        (glhModel allWithType: GLHProject)
1✔
1773
                detect: [ :project | project id = aProjectID ]
1✔
1774
                ifFound: [ :project | ^ project ].
1✔
1775

1✔
1776
        result := self repoApi projects get: aProjectID.
1✔
1777
        projectResult := self parseProjectResult: result.
1✔
1778

1✔
1779
        projectResult repository: GLHRepository new.
1✔
1780
        self glhModel add: projectResult repository.
1✔
1781
        self importRepository: projectResult repository.
1✔
1782

1✔
1783
        ^ projectResult
1✔
1784
]
1✔
1785

1✔
1786
{ #category : #'import - pipelines' }
1✔
1787
GitlabModelImporter >> pipelinesOf: aProjectID after: after andBefore: before [
1✔
1788

1✔
1789
        | result |
1✔
1790
        ('Search pipelines of: ' , aProjectID printString) recordInfo.
1✔
1791
        
1✔
1792
        result := self repoApi pipelines getAllInProject: aProjectID 
1✔
1793
                                                                                                withParams: {        #updated_before -> before.
1✔
1794
                                                                                                                                        #updated_after -> after} asDictionary .
1✔
1795
        result isString ifTrue: [ ^ self parsePipelinesResult: result ].
1✔
1796

1✔
1797
        ^ (result collect: [ :pipelinesJson |
1✔
1798
                           self parsePipelinesResult: pipelinesJson ]) flattened
1✔
1799
]
1✔
1800

1✔
1801
{ #category : #'import - pipelines' }
1✔
1802
GitlabModelImporter >> pipelinesOf: aProjectID withLimit: aLimit [
1✔
1803

1✔
1804
        | result |
1✔
1805
        ('Search pipelines of: ' , aProjectID printString) recordInfo.
1✔
1806
        result := self repoApi pipelines getByPage: 1 perPage: aLimit inProject: aProjectID.
1✔
1807
        result isString ifTrue: [ ^ self parsePipelinesResult: result ].
1✔
1808

1✔
1809
        ^ (result collect: [ :pipelinesJson |
1✔
1810
                           self parsePipelinesResult: pipelinesJson ]) flattened
1✔
1811
]
1✔
1812

1✔
1813
{ #category : #accessing }
1✔
1814
GitlabModelImporter >> repoApi: anObject [
1✔
1815
        super repoApi: anObject.
1✔
1816
        self repoApi output: 'json'
1✔
1817
]
1✔
1818

1✔
1819
{ #category : #private }
1✔
1820
GitlabModelImporter >> selectEntityType: aType overAttribut: aSelector equalTo: value [
1✔
1821

1✔
1822
        ^ (self glhModel allWithType: aType)
1✔
1823
                select: [ :entity | (entity perform: aSelector) = value ]
1✔
1824
]
1✔
1825

1✔
1826
{ #category : #'import - groups' }
1✔
1827
GitlabModelImporter >> subGroupsOf: aGroupID [
1✔
1828

1✔
1829
        | results subgroups |
1✔
1830
        ('Search subgroup of: ' , aGroupID printString) recordInfo.
1✔
1831
        results := self repoApi groups subgroupsOf: aGroupID.
1✔
1832
        subgroups := (results collect: [ :subgroupsJson | self parseSubGroupResult: subgroupsJson ]) flattened.
1✔
1833
        
1✔
1834
        ^ subgroups
1✔
1835
]
1✔
1836

1✔
1837
{ #category : #accessing }
1✔
1838
GitlabModelImporter >> withInitialCommits: boolean [
1✔
1839
        withInitialCommits := boolean 
1✔
1840
]
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