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

moosetechnology / GitProjectHealth / 14532584234

18 Apr 2025 08:52AM UTC coverage: 73.168% (-0.05%) from 73.222%
14532584234

Pull #172

github

web-flow
Merge 4ccb527e2 into 415b06620
Pull Request #172: Code OwnerShip "Git blame"

1008 of 1578 new or added lines in 19 files covered. (63.88%)

1 existing line in 1 file now uncovered.

15876 of 21698 relevant lines covered (73.17%)

0.73 hits per line

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

54.14
/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 : #private }
40
GitlabModelImporter >> chainsCommitsFrom: commitsCollection [
1✔
41

1✔
42
        | dic |
1✔
43
        
1✔
44
        ('Chains ', commitsCollection size printString , ' commits') recordInfo.
1✔
45
        
1✔
46
        dic := ((self glhModel allWithType: GLHCommit) collect: [ :commit |
1✔
47
                        commit id -> commit ]) asSet asDictionary.
1✔
48

1✔
49
        commitsCollection do: [ :commit |
1✔
50
                commit parent_ids do: [ :parentId | 
1✔
51
                        dic
1✔
52
                                at: parentId
1✔
53
                                ifPresent: [ :parentCommit |
1✔
54
                                        parentCommit childCommits
1✔
55
                                                add: commit
1✔
56
                                                unless: self blockOnIdEquality ]
1✔
57
                                ifAbsent: [  ] ] ].
1✔
58
        ^ commitsCollection
1✔
59
]
1✔
60

61
{ #category : #'import - commits' }
62
GitlabModelImporter >> commitsOfProject: aGLHProject forRefName: refName until: toDate [
×
63

×
64
        | params results allCommits |
×
65
        
×
66
        params := { 
×
67
                #ref_name -> refName.
×
68
                #until -> (toDate ifNotNil: [ toDate asDateAndTime asString ] ifNil: [ '' ]) 
×
69
        } asDictionary.
×
70
        results := self repoApi commits getAllInProject: aGLHProject id withParams: params.
×
71
        allCommits := (results collect: [ :commitsJson | self parseCommitsResult: commitsJson ]) flattened.
×
72
        
×
73
        self glhModel addAll: allCommits unless: self blockOnIdEquality.
×
74
        aGLHProject repository commits addAll: allCommits unless: self blockOnIdEquality.
×
75

×
76
        self withCommitDiffs ifTrue: [
×
77
                aGLHProject repository commits do: [ :commit |
×
78
                        self importDiffOfCommit: commit ] ].
×
79
        
×
80
        ^allCommits
×
81
]
×
82

83
{ #category : #'import - projects' }
84
GitlabModelImporter >> completeImportProject: aGLHProject [
1✔
85

1✔
86
        | importedProject |
1✔
87
        ('Complete import of project: ' , aGLHProject id printString)
1✔
88
                recordInfo.
1✔
89
        aGLHProject repository ifNotNil: [ ^ aGLHProject ].
1✔
90

1✔
91
        importedProject := self glhModel
1✔
92
                                   add: aGLHProject
1✔
93
                                   unless: self blockOnIdEquality.
1✔
94

1✔
95
        self importPipelinesOfProject: importedProject.
1✔
96

1✔
97
        "aGLHProject creator: (self importUser: aGLHProject creator_id)."
1✔
98

1✔
99
        (self importUser: importedProject creator_id) addCreatedProject:
1✔
100
                importedProject.
1✔
101

1✔
102

1✔
103
        importedProject repository: GLHRepository new.
1✔
104
        self glhModel add: importedProject repository.
1✔
105
        self importRepository: importedProject repository.
1✔
106

1✔
107

1✔
108
        withInitialMergeRequest ifTrue: [
1✔
109
                self
1✔
110
                        importMergeRequests: importedProject
1✔
111
                        since: DateAndTime today
1✔
112
                        until: DateAndTime now ].
1✔
113

1✔
114
        ^ importedProject
1✔
115
        
1✔
116

1✔
117
]
1✔
118

119
{ #category : #'import - commits' }
120
GitlabModelImporter >> completeImportedCommit: aCommit [
1✔
121

1✔
122
        ('completing commit: ' , aCommit short_id printString) recordInfo.
1✔
123
        self importCreatorOfCommit: aCommit.
1✔
124

1✔
125
        self withCommitDiffs ifTrue: [
1✔
126
                | diffs |
1✔
127
                aCommit diffs ifEmpty: [
1✔
128
                        diffs := self importDiffOfCommit: aCommit.
1✔
129
                        self glhModel addAll: diffs unless: self blockForDiffEquality ] ].
1✔
130

1✔
131
        ^ aCommit
1✔
132
]
1✔
133

134
{ #category : #'private - configure reader' }
135
GitlabModelImporter >> configureReaderForCommit: reader [
1✔
136

1✔
137
          reader for: GLHCommit do: [ :mapping |
1✔
138
                mapping mapInstVars:
1✔
139
                        #( id short_id title author_name author_email committer_name
1✔
140
                           committer_email message web_url ).
1✔
141
                (mapping mapInstVar: #authored_date) valueSchema: DateAndTime.
1✔
142
                (mapping mapInstVar: #committed_date) valueSchema: DateAndTime.
1✔
143
                (mapping mapInstVar: #created_at) valueSchema: DateAndTime.
1✔
144
                (mapping mapInstVar: #parent_ids) valueSchema: #ArrayOfIds.
1✔
145
                mapping
1✔
146
                        mapProperty: 'stats'
1✔
147
                        getter: [ :el | "Not used" ]
1✔
148
                        setter: [ :commit :value |
1✔
149
                                commit deletions: (value at: #deletions).
1✔
150
                                commit additions: (value at: #additions) ] ].
1✔
151

1✔
152
        reader for: DateAndTime customDo: [ :mapping |
1✔
153
                mapping decoder: [ :string | DateAndTime fromString: string ] ].
1✔
154

1✔
155
        reader
1✔
156
                for: #ArrayOfIds
1✔
157
                customDo: [ :mapping | mapping decoder: [ :string | string ] ].
1✔
158
  
1✔
159
        reader
1✔
160
                for: #ArrayOfCommit
1✔
161
                customDo: [ :customMappting |
1✔
162
                customMappting listOfElementSchema: GLHCommit ].
1✔
163

1✔
164
]
1✔
165

166
{ #category : #'private - configure reader' }
167
GitlabModelImporter >> configureReaderForDiffs: reader [
1✔
168

1✔
169
        reader for: GLHDiff do: [ :mapping |
1✔
170
                mapping mapInstVars:
1✔
171
                        #( deleted_file new_file new_path old_path renamed_file ).
1✔
172
                mapping mapInstVar: #diffString to: #diff ].
1✔
173

1✔
174
        reader
1✔
175
                for: #ArrayOfDiffs
1✔
176
                customDo: [ :customMappting |
1✔
177
                customMappting listOfElementSchema: GLHDiff ].
1✔
178
        ^ reader
1✔
179
]
1✔
180

181
{ #category : #'private - configure reader' }
182
GitlabModelImporter >> configureReaderForGroup: reader [
1✔
183

1✔
184
        reader for: GLHGroup do: [ :mapping |
1✔
185
                mapping mapInstVars.
1✔
186
                (mapping mapInstVar: #projects) valueSchema: #ArrayOfProjects ].
1✔
187
        reader mapInstVarsFor: GLHProject.
1✔
188
        reader
1✔
189
                for: #ArrayOfProjects
1✔
190
                customDo: [ :customMappting |
1✔
191
                customMappting listOfElementSchema: GLHProject ].
1✔
192
        reader
1✔
193
                for: #ArrayOfGroups
1✔
194
                customDo: [ :customMappting |
1✔
195
                customMappting listOfElementSchema: GLHGroup ]
1✔
196
]
1✔
197

198
{ #category : #'private - configure reader' }
199
GitlabModelImporter >> configureReaderForMergeRequest: reader [
1✔
200
        "declare quil y a un array a mapper"
1✔
201

1✔
202
        reader for: #ArrayOfMergeRequest customDo: [ :customMappting |
1✔
203
                customMappting listOfElementSchema: GLHMergeRequest ].
1✔
204

1✔
205
        "declare la liste des properties"
1✔
206
        reader for: GLHMergeRequest do: [ :mapping |
1✔
207
                mapping mapInstVars:
1✔
208
                        #( blocking_discussions_resolved changes_count description
1✔
209
                           detailed_merge_status discussion_locked downvotes draft first_deployed_to_production_at
1✔
210
                           force_remove_source_branch has_conflicts id iid labels latest_build_finished_at
1✔
211
                           latest_build_started_at merge_commit_sha merge_status
1✔
212
                           merge_when_pipeline_succeeds merged_at milestone project_id
1✔
213
                           reference references_full references_relative
1✔
214
                           references_short sha should_remove_source_branch
1✔
215
                           source_branch source_project_id squash squash_commit_sha
1✔
216
                           squash_on_merge state subscribed target_branch target_project_id
1✔
217
                           task_completion_status_completed_count
1✔
218
                           task_completion_status_count time_stats_human_time_estimate
1✔
219
                           time_stats_human_total_time_spent
1✔
220
                           time_stats_time_estimate time_stats_total_time_spent
1✔
221
                           title updated_at upvotes user_notes_count web_url work_in_progress ).
1✔
222
                (mapping mapInstVar: #created_at) valueSchema: DateAndTime.
1✔
223
                (mapping mapInstVar: #updated_at) valueSchema: DateAndTime.
1✔
224
                (mapping mapInstVar: #merged_at) valueSchema: DateAndTime.
1✔
225
                (mapping mapInstVar: #closed_at) valueSchema: DateAndTime.
1✔
226
                "(mapping mapInstVar: #assignee) valueSchema: GLHUser."
1✔
227
                mapping
1✔
228
                        mapProperty: #author
1✔
229
                        getter: [  ]
1✔
230
                        setter: [ :object :value |
1✔
231
                        object cacheAt: #authorID put: (value at: #id) ].
1✔
232
                mapping
1✔
233
                        mapProperty: #merge_user
1✔
234
                        getter: [  ]
1✔
235
                        setter: [ :object :value | 
1✔
236
                                value ifNotNil: [
1✔
237
                                        object cacheAt: #mergeUserID put: (value at: #id) ] ] ].
1✔
238

1✔
239
        "(mapping mapInstVar: #closed_by) valueSchema: GLHUser.
1✔
240
        (mapping mapInstVar: #mergeCommit) valueSchema: GLHCommit."
1✔
241
        "indique ce que doit faire le reader lorsqu'il parse une DateAndTime object"
1✔
242
        reader for: DateAndTime customDo: [ :mapping |
1✔
243
                mapping decoder: [ :string |
1✔
244
                        string ifNil: [ nil ] ifNotNil: [ DateAndTime fromString: string ] ] ]
1✔
245
]
1✔
246

247
{ #category : #private }
248
GitlabModelImporter >> convertApiFileAsFile: aAPIFile [
×
249

×
250
        aAPIFile type = 'tree' ifTrue: [ 
×
251
                ^ GLHFileDirectory new
×
252
                          name: aAPIFile name;
×
253
                          yourself ].
×
254
        ^ GLHFileBlob new
×
255
                  name: aAPIFile name;
×
256
                  yourself
×
257
]
×
258

259
{ #category : #private }
260
GitlabModelImporter >> detectEntityType: aType overAttribut: aSelector equalTo: value [
1✔
261

1✔
262
        ^ (self glhModel allWithType: aType) detect: [ :entity |
1✔
263
                  (entity perform: aSelector) = value ] ifNone: [ nil ]. 
1✔
264
]
1✔
265

266
{ #category : #accessing }
267
GitlabModelImporter >> glhApi [
×
268

×
269
        self
×
270
                deprecated: 'Use #repoApi instead'
×
271
                on: '7 October 2024'
×
272
                in:
×
273
                'Pharo-11.0.0+build.726.sha.aece1b5473acf3830a0e082c1bc3a15d4ff3522b (64 Bit)'.
×
274

×
275
        ^ repoApi
×
276
]
×
277

278
{ #category : #accessing }
279
GitlabModelImporter >> glhApi: anObject [
×
280

×
281
        self
×
282
                deprecated: 'Use #repoApi: instead'
×
283
                on: '7 October 2024'
×
284
                in:
×
285
                'Pharo-11.0.0+build.726.sha.aece1b5473acf3830a0e082c1bc3a15d4ff3522b (64 Bit)'.
×
286

×
287
        repoApi := anObject
×
288
]
×
289

290
{ #category : #accessing }
291
GitlabModelImporter >> glhModel [
1✔
292

1✔
293
        ^ glhModel
1✔
294
]
1✔
295

296
{ #category : #accessing }
297
GitlabModelImporter >> glhModel: anObject [
1✔
298

1✔
299
        glhModel := anObject
1✔
300
]
1✔
301

302
{ #category : #'import - users' }
303
GitlabModelImporter >> importActiveHumanUsers [
×
304

×
305
        | params result users |
×
306
        params := { 
×
307
                #humans -> 'true'.
×
308
                #active -> 'true'.
×
309
                #without_project_bots -> 'true'
×
310
        } asDictionary.
×
311
        result := self repoApi users allWithParams: params.
×
312
        users := (result collect: [ :usersJson | self parseUsersResult: usersJson ]) flattened.
×
313
        
×
314
        self glhModel
×
315
                                 addAll: users
×
316
                                 unless: self blockOnIdEquality.
×
317

×
318
        ^ users
×
319
]
×
320

321
{ #category : #'import - groups' }
322
GitlabModelImporter >> importAllGroups [
×
323

×
324
        | params results groups |
×
325
        
×
326
        params := { 
×
327
                        #top_level_only -> 'true'
×
328
        } asDictionary.
×
329
        results := self repoApi groups getAllWithParams: params.
×
330
        
×
331
        groups := (results collect: [ :groupsJson | generalReader
×
332
                                            on: groupsJson readStream;
×
333
                                            nextAs: #ArrayOfGroups. ]) flattened.
×
334
        ^ groups
×
335
]
×
336

337
{ #category : #'import - commits' }
338
GitlabModelImporter >> importAndLoadLatestsCommitsOfProject: aGLHProject [
×
339

×
340
        | commits completedProject |
×
341
        completedProject := self completeImportProject: aGLHProject.
×
342
        commits := self importLastestCommitsOfProject: completedProject.
×
343
        commits do: [ :commit | self completeImportedCommit: commit ].
×
344
        self chainsCommitsFrom: commits.
×
345
        ^ commits
×
346
]
×
347

348
{ #category : #'import - repositories' }
NEW
349
GitlabModelImporter >> importBranches: aGLHProject [ 
×
NEW
350
        "Fetches all branches of the given project"
×
NEW
351
        | results parsedResults |
×
NEW
352

×
NEW
353
        "Fetch branches from the repository API"
×
NEW
354
        results := self repoApi branches getAllFromProject: aGLHProject id.
×
NEW
355

×
NEW
356
        "Parse the retrieved branches"
×
NEW
357
        parsedResults := (results collect: [ :branchJson | self parseBranchesResult: branchJson ]) flattened.
×
NEW
358

×
NEW
359
        "Add branches to the model (if not blocked by name equality)"
×
NEW
360
        self glhModel addAll: parsedResults unless: self blockOnNameEquality.
×
NEW
361

×
NEW
362
        "Return the list of parsed branches"
×
NEW
363
        ^ parsedResults.
×
NEW
364

×
NEW
365
]
×
366

367
{ #category : #'import - commits' }
368
GitlabModelImporter >> importCommit: aCommitID ofProject: aGLHProject [
×
369

×
370
        | result parsedResult |
×
371
        (self glhModel allWithType: GLHCommit) asOrderedCollection
×
372
                detect: [ :commit | commit id = aCommitID ]
×
373
                ifFound: [ :commit | ^ commit ].
×
374
        result := self repoApi commits get: aCommitID inProject: aGLHProject id.
×
375
        
×
376
        parsedResult := self parseCommitResult: result.
×
377
        
×
378
        self
×
379
                addCommits: { parsedResult }
×
380
                toRepository: aGLHProject repository.
×
381
        ^ parsedResult
×
382
]
×
383

384
{ #category : #'import - commits' }
385
GitlabModelImporter >> importCommitOfProject: anProject withId: anID [
1✔
386

1✔
387
        | commit result |
1✔
388
        anID ifNil: [ ^ nil ].
1✔
389

1✔
390
        ('looking for commit ' , anID printString , ' in project : '
1✔
391
         , anProject id printString) recordInfo.
1✔
392

1✔
393
        commit := (self
1✔
394
                           detectEntityType: GLHCommit
1✔
395
                           overAttribut: #id
1✔
396
                           equalTo: anID) ifNil: [
1✔
397
                          result := self repoApi commits get: anID inProject: anProject id.
1✔
398
                          commit := (self parseCommitsResult: '[' , result , ']')
1✔
399
                                            first.
1✔
400

1✔
401
                          self glhModel add: commit unless: self blockOnIdEquality.
1✔
402
                          commit repository: anProject repository.
1✔
403

1✔
404
                          commit ].
1✔
405

1✔
406
        self withCommitDiffs ifTrue: [ self importDiffOfCommit: commit ].
1✔
407

1✔
408
        ^ commit
1✔
409
]
1✔
410

411
{ #category : #'import - commits' }
412
GitlabModelImporter >> importCommits: aGLHProject [
×
413
        "limited to the last 20 commits"
×
414

×
415
        | results parsedResults params |
×
416
        params := { 
×
417
         #with_stats -> 'true'
×
418
        } asDictionary.
×
419
        results := self repoApi commits getByPage: 1 perPage: 20 inProject: aGLHProject id withParams: params.
×
420
        
×
421
        parsedResults := self parseCommitsResult: results.
×
422
        self glhModel addAll: parsedResults unless: self blockOnIdEquality.
×
423

×
424
        parsedResults do: [ :commit |
×
425
                commit repository: aGLHProject repository ].
×
426

×
427
        self withCommitDiffs ifTrue: [
×
428
                parsedResults do: [ :commit | self importDiffOfCommit: commit ] ].
×
429
        
×
430
        ^ parsedResults. 
×
431
]
×
432

433
{ #category : #'import - commits' }
434
GitlabModelImporter >> importCommitsFollowing: aCommit upToDays: aNumberOfDay [
×
435
        "import the 'n' commits of a project starting from an initial 'aCommit' commit. 
×
436
        Lazy import does not import the entities inside the model"
×
437

×
438
        | date |
×
439
        date := aCommit created_at asDateAndTime.
×
440

×
441
        ^ self
×
442
                  importCommitsOfBranch: aCommit branch
×
443
                  forRefName: aCommit branch name
×
444
                  since: date
×
445
                  until: (date + aNumberOfDay day)
×
446
]
×
447

448
{ #category : #commit }
449
GitlabModelImporter >> importCommitsOf: aGLHProject withStats: aBoolean until: toDate [
×
450

×
451
        | newlyFoundCommit page |
×
452
        
×
453
        self deprecated: [  ] .
×
454
        
×
455
        page := 0.
×
456
        newlyFoundCommit := { true }.
×
457
        [ newlyFoundCommit isNotEmpty ] whileTrue: [
×
458
                | results parsedResults existingCommits |
×
459
                page := page + 1.
×
460
                ('import commit page ' , page printString) recordInfo.
×
461
                results := self repoApi
×
462
                                   commitsOfProject: aGLHProject id
×
463
                                   forRefName: nil
×
464
                                   since: nil
×
465
                                   until: nil
×
466
                                   path: nil
×
467
                                   author: nil
×
468
                                   all: nil
×
469
                                   with_stats: aBoolean
×
470
                                   firstParent: nil
×
471
                                   order: nil
×
472
                                   trailers: nil
×
473
                                   perPage: 100
×
474
                                   page: page.
×
475
                parsedResults := self parseCommitsResult: results.
×
476
                existingCommits := aGLHProject mooseModel allWithType: GLHCommit.
×
477

×
478
                newlyFoundCommit := parsedResults reject: [ :commitParsed |
×
479
                                            (toDate isNil or: [
×
480
                                                     commitParsed committed_date
×
481
                                                     < toDate asDateAndTime ]) or: [
×
482
                                                    existingCommits anySatisfy: [ :existingCommit |
×
483
                                                            existingCommit id = commitParsed id ] ] ].
×
484
                aGLHProject mooseModel addAll: newlyFoundCommit.
×
485
                aGLHProject repository commits addAll: newlyFoundCommit ].
×
486

×
487

×
488
        self withCommitDiffs ifTrue: [
×
489
                aGLHProject repository commits do: [ :commit |
×
490
                        self importDiffOfCommit: commit ] ]
×
491
]
×
492

493
{ #category : #'import - commits' }
494
GitlabModelImporter >> importCommitsOfBranch: aGLHBranch [
×
495

×
496
        | commits |
×
497
        "        result := self glhApi
×
498
                          commitsOfProject: aGLHBranch repository project id
×
499
                          forRefName: aGLHBranch name."
×
500
        commits := self
×
501
                           importCommitsOfBranch: aGLHBranch
×
502
                           forRefName: aGLHBranch name
×
503
                           since: withCommitsSince.
×
504

×
505
        self chainsCommitsFrom: commits.
×
506

×
507
        commits do: [ :aCommit |
×
508
                aCommit repository: aGLHBranch repository.
×
509
                self completeImportedCommit: aCommit. 
×
510
                 ]
×
511
]
×
512

513
{ #category : #'import - commits' }
514
GitlabModelImporter >> importCommitsOfBranch: aGLHBranch forRefName: refName since: fromDate [
×
515

×
516
        ^ self
×
517
                  importCommitsOfBranch: aGLHBranch
×
518
                  forRefName: aGLHBranch name
×
519
                  since: fromDate
×
520
                  until: nil
×
521
]
×
522

523
{ #category : #'import - commits' }
524
GitlabModelImporter >> importCommitsOfBranch: aGLHBranch forRefName: refName since: fromDate until: toDate [
×
525

×
526
        | params result allCommits |
×
527
        params := { 
×
528
          #ref_name -> aGLHBranch name.
×
529
          #since ->  (fromDate ifNotNil: [ fromDate asDate asDateAndTime asString ] ifNil: [ '' ]).
×
530
          #until -> (toDate ifNotNil: [ toDate asDate asDateAndTime asString ] ifNil: [ '' ]). 
×
531

×
532
        } asDictionary.
×
533
        result := self repoApi commits getAllInProject: aGLHBranch repository project id withParams: params.
×
534
        
×
535
        allCommits := (result collect: [ :commitsJson | self parseCommitsResult: commitsJson ]) flattened.
×
536
        
×
537
        aGLHBranch commits
×
538
                        addAll: allCommits
×
539
                        unless: self blockOnIdEquality.
×
540

×
541
        self glhModel
×
542
                addAll: aGLHBranch commits
×
543
                unless: self blockOnIdEquality.
×
544

×
545
        ^ allCommits
×
546
]
×
547

548
{ #category : #'import - commits' }
549
GitlabModelImporter >> importCommitsOfBranch: aGLHBranch forRefName: refName until: toDate [
×
550

×
551
        ^ self
×
552
                  importCommitsOfBranch: aGLHBranch
×
553
                  forRefName: aGLHBranch name
×
554
                  since: nil
×
555
                  until: toDate
×
556
]
×
557

558
{ #category : #'import - commits' }
559
GitlabModelImporter >> importCommitsOfProject: aProject since: fromDate until: toDate [
1✔
560

1✔
561
        | params results allCommits |
1✔
562
        params := {
1✔
563
                          (#since
1✔
564
                           ->
1✔
565
                           (fromDate
1✔
566
                                    ifNotNil: [ fromDate asDate asDateAndTime asString ]
1✔
567
                                    ifNil: [ '' ])).
1✔
568
                          (#until
1✔
569
                           ->
1✔
570
                           (toDate
1✔
571
                                    ifNotNil: [ toDate asDate asDateAndTime asString ]
1✔
572
                                    ifNil: [ '' ])).
1✔
573
                          (#with_stats -> 'true').
1✔
574
                          (#all -> 'true') } asDictionary.
1✔
575
        results := self repoApi commits
1✔
576
                           getAllInProject: aProject id
1✔
577
                           withParams: params.
1✔
578

1✔
579
        allCommits := (results collect: [ :commitsJson |
1✔
580
                               self parseCommitsResult: commitsJson ]) flattened.
1✔
581

1✔
582
        allCommits:= aProject repository commits
1✔
583
                addAll: allCommits
1✔
584
                unless: self blockOnIdEquality.
1✔
585

1✔
586
        ^ self glhModel addAll: allCommits unless: self blockOnIdEquality
1✔
587
]
1✔
588

589
{ #category : #'import - projects' }
590
GitlabModelImporter >> importContributedProjectsOfUser: aGLHUser [
×
591

×
592
        | remaningProjects params results projects projectsIds |
×
593
        params := {
×
594
                          (#order_by -> 'last_activity_at').
×
595
                          (#simple -> 'true') } asDictionary.
×
596
        results := self repoApi projects
×
597
                           contributedProjectsOfUser: aGLHUser id
×
598
                           withParams: params.
×
599

×
600
        projectsIds := (results collect: [ :projectsJson |
×
601
                             (NeoJSONReader fromString: projectsJson) collect: [:projectJson | projectJson at: #id ] ]) flattened.
×
602
        
×
603
        projects := self importProjects: projectsIds.
×
604
        remaningProjects := self importProjects:
×
605
                                    ((projects collect: #id) difference:
×
606
                                             ((self userCatalogue atId: aGLHUser id) at:
×
607
                                                      #contributedProjects)).
×
608

×
609

×
610
        aGLHUser contributedProjects
×
611
                addAll: projects , remaningProjects
×
612
                unless: self blockOnIdEquality.
×
613

×
614
        self userCatalogue
×
615
                addUser: aGLHUser
×
616
                withProjects: (aGLHUser contributedProjects collect: #id).
×
617

×
618
        ^ projects
×
619
]
×
620

621
{ #category : #'import - commits' }
622
GitlabModelImporter >> importCreatorOfCommit: aCommit [
1✔
623

1✔
624
        aCommit commitCreator ifNil: [
1✔
625
                aCommit commitCreator:
1✔
626
                        (self importUserByUsername: aCommit author_name) ].
1✔
627
        self userCatalogue
1✔
628
                addUser: aCommit commitCreator
1✔
629
                withProject: aCommit repository project id.
1✔
630
        ^ aCommit commitCreator
1✔
631
]
1✔
632

633
{ #category : #'import - commits' }
634
GitlabModelImporter >> importDiffOfCommit: aCommit [
1✔
635

1✔
636
        | result diffsResult |
1✔
637
        aCommit diffs ifNotEmpty: [
1✔
638
                'Diff already importer: ' , aCommit short_id printString recordInfo.
1✔
639
                ^ aCommit diffs ].
1✔
640
        ('Import diff of commit: ' , aCommit short_id printString) recordInfo.
1✔
641

1✔
642
        result := self repoApi commits
1✔
643
                          diffOf: aCommit id
1✔
644
                          inProject: aCommit repository project id
1✔
645
                          uniDiff: true.
1✔
646

1✔
647
        (self isServerError: result) ifTrue: [ ^ {  } ].
1✔
648
        diffsResult := self newParseDiffResult: result.
1✔
649

1✔
650
        aCommit diffs addAll: diffsResult unless: self blockForDiffEquality.
1✔
651
        
1✔
652
        "changes are added into the model during the import"
1✔
653
        aCommit diffs do: [ :diff | self importDiffRangesForDiff: diff ].
1✔
654

1✔
655
        ^ aCommit diffs
1✔
656
]
1✔
657

658
{ #category : #'import - merge request' }
659
GitlabModelImporter >> importDiffOfMergeRequest: aMergeRequest [
1✔
660

1✔
661
        | result diffsResult |
1✔
662
        aMergeRequest diffs ifNotEmpty: [
1✔
663
                'Diff of already importer: '
1✔
664
                , aMergeRequest iid printString recordInfo.
1✔
665
                ^ aMergeRequest diffs ].
1✔
666
        ('Import diff commits of MR ' , aMergeRequest iid printString)
1✔
667
                recordInfo.
1✔
668
        result := self repoApi mergeRequests diffsOf: aMergeRequest iid inProject: aMergeRequest project_id.
1✔
669

1✔
670
        diffsResult := self newParseDiffResult: result.
1✔
671

1✔
672

1✔
673
        aMergeRequest diffs
1✔
674
                addAll: diffsResult
1✔
675
                unless: self blockForDiffEquality.
1✔
676
        self glhModel
1✔
677
                addAll: aMergeRequest diffs
1✔
678
                unless: self blockForDiffEquality.
1✔
679

1✔
680
        aMergeRequest diffs do: [ :diff | self importDiffRangesForDiff: diff ].
1✔
681

1✔
682
        ^ aMergeRequest diffs
1✔
683
]
1✔
684

685
{ #category : #'import - repositories' }
686
GitlabModelImporter >> importDirectoryFiles: aDirectoryFile OfBranch: aBranch [
×
687

×
688
        | result files apiFiles params |
×
689
        params := { 
×
690
                #ref -> aBranch name.
×
691
                #path -> (aDirectoryFile path , '/')
×
692
        } asDictionary.
×
693
        result := self repoApi repositories repositoryTreeOfProject: aBranch repository project id withParams: params.
×
694
                         " treeOfRepository: aBranch repository project id
×
695
                          ofBranch: aBranch name
×
696
                          andPath: aDirectoryFile path , '/'."
×
697
        apiFiles := (result collect: [ :treeJson | self parseFileTreeResult: treeJson ]) flattened.
×
698
        files := apiFiles collect: [ :apiFile |
×
699
                         self convertApiFileAsFile: apiFile ].
×
700
        
×
701
        files do: [ :file |
×
702
                self glhModel add: file.
×
703
                aDirectoryFile addFile: file ].
×
704
        
×
705
        files
×
706
                select: [ :file | file isKindOf: GLHFileDirectory ]
×
707
                thenCollect: [ :file |
×
708
                self importDirectoryFiles: file OfBranch: aBranch ]
×
709
]
×
710

711
{ #category : #'import - repositories' }
712
GitlabModelImporter >> importFilesOfBranch: aBranch [
×
713

×
714
        | result files apiFiles params |
×
715
        params := { 
×
716
                #ref -> aBranch name.
×
717
        } asDictionary.
×
718
        
×
719
        result := self repoApi repositories repositoryTreeOfProject: aBranch repository project id withParams: params.
×
720
        
×
721
                          "treeOfRepository: aBranch repository project id
×
722
                          ofBranch: aBranch name
×
723
                          andPath: nil."
×
724
        apiFiles := (result collect: [ :filesJson | self parseFileTreeResult: filesJson  ]) flattened.
×
NEW
725
        files := apiFiles collect: [ :apiFile |  self convertApiFileAsFile: apiFile ].
×
NEW
726
   files := self glhModel addAll: files unless: [:f1 :f2 | f1 branch = f2 branch and: [f1 path = f2 path]].
×
NEW
727
   files := aBranch addAll: files unless: [:f1 :f2 | f1 branch = f2 branch and: [f1 path = f2 path]].
×
728
        files
×
729
                select: [ :file | file isKindOf: GLHFileDirectory ]
×
730
                thenCollect: [ :file | 
×
NEW
731
                self importDirectoryFiles: file OfBranch: aBranch ] .
×
NEW
732
        ^ files 
×
UNCOV
733
]
×
734

735
{ #category : #'import - groups' }
736
GitlabModelImporter >> importGroup: aGroupID [
1✔
737

1✔
738
        | result groupResult |
1✔
739
        ('Import group: ' , aGroupID printString) recordInfo.
1✔
740

1✔
741
        result := self repoApi groups get: aGroupID.
1✔
742
        
1✔
743
        "group: aGroupID."
1✔
744
        groupResult := self parseGroupResult: result.
1✔
745
        groupResult := self addGroupResultToModel: groupResult.
1✔
746

1✔
747
        groupResult projects do: [ :project |
1✔
748
                self completeImportProject: project ].
1✔
749

1✔
750
        (self subGroupsOf: aGroupID) do: [ :subGroup |
1✔
751
                
1✔
752
                groupResult subGroups
1✔
753
                        add: (self importGroup: subGroup id)
1✔
754
                        unless: self blockOnIdEquality ].
1✔
755
        ^ groupResult
1✔
756
]
1✔
757

758
{ #category : #'import - jobs' }
759
GitlabModelImporter >> importJobsOf: aPipeline [
×
760

×
761
        | jobs results |
×
762
        results := self repoApi jobs allForPipeline: aPipeline id inProject: aPipeline project id.
×
763
                          "jobsOfProject: aPipeline project id
×
764
                          ofPipelines: aPipeline id."
×
765
        jobs := (results collect: [ :jobsJson | self parseJobsResult: jobsJson ofProject: aPipeline project ]) flattened.
×
766
        jobs do: [ :job | aPipeline addJob: job ].
×
767
        self glhModel addAll: jobs.
×
768
        
×
769
        ^jobs
×
770

×
771
]
×
772

773
{ #category : #'import - commits' }
774
GitlabModelImporter >> importLastestCommitsOfProject: aGLHProject [
1✔
775
        "limited to the last 50 commits"
1✔
776

1✔
777
        | results parsedResults params |
1✔
778
        params := { 
1✔
779
                #with_stats -> 'true'.
1✔
780
                #all -> true
1✔
781
         } asDictionary.
1✔
782
        results := self repoApi commits getByPage: 1 perPage: 50 inProject: aGLHProject id withParams: params.
1✔
783

1✔
784
        parsedResults := self parseCommitsResult: results.
1✔
785
        parsedResults := self glhModel
1✔
786
                                 addAll: parsedResults
1✔
787
                                 unless: self blockOnIdEquality.
1✔
788

1✔
789
        aGLHProject repository commits
1✔
790
                addAll: parsedResults
1✔
791
                unless: self blockOnIdEquality.
1✔
792

1✔
793
        self withCommitDiffs ifTrue: [
1✔
794
                parsedResults do: [ :commit | self importDiffOfCommit: commit ] ].
1✔
795

1✔
796
        ^ parsedResults
1✔
797
]
1✔
798

799
{ #category : #'import - merge request' }
800
GitlabModelImporter >> importMergeRequestCommits: aGLPHEMergeRequest [
×
801

×
802
        | commits result |
×
803
        aGLPHEMergeRequest commits ifNotNil: [ ^ aGLPHEMergeRequest commits ].
×
804
        
×
805
        result := self repoApi mergeRequests commitsOf: aGLPHEMergeRequest iid inProject: aGLPHEMergeRequest project id.
×
806
        
×
807
        commits := (result collect: [ :commitsJson | self parseCommitsResult: commitsJson ]) flattened.
×
808
        commits := commits collect: [ :commit | self importCommit: commit id ofProject: aGLPHEMergeRequest project ].
×
809
        aGLPHEMergeRequest commits: commits.
×
810

×
811

×
812
        ^ commits
×
813
]
×
814

815
{ #category : #'import - merge request' }
816
GitlabModelImporter >> importMergeRequestMergeCommits: aGLPHEMergeRequest [
1✔
817

1✔
818
        | foundCommits |
1✔
819
        foundCommits := OrderedCollection new.
1✔
820

1✔
821
        ('Import commit sha of MR:  ' , aGLPHEMergeRequest iid printString)
1✔
822
                recordInfo.
1✔
823
        "the founds commits are added to the model during their respective import"
1✔
824
        aGLPHEMergeRequest mergeRequestCommit: ((self
1✔
825
                          importCommitOfProject: aGLPHEMergeRequest project
1✔
826
                          withId: aGLPHEMergeRequest sha) ifNotNil: [ :commit |
1✔
827
                         foundCommits add: commit ]).
1✔
828

1✔
829
        ('Import commit merge_commit_sha of MR:  '
1✔
830
         , aGLPHEMergeRequest iid printString) recordInfo.
1✔
831
        aGLPHEMergeRequest mergedCommit: ((self
1✔
832
                          importCommitOfProject: aGLPHEMergeRequest project
1✔
833
                          withId: aGLPHEMergeRequest merge_commit_sha) ifNotNil: [ :commit |
1✔
834
                         foundCommits add: commit ]).
1✔
835

1✔
836
        ('Import commit squash_commit_sha of MR:  '
1✔
837
         , aGLPHEMergeRequest iid printString) recordInfo.
1✔
838
        aGLPHEMergeRequest squashCommit: ((self
1✔
839
                          importCommitOfProject: aGLPHEMergeRequest project
1✔
840
                          withId: aGLPHEMergeRequest squash_commit_sha) ifNotNil: [ :commit |
1✔
841
                         foundCommits add: commit ]).
1✔
842

1✔
843

1✔
844
        self chainsCommitsFrom: foundCommits.
1✔
845
        ^ foundCommits
1✔
846
]
1✔
847

848
{ #category : #'import - merge request' }
849
GitlabModelImporter >> importMergeRequests: aGLHProject [
1✔
850

1✔
851
        | results parsedResults mrs |
1✔
852
        ('Import merge request of Project: ' , aGLHProject id printString)
1✔
853
                recordInfo.
1✔
854

1✔
855
        results := self repoApi mergeRequests allOfProject: aGLHProject id.
1✔
856
        parsedResults := (results collect: [ :projectsJson | self parseMergeRequestResult: projectsJson ]) flattened. 
1✔
857

1✔
858
        aGLHProject mergeRequests
1✔
859
                addAll: parsedResults
1✔
860
                unless: self blockOnIdEquality.
1✔
861

1✔
862
        mrs := self glhModel
1✔
863
                       addAll: aGLHProject mergeRequests
1✔
864
                       unless: self blockOnIdEquality.
1✔
865

1✔
866

1✔
867
        "gets it related commits"
1✔
868
        aGLHProject mergeRequests do: [ :mr |
1✔
869
                self importMergeRequestMergeCommits: mr ].
1✔
870

1✔
871

1✔
872
        self withCommitDiffs ifTrue: [
1✔
873
                aGLHProject mergeRequests do: [ :mr |
1✔
874
                        self importDiffOfMergeRequest: mr ] ].
1✔
875

1✔
876
        ^ mrs
1✔
877
]
1✔
878

879
{ #category : #'import - merge request' }
880
GitlabModelImporter >> importMergeRequests: aGLHProject since: fromDate until: toDate [
×
881

×
882
        | params result mergeRequests |
×
883
        ('import MR of Project ' , aGLHProject name) recordInfo.
×
884
        params := {
×
885
                          (#created_after
×
886
                           ->
×
887
                           (fromDate
×
888
                                    ifNotNil: [ fromDate asDateAndTime asString ]
×
889
                                    ifNil: [ '' ])).
×
890
                          (#created_before
×
891
                           ->
×
892
                           (toDate
×
893
                                    ifNotNil: [ toDate asDateAndTime asString ]
×
894
                                    ifNil: [ '' ])).
×
895
                          (#scope -> 'all') } asDictionary.
×
896

×
897
        result := self repoApi mergeRequests
×
898
                          allOfProject: aGLHProject id
×
899
                          withParams: params.
×
900
        mergeRequests := (result collect: [ :mergeRequestsJson |
×
901
                                  self parseMergeRequestResult: mergeRequestsJson ])
×
902
                                 flattened.
×
903

×
904
        aGLHProject mergeRequests
×
905
                addAll: mergeRequests
×
906
                unless: self blockOnIdEquality.
×
907

×
908
        "gets it related commits"
×
909
        aGLHProject mergeRequests do: [ :mr |
×
910
                self importMergeRequestMergeCommits: mr ].
×
911

×
912
        self withCommitDiffs ifTrue: [
×
913
                aGLHProject mergeRequests do: [ :mr |
×
914
                        self importDiffOfMergeRequest: mr ] ].
×
915

×
916
        self glhModel
×
917
                addAll: mergeRequests
×
918
                unless: (self blockEqualityOn: #iid).
×
919

×
920
        ^ mergeRequests
×
921
]
×
922

923
{ #category : #'import - merge request' }
924
GitlabModelImporter >> importMergeResquestApprovals: aGLPHEMergeRequest [
×
925

×
926
        | results parsedResult |
×
927
        (String streamContents: [ :str |
×
928
                 str << 'Check approvals of '.
×
929
                 aGLPHEMergeRequest printOn: str ]) recordInfo.
×
930
        results := self repoApi mergeRequests approvalsOf: aGLPHEMergeRequest iid inProject: aGLPHEMergeRequest project id.
×
931

×
932
        parsedResult := generalReader
×
933
                                on: results readStream;
×
934
                                next.
×
935

×
936
        (parsedResult at: #approved_by) do: [ :approvedUser |
×
937
                aGLPHEMergeRequest addApproved_by:
×
938
                        (self importUser: ((approvedUser at: #user) at: #id)) ].
×
939
        aGLPHEMergeRequest approved: (parsedResult at: #approved).
×
940
        ^ aGLPHEMergeRequest
×
941
]
×
942

943
{ #category : #'import - merge request' }
944
GitlabModelImporter >> importMergeResquestAuthor: aGLPHEMergeRequest [
1✔
945

1✔
946
        | authorID |
1✔
947
        aGLPHEMergeRequest author ifNotNil: [ ^ aGLPHEMergeRequest author ].
1✔
948
        authorID := aGLPHEMergeRequest cacheAt: #authorID ifAbsent: [
1✔
949
                            | result |
1✔
950
                            result := self repoApi mergeRequests
1✔
951
                                              get: aGLPHEMergeRequest iid
1✔
952
                                              inProject: aGLPHEMergeRequest project_id.
1✔
953

1✔
954
                            (generalReader
1✔
955
                                     on: result readStream;
1✔
956
                                     next) at: #author at: #id ].
1✔
957
        ^aGLPHEMergeRequest author: (self importUser: authorID)
1✔
958
]
1✔
959

960
{ #category : #'import - merge request' }
961
GitlabModelImporter >> importMergeResquestMerger: aGLPHEMergeRequest [
1✔
962

1✔
963
        | authorID |
1✔
964
        aGLPHEMergeRequest merge_user ifNotNil: [
1✔
965
                ^ aGLPHEMergeRequest merge_user ].
1✔
966
        authorID := aGLPHEMergeRequest cacheAt: #mergeUserID ifAbsent: [
1✔
967
                            | result |
1✔
968
                            result := self repoApi mergeRequests
1✔
969
                                              get: aGLPHEMergeRequest iid
1✔
970
                                              inProject: aGLPHEMergeRequest project_id.
1✔
971
                            (generalReader
1✔
972
                                     on: result readStream;
1✔
973
                                     next)
1✔
974
                                    at: #merge_user
1✔
975
                                    ifPresent: [ :mergeUser |
1✔
976
                                    mergeUser ifNotNil: [ :mruser | mruser at: #id ] ] ].
1✔
977
        ^aGLPHEMergeRequest merge_user: (self importUser: authorID)
1✔
978
]
1✔
979

980
{ #category : #'import - notes' }
981
GitlabModelImporter >> importNotesfromMergeRequest: mergeRequest [
×
982
        | results notes |
×
983
        
×
984
        results := self repoApi notes allInMergeRequest: mergeRequest iid ofProject: mergeRequest project id.
×
985
        
×
986
        notes := results collect: [ :note | 
×
987
                self parseNoteJson: note ].
×
988
        "notes := self parseNoteJson: results."
×
989
        notes do: [ :tabNotes | tabNotes do: [ :note |
×
990
                        note author: (self importUser: (note author at: #id)).
×
991
                        note name: note id asString]. ].
×
992
        notes := notes flattened.
×
993
        notes := self glhModel addAll: notes unless: self blockOnIdEquality. 
×
994
        notes := mergeRequest note addAll: notes unless: self blockOnIdEquality. 
×
995
        ^notes
×
996
        
×
997
]
×
998

999
{ #category : #'import - commits' }
1000
GitlabModelImporter >> importParentCommitsOfCommit: aGLHCommit since: aDate [
×
1001

×
1002
        | parentsIds commits |
×
1003
        commits := OrderedCollection new.
×
1004
        aGLHCommit created_at asDateAndTime < aDate asDateAndTime ifTrue: [
×
1005
                 
×
1006
                ^ commits
×
1007
                          add: aGLHCommit;
×
1008
                          yourself ].
×
1009

×
1010
        parentsIds := aGLHCommit parent_ids.
×
1011

×
1012
        commits addAll: (parentsIds collect: [ :id |
×
1013
                         self
×
1014
                                 importCommitOfProject: aGLHCommit repository project
×
1015
                                 withId: id ]).
×
1016

×
1017

×
1018
        ^ (commits collect: [ :parentCommit |
×
1019
                   self importParentCommitsOfCommit: parentCommit since: aDate ])
×
1020
                  flatten
×
1021
]
×
1022

1023
{ #category : #'imports - pipelines' }
1024
GitlabModelImporter >> importPipelinesOfProject: aGLHProject [
1✔
1025

1✔
1026
        (self pipelinesOf: aGLHProject id) do: [ :pipeline |
1✔
1027
                self glhModel add: pipeline unless: self blockOnIdEquality .
1✔
1028
                aGLHProject pipelines add: pipeline unless: self blockOnIdEquality]
1✔
1029
]
1✔
1030

1031
{ #category : #'import - projects' }
1032
GitlabModelImporter >> importProject: aProjectID [
1✔
1033

1✔
1034
        | result projectResult |
1✔
1035
        ('Import project with id:  ' , aProjectID printString) recordInfo.
1✔
1036

1✔
1037
        (glhModel allWithType: GLHProject)
1✔
1038
                detect: [ :project | project id = aProjectID ]
1✔
1039
                ifFound: [ :project | ^ project ].
1✔
1040

1✔
1041
        result := self repoApi projects get: aProjectID.
1✔
1042
        projectResult := self parseProjectResult: result.
1✔
1043

1✔
1044
        ^ self completeImportProject: projectResult
1✔
1045
]
1✔
1046

1047
{ #category : #'import - projects' }
1048
GitlabModelImporter >> importProjects [
×
1049

×
1050
        | result projects |
×
1051
        ('import all Projects') recordInfo.
×
1052

×
1053

×
1054
        result := self repoApi projects all.
×
1055
        projects := (result collect: [ :projectsJson | self parseArrayOfProject: projectsJson ]) flattened.
×
1056
        
×
1057
        self glhModel addAll: projects unless: self blockOnIdEquality.
×
1058

×
1059
        ^ projects
×
1060
]
×
1061

1062
{ #category : #imports }
1063
GitlabModelImporter >> importProjectsSince: since [
×
1064
        "heavy import of all projects"
×
1065

×
1066
        "copy import from commits"
×
1067

×
1068
        | newlyFoundProjects page foundProject amount |
×
1069
        ('import all Projects since: ' , since printString) recordInfo.
×
1070

×
1071
        "number of projects per page"
×
1072
        amount := 100.
×
1073
        page := 0.
×
1074
        foundProject := OrderedCollection new.
×
1075
        newlyFoundProjects := { true }.
×
1076
        [ newlyFoundProjects isNotEmpty ] whileTrue: [
×
1077
                | results |
×
1078
                page := page + 1.
×
1079
                ('import projects page #' , page printString) recordInfo.
×
1080

×
1081
                results := self repoApi projects: amount since: since page: page.
×
1082

×
1083
                newlyFoundProjects := self glhModel
×
1084
                                              addAll: (self parseArrayOfProject: results)
×
1085
                                              unless: self blockOnIdEquality.
×
1086
                foundProject addAll: newlyFoundProjects ].
×
1087
]
×
1088

1089
{ #category : #'import - repositories' }
1090
GitlabModelImporter >> importRepository: aGLHRepository [
1✔
1091

1✔
1092
        | resultBranches branches |
1✔
1093
        [
1✔
1094
        ('import the repository of project ' , aGLHRepository project name)
1✔
1095
                recordInfo.
1✔
1096

1✔
1097
        resultBranches := self repoApi branches getAllFromProject:
1✔
1098
                                  aGLHRepository project id.
1✔
1099

1✔
1100
        branches := (resultBranches collect: [ :branchesJson |
1✔
1101
                             self parseBranchesResult: branchesJson ]) flattened.
1✔
1102

1✔
1103
        'import the branches of project ' recordInfo.
1✔
1104

1✔
1105
        branches := aGLHRepository branches
1✔
1106
                            addAll: branches
1✔
1107
                            unless: self blockOnNameEquality.
1✔
1108
        branches := self glhModel
1✔
1109
                            addAll: branches
1✔
1110
                            unless: self blockOnNameEquality.
1✔
1111

1✔
1112

1✔
1113
        self withFiles ifTrue: [
1✔
1114
                branches do: [ :branch | self importFilesOfBranch: branch ] ] ]
1✔
1115
                on: NeoJSONParseError
1✔
1116
                do: [
1✔
1117
                self inform: aGLHRepository project name , ' has no repository' ].
1✔
1118
        
1✔
1119
        withInitialCommits ifTrue: [
1✔
1120
                aGLHRepository branches do: [ :branch |
1✔
1121
                        self importCommitsOfBranch: branch ] ]
1✔
1122
]
1✔
1123

1124
{ #category : #'import - users' }
1125
GitlabModelImporter >> importUser: aUserID [
1✔
1126

1✔
1127
        | result userResult |
1✔
1128
        (self glhModel allWithType: GLHUser)
1✔
1129
                detect: [ :user | user id = aUserID ]
1✔
1130
                ifFound: [ :user | ^ user ].
1✔
1131
        ('Import user: ' , aUserID printString) recordInfo.
1✔
1132
        
1✔
1133
        result := self repoApi users get: aUserID.
1✔
1134
        userResult := self parseUserResult: result.
1✔
1135
        
1✔
1136
        userResult := self glhModel add: userResult unless: self blockOnIdEquality.
1✔
1137
        userCatalogue addUser: userResult.
1✔
1138
        ^ userResult 
1✔
1139
]
1✔
1140

1141
{ #category : #'import - users' }
1142
GitlabModelImporter >> importUserByUsername: anUsername [
1✔
1143

1✔
1144
        | dicUsername resultUser |
1✔
1145
        dicUsername := ((self glhModel allWithType: GLHUser) collect: [ :user |
1✔
1146
                                user username -> user ]) asSet asDictionary.
1✔
1147

1✔
1148
        dicUsername addAll: self userCatalogue collectUsernames.
1✔
1149

1✔
1150

1✔
1151
        resultUser := dicUsername
1✔
1152
                              at: anUsername
1✔
1153
                              ifAbsent: [ "thus we have to import this new user"
1✔
1154
                                      | result userId searchResult params |
1✔
1155
                                      ('Import user with username: '
1✔
1156
                                       , anUsername printString) recordInfo.
1✔
1157
                                      params := { (#search -> anUsername) } asDictionary.
1✔
1158
                                      result := self repoApi users allWithParams: params.
1✔
1159
                                                        
1✔
1160
                                                         "when result is an error"
1✔
1161
                                                         (result isString) ifTrue: [ result := { result } ].
1✔
1162
                                                        
1✔
1163
                                      searchResult := result ifEmpty: [ result ] ifNotEmpty: [(result collect: [ :usersJson |
1✔
1164
                                                               NeoJSONReader fromString: usersJson ]) first].
1✔
1165
                                                         
1✔
1166
                                      (searchResult class = Dictionary and: [
1✔
1167
                                               (searchResult at: #message) includesSubstring:
1✔
1168
                                                       '403 Forbidden' ])
1✔
1169
                                              ifTrue: [ "if the result is an 403 error we fake a new user"
1✔
1170
                                                      self glhModel
1✔
1171
                                                              add: (GLHUser new
1✔
1172
                                                                               username: anUsername;
1✔
1173
                                                                               name: anUsername;
1✔
1174
                                                                               yourself)
1✔
1175
                                                              unless: [ :nu :ou | nu username = ou username ] ]
1✔
1176
                                              ifFalse: [
1✔
1177
                                                      searchResult
1✔
1178
                                                              ifEmpty: [ "results can be empty thus we force a new user with the info we have "
1✔
1179
                                                                      self glhModel
1✔
1180
                                                                              add: (GLHUser new
1✔
1181
                                                                                               username: anUsername;
1✔
1182
                                                                                               name: anUsername;
1✔
1183
                                                                                               yourself)
1✔
1184
                                                                              unless: [ :nu :ou | nu username = ou username ] ]
1✔
1185
                                                              ifNotEmpty: [ "because we may already have the researched user, we look by ID in the model"
1✔
1186
                                                                      userId := searchResult first at: #id.
1✔
1187
                                                                      (self glhModel allWithType: GLHUser)
1✔
1188
                                                                              detect: [ :user | user id = userId ]
1✔
1189
                                                                              ifNone: [ self importUser: userId ] ] ] ].
1✔
1190

1✔
1191
        self userCatalogue addUser: resultUser withName: anUsername.
1✔
1192

1✔
1193
        ^ resultUser
1✔
1194
]
1✔
1195

1196
{ #category : #initialization }
1197
GitlabModelImporter >> initReader [
1✔
1198

1✔
1199
        generalReader := NeoJSONReader new.
1✔
1200
        self configureReaderForCommit: generalReader.
1✔
1201
        self configureReaderForGroup: generalReader.
1✔
1202
        self configureReaderForDiffs: generalReader.
1✔
1203
        self configureReaderForMergeRequest: generalReader
1✔
1204
]
1✔
1205

1206
{ #category : #initialization }
1207
GitlabModelImporter >> initialize [
1✔
1208

1✔
1209
        super initialize.
1✔
1210
        withCommitDiffs := true.
1✔
1211
        withInitialCommits := false.
1✔
1212
        withInitialMergeRequest := false.
1✔
1213

1✔
1214
        self withCommitsSince: 1 week.
1✔
1215

1✔
1216
        self initReader
1✔
1217
]
1✔
1218

1219
{ #category : #private }
1220
GitlabModelImporter >> isServerError: aString [
1✔
1221
        ^ aString = '{"message":"500 Internal Server Error"}'
1✔
1222
]
1✔
1223

1224
{ #category : #'import - projects' }
1225
GitlabModelImporter >> loadAllProjectsFromRepositorySoftware [
×
1226
        "heavy import that load all the active project inside the model. Only import the project entities"
×
1227
        |projects|
×
1228
        
×
1229
        projects := self repoApi projects. 
×
1230
]
×
1231

1232
{ #category : #'private - parsing' }
1233
GitlabModelImporter >> newParseCommitResult: result [
×
1234

×
1235
        generalReader  on: result readStream.
×
1236

×
1237
        ^ generalReader nextAs: GLHCommit
×
1238
]
×
1239

1240
{ #category : #'private - parsing' }
1241
GitlabModelImporter >> newParseDiffResult: result [
1✔
1242

1✔
1243
        generalReader on: result readStream.
1✔
1244
        ^ generalReader nextAs: #ArrayOfDiffs
1✔
1245
]
1✔
1246

1247
{ #category : #'private - parsing' }
1248
GitlabModelImporter >> parseArrayOfProject: arrayOfProjects [
×
1249

×
1250
        | reader |
×
1251
        reader := NeoJSONReader on: arrayOfProjects readStream.
×
1252
        reader
×
1253
                for: #ArrayOfProjects
×
1254
                customDo: [ :customMappting |
×
1255
                customMappting listOfElementSchema: GLHProject ].
×
1256
        reader for: GLHProject do: [ :mapping |
×
1257
                mapping mapInstVar: #name to: #name.
×
1258
                mapping mapInstVar: #description to: #description.
×
1259
                mapping mapInstVar: #id to: #id.
×
1260
                mapping mapInstVar: #archived to: #archived.
×
1261
                mapping mapInstVar: #web_url to: #html_url.
×
1262
                mapping mapInstVar: #topics to: #topics ].
×
1263
        ^ reader nextAs: #ArrayOfProjects
×
1264
]
×
1265

1266
{ #category : #'private - parsing' }
1267
GitlabModelImporter >> parseBranchesResult: result [
1✔
1268

1✔
1269
        | reader |
1✔
1270
        reader := NeoJSONReader on: result readStream.
1✔
1271
        reader mapInstVarsFor: GLHBranch.
1✔
1272
        reader
1✔
1273
                for: #ArrayOfBranch
1✔
1274
                customDo: [ :customMappting | 
1✔
1275
                customMappting listOfElementSchema: GLHBranch ].
1✔
1276
        ^ reader nextAs: #ArrayOfBranch
1✔
1277
]
1✔
1278

1279
{ #category : #'private - parsing' }
1280
GitlabModelImporter >> parseCommitResult: result [
×
1281

×
1282
        | reader |
×
1283
        reader := NeoJSONReader on: result readStream.
×
1284

×
1285
        reader for: GLHCommit do: [ :mapping |
×
1286
                mapping mapInstVars:
×
1287
                        #( id short_id title author_name author_email committer_name
×
1288
                           committer_email message web_url ).
×
1289
                (mapping mapInstVar: #authored_date) valueSchema: DateAndTime.
×
1290
                (mapping mapInstVar: #committed_date) valueSchema: DateAndTime.
×
1291
                (mapping mapInstVar: #created_at) valueSchema: DateAndTime.
×
1292
                (mapping mapInstVar: #parent_ids) valueSchema: #ArrayOfIds.
×
1293
                mapping
×
1294
                        mapProperty: 'stats'
×
1295
                        getter: [ :el | "Not used" ]
×
1296
                        setter: [ :commit :value |
×
1297
                                commit deletions: (value at: #deletions).
×
1298
                                commit additions: (value at: #additions) ] ].
×
1299

×
1300
        reader for: DateAndTime customDo: [ :mapping |
×
1301
                mapping decoder: [ :string | DateAndTime fromString: string ] ].
×
1302

×
1303
        reader
×
1304
                for: #ArrayOfIds
×
1305
                customDo: [ :mapping | mapping decoder: [ :string | string ] ].
×
1306

×
1307

×
1308
        ^ reader nextAs: GLHCommit
×
1309
]
×
1310

1311
{ #category : #'private - parsing' }
1312
GitlabModelImporter >> parseCommitsResult: result [
1✔
1313

1✔
1314
        | reader |
1✔
1315
        reader := NeoJSONReader on: result readStream.
1✔
1316

1✔
1317
          reader for: GLHCommit do: [ :mapping |
1✔
1318
                mapping mapInstVars:
1✔
1319
                        #( id short_id title author_name author_email committer_name
1✔
1320
                           committer_email message web_url ).
1✔
1321
                (mapping mapInstVar: #authored_date) valueSchema: DateAndTime.
1✔
1322
                (mapping mapInstVar: #committed_date) valueSchema: DateAndTime.
1✔
1323
                (mapping mapInstVar: #created_at) valueSchema: DateAndTime.
1✔
1324
                (mapping mapInstVar: #parent_ids) valueSchema: #ArrayOfIds.
1✔
1325
                mapping
1✔
1326
                        mapProperty: 'stats'
1✔
1327
                        getter: [ :el | "Not used" ]
1✔
1328
                        setter: [ :commit :value |
1✔
1329
                                commit deletions: (value at: #deletions).
1✔
1330
                                commit additions: (value at: #additions) ] ].
1✔
1331

1✔
1332
        reader for: DateAndTime customDo: [ :mapping |
1✔
1333
                mapping decoder: [ :string | DateAndTime fromString: string ] ].
1✔
1334

1✔
1335
        reader
1✔
1336
                for: #ArrayOfIds
1✔
1337
                customDo: [ :mapping | mapping decoder: [ :string | string ] ].
1✔
1338
  
1✔
1339
        reader
1✔
1340
                for: #ArrayOfCommit
1✔
1341
                customDo: [ :customMappting |
1✔
1342
                customMappting listOfElementSchema: GLHCommit ].
1✔
1343

1✔
1344
        ^ reader nextAs: #ArrayOfCommit
1✔
1345
]
1✔
1346

1347
{ #category : #private }
1348
GitlabModelImporter >> parseDiffResult: result [
×
1349

×
1350
        | reader |
×
1351
        self
×
1352
                deprecated: 'Use #newParseDiffResult: instead'
×
1353
                on: '28 June 2024'
×
1354
                in:
×
1355
                'Pharo-11.0.0+build.726.sha.aece1b5473acf3830a0e082c1bc3a15d4ff3522b (64 Bit)'.
×
1356
        reader := NeoJSONReader on: result readStream.
×
1357
        reader for: GLHDiff do: [ :mapping |
×
1358
                mapping mapInstVars:
×
1359
                        #( deleted_file new_file new_path old_path renamed_file ).
×
1360
                mapping mapInstVar: #diffString to: #diff ].
×
1361

×
1362
        reader
×
1363
                for: #ArrayOfDiffs
×
1364
                customDo: [ :customMappting |
×
1365
                customMappting listOfElementSchema: GLHDiff ].
×
1366
        ^ reader nextAs: #ArrayOfDiffs
×
1367
]
×
1368

1369
{ #category : #'private - parsing' }
1370
GitlabModelImporter >> parseFileTreeResult: aResult [
×
1371

×
1372
        | reader |
×
1373
        reader := NeoJSONReader on: aResult readStream.
×
1374
        reader mapInstVarsFor: GLHApiFile.
×
1375
        reader
×
1376
                for: #ArrayOfFile
×
1377
                customDo: [ :customMappting | 
×
1378
                customMappting listOfElementSchema: GLHApiFile ].
×
1379
        ^ reader nextAs: #ArrayOfFile
×
1380
]
×
1381

1382
{ #category : #'private - parsing' }
1383
GitlabModelImporter >> parseGroupResult: aResult [
1✔
1384

1✔
1385
        | reader |
1✔
1386

1✔
1387
        reader := NeoJSONReader on: aResult readStream.
1✔
1388
        reader for: GLHGroup do: [ :mapping |
1✔
1389
                mapping mapInstVars.
1✔
1390
                (mapping mapInstVar: #projects) valueSchema: #ArrayOfProjects ].
1✔
1391
        reader mapInstVarsFor: GLHProject.
1✔
1392
        reader
1✔
1393
                for: #ArrayOfProjects
1✔
1394
                customDo: [ :customMappting |
1✔
1395
                customMappting listOfElementSchema: GLHProject ].
1✔
1396
        ^ reader nextAs: GLHGroup
1✔
1397
]
1✔
1398

1399
{ #category : #'private - parsing' }
1400
GitlabModelImporter >> parseJobsResult: result ofProject: aProject [
×
1401

×
1402
        | reader |
×
1403
        reader := NeoJSONReader on: result readStream.
×
1404
        reader for: GLHJob do: [ :mapping |
×
1405
                mapping mapInstVars: #( id allow_failure web_url name ).
×
1406

×
1407
                mapping
×
1408
                        mapProperty: #user
×
1409
                        getter: [ :object | #ignore ]
×
1410
                        setter: [ :object :value |
×
1411
                        object user: (self importUser: (value at: #id)) ].
×
1412

×
1413
                mapping
×
1414
                        mapProperty: #commit
×
1415
                        getter: [ :object | #ignore ]
×
1416
                        setter: [ :object :value |
×
1417
                                value ifNotNil: [
×
1418
                                        object commit:
×
1419
                                                (self importCommit: (value at: #id) ofProject: aProject) ] ].
×
1420

×
1421
                mapping
×
1422
                        mapProperty: #duration
×
1423
                        getter: [ :object | #ignore ]
×
1424
                        setter: [ :object :value |
×
1425
                        value ifNotNil: [ object duration: value seconds ] ] ].
×
1426

×
1427
        reader
×
1428
                for: #ArrayOfGLHJob
×
1429
                customDo: [ :customMappting |
×
1430
                customMappting listOfElementSchema: GLHJob ].
×
1431
        ^ reader nextAs: #ArrayOfGLHJob
×
1432
]
×
1433

1434
{ #category : #'private - parsing' }
1435
GitlabModelImporter >> parseMergeRequestResult: result [
1✔
1436

1✔
1437
        generalReader on: result readStream.
1✔
1438
        ^ generalReader nextAs: #ArrayOfMergeRequest
1✔
1439
]
1✔
1440

1441
{ #category : #'private - parsing' }
1442
GitlabModelImporter >> parseNoteJson: results [  
1✔
1443
    | reader |  
1✔
1444

1✔
1445
    "Créer un lecteur JSON"
1✔
1446
    reader := NeoJSONReader on: results readStream.    
1✔
1447

1✔
1448
    "Définir le mapping pour l'objet GLHNote"
1✔
1449
    reader for: GLHNote do: [ :mapping |  
1✔
1450
        mapping mapInstVars: #(id noteable_id attachment system confidential internal  
1✔
1451
                               noteable_iid resolvable imported imported_from  
1✔
1452
                               author body project_id noteable_type).  
1✔
1453

1✔
1454
        (mapping mapInstVar: #created_at) valueSchema: DateAndTime.  
1✔
1455
        (mapping mapInstVar: #updated_at) valueSchema: DateAndTime.  
1✔
1456
    ].    
1✔
1457

1✔
1458
    "Corriger la conversion des dates"
1✔
1459
    reader for: DateAndTime customDo: [ :mapping |  
1✔
1460
        mapping decoder: [ :string | DateAndTime readFrom: string readStream ] ].
1✔
1461

1✔
1462
        reader
1✔
1463
                for: #ArrayOfNote
1✔
1464
                customDo: [ :customMappting | 
1✔
1465
                customMappting listOfElementSchema: GLHNote ].
1✔
1466
         ^ reader nextAs: #ArrayOfNote
1✔
1467

1✔
1468
    "Retourner la Note"
1✔
1469
    "^ reader nextAs: GLHNote"
1✔
1470

1✔
1471

1✔
1472
]
1✔
1473

1474
{ #category : #'private - parsing' }
1475
GitlabModelImporter >> parsePipelinesResult: result [
×
1476

×
1477
        | reader |
×
1478
        
×
1479
        (result includesSubstring: '{"message":"40' )ifTrue: [ ^ {  } ].
×
1480
        
×
1481
        reader := NeoJSONReader on: result readStream.
×
1482
        reader mapInstVarsFor: GLHPipeline.
×
1483
        reader for: GLHPipeline do: [ :mapping |
×
1484
                mapping
×
1485
                        mapProperty: #created_at
×
1486
                        getter: [ :object | #ignore ]
×
1487
                        setter: [ :object :value |
×
1488
                        object runDate: (DateAndTime fromString: value) ] ].
×
1489
        reader
×
1490
                for: #ArrayOfPipelines
×
1491
                customDo: [ :customMappting |
×
1492
                customMappting listOfElementSchema: GLHPipeline ].
×
1493
        ^ reader nextAs: #ArrayOfPipelines
×
1494
]
×
1495

1496
{ #category : #'private - parsing' }
1497
GitlabModelImporter >> parseProjectResult: aResult [ 
1✔
1498
                | reader |
1✔
1499
        reader := NeoJSONReader on: aResult readStream.
1✔
1500
        reader for: GLHProject do: [ :mapping |
1✔
1501
                mapping mapInstVars. ].
1✔
1502
"        reader mapInstVarsFor: GLHProject."
1✔
1503

1✔
1504
        ^ reader nextAs: GLHProject
1✔
1505
]
1✔
1506

1✔
1507
{ #category : #'private - parsing' }
1✔
1508
GitlabModelImporter >> parseSubGroupResult: aResult [
1✔
1509

1✔
1510
        | reader |
1✔
1511
        reader := NeoJSONReader on: aResult readStream.
1✔
1512
        self configureReaderForGroup: reader.
1✔
1513
        ^ reader nextAs: #ArrayOfGroups
1✔
1514
]
1✔
1515

1✔
1516
{ #category : #'private - parsing' }
1✔
1517
GitlabModelImporter >> parseUserResult: result [
1✔
1518

1✔
1519
        | reader |
1✔
1520
        reader := NeoJSONReader on: result readStream.
1✔
1521
        reader mapInstVarsFor: GLHUser.
1✔
1522
        ^ reader nextAs: GLHUser
1✔
1523
]
1✔
1524

1✔
1525
{ #category : #'private - parsing' }
1✔
1526
GitlabModelImporter >> parseUsersResult: result [
1✔
1527

1✔
1528
        | reader |
1✔
1529
        reader := NeoJSONReader on: result readStream.
1✔
1530

1✔
1531
        reader mapInstVarsFor: GLHUser.
1✔
1532

1✔
1533
        reader
1✔
1534
                for: #ArrayOfUser
1✔
1535
                customDo: [ :customMappting |
1✔
1536
                customMappting listOfElementSchema: GLHUser ].
1✔
1537

1✔
1538
        ^ reader nextAs: #ArrayOfUser
1✔
1539
]
1✔
1540

1✔
1541
{ #category : #'imports - pipelines' }
1✔
1542
GitlabModelImporter >> pipelinesOf: aProjectID [
1✔
1543

1✔
1544
        | result |
1✔
1545
        ('Search pipelines of: ' , aProjectID printString) recordInfo.
1✔
1546
        result := self repoApi pipelines getAllInProject: aProjectID.
1✔
1547
        result isString ifTrue: [ ^ self parsePipelinesResult: result ].
1✔
1548

1✔
1549
        ^ (result collect: [ :pipelinesJson |
1✔
1550
                           self parsePipelinesResult: pipelinesJson ]) flattened
1✔
1551
]
1✔
1552

1✔
1553
{ #category : #accessing }
1✔
1554
GitlabModelImporter >> repoApi: anObject [
1✔
1555
        super repoApi: anObject.
1✔
1556
        self repoApi output: 'json'
1✔
1557
]
1✔
1558

1✔
1559
{ #category : #private }
1✔
1560
GitlabModelImporter >> selectEntityType: aType overAttribut: aSelector equalTo: value [
1✔
1561

1✔
1562
        ^ (self glhModel allWithType: aType)
1✔
1563
                select: [ :entity | (entity perform: aSelector) = value ]
1✔
1564
]
1✔
1565

1✔
1566
{ #category : #'import - groups' }
1✔
1567
GitlabModelImporter >> subGroupsOf: aGroupID [
1✔
1568

1✔
1569
        | results subgroups |
1✔
1570
        ('Search subgroup of: ' , aGroupID printString) recordInfo.
1✔
1571
        results := self repoApi groups subgroupsOf: aGroupID.
1✔
1572
        subgroups := (results collect: [ :subgroupsJson | self parseSubGroupResult: subgroupsJson ]) flattened.
1✔
1573
        
1✔
1574
        ^ subgroups
1✔
1575
]
1✔
1576

1✔
1577
{ #category : #accessing }
1✔
1578
GitlabModelImporter >> withInitialCommits: boolean [
1✔
1579
        withInitialCommits := boolean 
1✔
1580
]
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