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

moosetechnology / GitProjectHealth / 14190600424

01 Apr 2025 08:13AM UTC coverage: 72.386% (+1.0%) from 71.4%
14190600424

Pull #175

github

web-flow
Merge pull request #177 from moosetechnology/not-autoreneraku-for-now

remove autoreneraku for now
Pull Request #175: Develop

1556 of 2760 new or added lines in 40 files covered. (56.38%)

2 existing lines in 1 file now uncovered.

15272 of 21098 relevant lines covered (72.39%)

0.72 hits per line

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

54.56
/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 - commits' }
349
GitlabModelImporter >> importCommit: aCommitID ofProject: aGLHProject [
×
350

×
351
        | result parsedResult |
×
352
        (self glhModel allWithType: GLHCommit) asOrderedCollection
×
353
                detect: [ :commit | commit id = aCommitID ]
×
354
                ifFound: [ :commit | ^ commit ].
×
355
        result := self repoApi commits get: aCommitID inProject: aGLHProject id.
×
356
        
×
357
        parsedResult := self parseCommitResult: result.
×
358
        
×
359
        self
×
360
                addCommits: { parsedResult }
×
361
                toRepository: aGLHProject repository.
×
362
        ^ parsedResult
×
363
]
×
364

365
{ #category : #'import - commits' }
366
GitlabModelImporter >> importCommitOfProject: anProject withId: anID [
1✔
367

1✔
368
        | commit result |
1✔
369
        anID ifNil: [ ^ nil ].
1✔
370

1✔
371
        ('looking for commit ' , anID printString , ' in project : '
1✔
372
         , anProject id printString) recordInfo.
1✔
373

1✔
374
        commit := (self
1✔
375
                           detectEntityType: GLHCommit
1✔
376
                           overAttribut: #id
1✔
377
                           equalTo: anID) ifNil: [
1✔
378
                          result := self repoApi commits get: anID inProject: anProject id.
1✔
379
                          commit := (self parseCommitsResult: '[' , result , ']')
1✔
380
                                            first.
1✔
381

1✔
382
                          self glhModel add: commit unless: self blockOnIdEquality.
1✔
383
                          commit repository: anProject repository.
1✔
384

1✔
385
                          commit ].
1✔
386

1✔
387
        self withCommitDiffs ifTrue: [ self importDiffOfCommit: commit ].
1✔
388

1✔
389
        ^ commit
1✔
390
]
1✔
391

392
{ #category : #'import - commits' }
393
GitlabModelImporter >> importCommits: aGLHProject [
×
394
        "limited to the last 20 commits"
×
395

×
396
        | results parsedResults params |
×
397
        params := { 
×
398
         #with_stats -> 'true'
×
399
        } asDictionary.
×
400
        results := self repoApi commits getByPage: 1 perPage: 20 inProject: aGLHProject id withParams: params.
×
401
        
×
402
        parsedResults := self parseCommitsResult: results.
×
403
        self glhModel addAll: parsedResults unless: self blockOnIdEquality.
×
404

×
405
        parsedResults do: [ :commit |
×
406
                commit repository: aGLHProject repository ].
×
407

×
408
        self withCommitDiffs ifTrue: [
×
409
                parsedResults do: [ :commit | self importDiffOfCommit: commit ] ].
×
410
        
×
411
        ^ parsedResults. 
×
412
]
×
413

414
{ #category : #'import - commits' }
415
GitlabModelImporter >> importCommitsFollowing: aCommit upToDays: aNumberOfDay [
×
416
        "import the 'n' commits of a project starting from an initial 'aCommit' commit. 
×
417
        Lazy import does not import the entities inside the model"
×
418

×
419
        | date |
×
420
        date := aCommit created_at asDateAndTime.
×
421

×
422
        ^ self
×
423
                  importCommitsOfBranch: aCommit branch
×
424
                  forRefName: aCommit branch name
×
425
                  since: date
×
426
                  until: (date + aNumberOfDay day)
×
427
]
×
428

429
{ #category : #commit }
430
GitlabModelImporter >> importCommitsOf: aGLHProject withStats: aBoolean until: toDate [
×
431

×
432
        | newlyFoundCommit page |
×
433
        
×
434
        self deprecated: [  ] .
×
435
        
×
436
        page := 0.
×
437
        newlyFoundCommit := { true }.
×
438
        [ newlyFoundCommit isNotEmpty ] whileTrue: [
×
439
                | results parsedResults existingCommits |
×
440
                page := page + 1.
×
441
                ('import commit page ' , page printString) recordInfo.
×
442
                results := self repoApi
×
443
                                   commitsOfProject: aGLHProject id
×
444
                                   forRefName: nil
×
445
                                   since: nil
×
446
                                   until: nil
×
447
                                   path: nil
×
448
                                   author: nil
×
449
                                   all: nil
×
450
                                   with_stats: aBoolean
×
451
                                   firstParent: nil
×
452
                                   order: nil
×
453
                                   trailers: nil
×
454
                                   perPage: 100
×
455
                                   page: page.
×
456
                parsedResults := self parseCommitsResult: results.
×
457
                existingCommits := aGLHProject mooseModel allWithType: GLHCommit.
×
458

×
459
                newlyFoundCommit := parsedResults reject: [ :commitParsed |
×
460
                                            (toDate isNil or: [
×
461
                                                     commitParsed committed_date
×
462
                                                     < toDate asDateAndTime ]) or: [
×
463
                                                    existingCommits anySatisfy: [ :existingCommit |
×
464
                                                            existingCommit id = commitParsed id ] ] ].
×
465
                aGLHProject mooseModel addAll: newlyFoundCommit.
×
466
                aGLHProject repository commits addAll: newlyFoundCommit ].
×
467

×
468

×
469
        self withCommitDiffs ifTrue: [
×
470
                aGLHProject repository commits do: [ :commit |
×
471
                        self importDiffOfCommit: commit ] ]
×
472
]
×
473

474
{ #category : #'import - commits' }
475
GitlabModelImporter >> importCommitsOfBranch: aGLHBranch [
×
476

×
477
        | commits |
×
478
        "        result := self glhApi
×
479
                          commitsOfProject: aGLHBranch repository project id
×
480
                          forRefName: aGLHBranch name."
×
481
        commits := self
×
482
                           importCommitsOfBranch: aGLHBranch
×
483
                           forRefName: aGLHBranch name
×
484
                           since: withCommitsSince.
×
485

×
486
        self chainsCommitsFrom: commits.
×
487

×
488
        commits do: [ :aCommit |
×
489
                aCommit repository: aGLHBranch repository.
×
490
                self completeImportedCommit: aCommit. 
×
491
                 ]
×
492
]
×
493

494
{ #category : #'import - commits' }
495
GitlabModelImporter >> importCommitsOfBranch: aGLHBranch forRefName: refName since: fromDate [
×
496

×
497
        ^ self
×
498
                  importCommitsOfBranch: aGLHBranch
×
499
                  forRefName: aGLHBranch name
×
500
                  since: fromDate
×
501
                  until: nil
×
502
]
×
503

504
{ #category : #'import - commits' }
505
GitlabModelImporter >> importCommitsOfBranch: aGLHBranch forRefName: refName since: fromDate until: toDate [
×
506

×
507
        | params result allCommits |
×
508
        params := { 
×
509
          #ref_name -> aGLHBranch name.
×
510
          #since ->  (fromDate ifNotNil: [ fromDate asDate asDateAndTime asString ] ifNil: [ '' ]).
×
511
          #until -> (toDate ifNotNil: [ toDate asDate asDateAndTime asString ] ifNil: [ '' ]). 
×
512

×
513
        } asDictionary.
×
514
        result := self repoApi commits getAllInProject: aGLHBranch repository project id withParams: params.
×
515
        
×
516
        allCommits := (result collect: [ :commitsJson | self parseCommitsResult: commitsJson ]) flattened.
×
517
        
×
518
        aGLHBranch commits
×
519
                        addAll: allCommits
×
520
                        unless: self blockOnIdEquality.
×
521

×
522
        self glhModel
×
523
                addAll: aGLHBranch commits
×
524
                unless: self blockOnIdEquality.
×
525

×
526
        ^ allCommits
×
527
]
×
528

529
{ #category : #'import - commits' }
530
GitlabModelImporter >> importCommitsOfBranch: aGLHBranch forRefName: refName until: toDate [
×
531

×
532
        ^ self
×
533
                  importCommitsOfBranch: aGLHBranch
×
534
                  forRefName: aGLHBranch name
×
535
                  since: nil
×
536
                  until: toDate
×
537
]
×
538

539
{ #category : #'import - commits' }
540
GitlabModelImporter >> importCommitsOfProject: aProject since: fromDate until: toDate [
1✔
541

1✔
542
        | params results allCommits |
1✔
543
        params := {
1✔
544
                          (#since
1✔
545
                           ->
1✔
546
                           (fromDate
1✔
547
                                    ifNotNil: [ fromDate asDate asDateAndTime asString ]
1✔
548
                                    ifNil: [ '' ])).
1✔
549
                          (#until
1✔
550
                           ->
1✔
551
                           (toDate
1✔
552
                                    ifNotNil: [ toDate asDate asDateAndTime asString ]
1✔
553
                                    ifNil: [ '' ])).
1✔
554
                          (#with_stats -> 'true').
1✔
555
                          (#all -> 'true') } asDictionary.
1✔
556
        results := self repoApi commits
1✔
557
                           getAllInProject: aProject id
1✔
558
                           withParams: params.
1✔
559

1✔
560
        allCommits := (results collect: [ :commitsJson |
1✔
561
                               self parseCommitsResult: commitsJson ]) flattened.
1✔
562

1✔
563
        allCommits:= aProject repository commits
1✔
564
                addAll: allCommits
1✔
565
                unless: self blockOnIdEquality.
1✔
566

1✔
567
        ^ self glhModel addAll: allCommits unless: self blockOnIdEquality
1✔
568
]
1✔
569

570
{ #category : #'import - projects' }
571
GitlabModelImporter >> importContributedProjectsOfUser: aGLHUser [
×
572

×
573
        | remaningProjects params results projects projectsIds |
×
574
        params := {
×
575
                          (#order_by -> 'last_activity_at').
×
576
                          (#simple -> 'true') } asDictionary.
×
577
        results := self repoApi projects
×
578
                           contributedProjectsOfUser: aGLHUser id
×
579
                           withParams: params.
×
580

×
581
        projectsIds := (results collect: [ :projectsJson |
×
582
                             (NeoJSONReader fromString: projectsJson) collect: [:projectJson | projectJson at: #id ] ]) flattened.
×
583
        
×
584
        projects := self importProjects: projectsIds.
×
585
        remaningProjects := self importProjects:
×
586
                                    ((projects collect: #id) difference:
×
587
                                             ((self userCatalogue atId: aGLHUser id) at:
×
588
                                                      #contributedProjects)).
×
589

×
590

×
591
        aGLHUser contributedProjects
×
592
                addAll: projects , remaningProjects
×
593
                unless: self blockOnIdEquality.
×
594

×
595
        self userCatalogue
×
596
                addUser: aGLHUser
×
597
                withProjects: (aGLHUser contributedProjects collect: #id).
×
598

×
599
        ^ projects
×
600
]
×
601

602
{ #category : #'import - commits' }
603
GitlabModelImporter >> importCreatorOfCommit: aCommit [
1✔
604

1✔
605
        aCommit commitCreator ifNil: [
1✔
606
                aCommit commitCreator:
1✔
607
                        (self importUserByUsername: aCommit author_name) ].
1✔
608
        self userCatalogue
1✔
609
                addUser: aCommit commitCreator
1✔
610
                withProject: aCommit repository project id.
1✔
611
        ^ aCommit commitCreator
1✔
612
]
1✔
613

614
{ #category : #'import - commits' }
615
GitlabModelImporter >> importDiffOfCommit: aCommit [
1✔
616

1✔
617
        | result diffsResult |
1✔
618
        aCommit diffs ifNotEmpty: [
1✔
619
                'Diff already importer: ' , aCommit short_id printString recordInfo.
1✔
620
                ^ aCommit diffs ].
1✔
621
        ('Import diff of commit: ' , aCommit short_id printString) recordInfo.
1✔
622

1✔
623
        result := self repoApi commits
1✔
624
                          diffOf: aCommit id
1✔
625
                          inProject: aCommit repository project id
1✔
626
                          uniDiff: true.
1✔
627

1✔
628
        (self isServerError: result) ifTrue: [ ^ {  } ].
1✔
629
        diffsResult := self newParseDiffResult: result.
1✔
630

1✔
631
        aCommit diffs addAll: diffsResult unless: self blockForDiffEquality.
1✔
632
        
1✔
633
        "changes are added into the model during the import"
1✔
634
        aCommit diffs do: [ :diff | self importDiffRangesForDiff: diff ].
1✔
635

1✔
636
        ^ aCommit diffs
1✔
637
]
1✔
638

639
{ #category : #'import - merge request' }
640
GitlabModelImporter >> importDiffOfMergeRequest: aMergeRequest [
1✔
641

1✔
642
        | result diffsResult |
1✔
643
        aMergeRequest diffs ifNotEmpty: [
1✔
644
                'Diff of already importer: '
1✔
645
                , aMergeRequest iid printString recordInfo.
1✔
646
                ^ aMergeRequest diffs ].
1✔
647
        ('Import diff commits of MR ' , aMergeRequest iid printString)
1✔
648
                recordInfo.
1✔
649
        result := self repoApi mergeRequests diffsOf: aMergeRequest iid inProject: aMergeRequest project_id.
1✔
650

1✔
651
        diffsResult := self newParseDiffResult: result.
1✔
652

1✔
653

1✔
654
        aMergeRequest diffs
1✔
655
                addAll: diffsResult
1✔
656
                unless: self blockForDiffEquality.
1✔
657
        self glhModel
1✔
658
                addAll: aMergeRequest diffs
1✔
659
                unless: self blockForDiffEquality.
1✔
660

1✔
661
        aMergeRequest diffs do: [ :diff | self importDiffRangesForDiff: diff ].
1✔
662

1✔
663
        ^ aMergeRequest diffs
1✔
664
]
1✔
665

666
{ #category : #'import - repositories' }
667
GitlabModelImporter >> importDirectoryFiles: aDirectoryFile OfBranch: aBranch [
×
668

×
669
        | result files apiFiles params |
×
670
        params := { 
×
671
                #ref -> aBranch name.
×
672
                #path -> (aDirectoryFile path , '/')
×
673
        } asDictionary.
×
674
        result := self repoApi repositories repositoryTreeOfProject: aBranch repository project id withParams: params.
×
675
                         " treeOfRepository: aBranch repository project id
×
676
                          ofBranch: aBranch name
×
677
                          andPath: aDirectoryFile path , '/'."
×
678
        apiFiles := (result collect: [ :treeJson | self parseFileTreeResult: treeJson ]) flattened.
×
679
        files := apiFiles collect: [ :apiFile |
×
680
                         self convertApiFileAsFile: apiFile ].
×
681
        
×
682
        files do: [ :file |
×
683
                self glhModel add: file.
×
684
                aDirectoryFile addFile: file ].
×
685
        
×
686
        files
×
687
                select: [ :file | file isKindOf: GLHFileDirectory ]
×
688
                thenCollect: [ :file |
×
689
                self importDirectoryFiles: file OfBranch: aBranch ]
×
690
]
×
691

692
{ #category : #'import - repositories' }
693
GitlabModelImporter >> importFilesOfBranch: aBranch [
×
694

×
695
        | result files apiFiles params |
×
696
        params := { 
×
697
                #ref -> aBranch name.
×
698
        } asDictionary.
×
699
        
×
700
        result := self repoApi repositories repositoryTreeOfProject: aBranch repository project id withParams: params.
×
701
        
×
702
                          "treeOfRepository: aBranch repository project id
×
703
                          ofBranch: aBranch name
×
704
                          andPath: nil."
×
705
        apiFiles := (result collect: [ :filesJson | self parseFileTreeResult: filesJson  ]) flattened.
×
706
        files := apiFiles collect: [ :apiFile | 
×
707
                         self convertApiFileAsFile: apiFile ].
×
708
        files do: [ :file | 
×
709
                self glhModel add: file.
×
710
                aBranch addFile: file ].
×
711
        files
×
712
                select: [ :file | file isKindOf: GLHFileDirectory ]
×
713
                thenCollect: [ :file | 
×
714
                self importDirectoryFiles: file OfBranch: aBranch ]
×
715
]
×
716

717
{ #category : #'import - groups' }
718
GitlabModelImporter >> importGroup: aGroupID [
1✔
719

1✔
720
        | result groupResult |
1✔
721
        ('Import group: ' , aGroupID printString) recordInfo.
1✔
722

1✔
723
        result := self repoApi groups get: aGroupID.
1✔
724
        
1✔
725
        "group: aGroupID."
1✔
726
        groupResult := self parseGroupResult: result.
1✔
727
        groupResult := self addGroupResultToModel: groupResult.
1✔
728

1✔
729
        groupResult projects do: [ :project |
1✔
730
                self completeImportProject: project ].
1✔
731

1✔
732
        (self subGroupsOf: aGroupID) do: [ :subGroup |
1✔
733
                
1✔
734
                groupResult subGroups
1✔
735
                        add: (self importGroup: subGroup id)
1✔
736
                        unless: self blockOnIdEquality ].
1✔
737
        ^ groupResult
1✔
738
]
1✔
739

740
{ #category : #'import - jobs' }
741
GitlabModelImporter >> importJobsOf: aPipeline [
×
742

×
743
        | jobs results |
×
744
        results := self repoApi jobs allForPipeline: aPipeline id inProject: aPipeline project id.
×
745
                          "jobsOfProject: aPipeline project id
×
746
                          ofPipelines: aPipeline id."
×
747
        jobs := (results collect: [ :jobsJson | self parseJobsResult: jobsJson ofProject: aPipeline project ]) flattened.
×
748
        jobs do: [ :job | aPipeline addJob: job ].
×
749
        self glhModel addAll: jobs.
×
750
        
×
751
        ^jobs
×
752

×
753
]
×
754

755
{ #category : #'import - commits' }
756
GitlabModelImporter >> importLastestCommitsOfProject: aGLHProject [
1✔
757
        "limited to the last 50 commits"
1✔
758

1✔
759
        | results parsedResults params |
1✔
760
        params := { 
1✔
761
                #with_stats -> 'true'.
1✔
762
                #all -> true
1✔
763
         } asDictionary.
1✔
764
        results := self repoApi commits getByPage: 1 perPage: 50 inProject: aGLHProject id withParams: params.
1✔
765

1✔
766
        parsedResults := self parseCommitsResult: results.
1✔
767
        parsedResults := self glhModel
1✔
768
                                 addAll: parsedResults
1✔
769
                                 unless: self blockOnIdEquality.
1✔
770

1✔
771
        aGLHProject repository commits
1✔
772
                addAll: parsedResults
1✔
773
                unless: self blockOnIdEquality.
1✔
774

1✔
775
        self withCommitDiffs ifTrue: [
1✔
776
                parsedResults do: [ :commit | self importDiffOfCommit: commit ] ].
1✔
777

1✔
778
        ^ parsedResults
1✔
779
]
1✔
780

781
{ #category : #'import - merge request' }
782
GitlabModelImporter >> importMergeRequestCommits: aGLPHEMergeRequest [
×
783

×
784
        | commits result |
×
785
        aGLPHEMergeRequest commits ifNotNil: [ ^ aGLPHEMergeRequest commits ].
×
786
        
×
787
        result := self repoApi mergeRequests commitsOf: aGLPHEMergeRequest iid inProject: aGLPHEMergeRequest project id.
×
788
        
×
789
        commits := (result collect: [ :commitsJson | self parseCommitsResult: commitsJson ]) flattened.
×
790
        commits := commits collect: [ :commit | self importCommit: commit id ofProject: aGLPHEMergeRequest project ].
×
791
        aGLPHEMergeRequest commits: commits.
×
792

×
793

×
794
        ^ commits
×
795
]
×
796

797
{ #category : #'import - merge request' }
798
GitlabModelImporter >> importMergeRequestMergeCommits: aGLPHEMergeRequest [
1✔
799

1✔
800
        | foundCommits |
1✔
801
        foundCommits := OrderedCollection new.
1✔
802

1✔
803
        ('Import commit sha of MR:  ' , aGLPHEMergeRequest iid printString)
1✔
804
                recordInfo.
1✔
805
        "the founds commits are added to the model during their respective import"
1✔
806
        aGLPHEMergeRequest mergeRequestCommit: ((self
1✔
807
                          importCommitOfProject: aGLPHEMergeRequest project
1✔
808
                          withId: aGLPHEMergeRequest sha) ifNotNil: [ :commit |
1✔
809
                         foundCommits add: commit ]).
1✔
810

1✔
811
        ('Import commit merge_commit_sha of MR:  '
1✔
812
         , aGLPHEMergeRequest iid printString) recordInfo.
1✔
813
        aGLPHEMergeRequest mergedCommit: ((self
1✔
814
                          importCommitOfProject: aGLPHEMergeRequest project
1✔
815
                          withId: aGLPHEMergeRequest merge_commit_sha) ifNotNil: [ :commit |
1✔
816
                         foundCommits add: commit ]).
1✔
817

1✔
818
        ('Import commit squash_commit_sha of MR:  '
1✔
819
         , aGLPHEMergeRequest iid printString) recordInfo.
1✔
820
        aGLPHEMergeRequest squashCommit: ((self
1✔
821
                          importCommitOfProject: aGLPHEMergeRequest project
1✔
822
                          withId: aGLPHEMergeRequest squash_commit_sha) ifNotNil: [ :commit |
1✔
823
                         foundCommits add: commit ]).
1✔
824

1✔
825

1✔
826
        self chainsCommitsFrom: foundCommits.
1✔
827
        ^ foundCommits
1✔
828
]
1✔
829

830
{ #category : #'import - merge request' }
831
GitlabModelImporter >> importMergeRequests: aGLHProject [
1✔
832

1✔
833
        | results parsedResults mrs |
1✔
834
        ('Import merge request of Project: ' , aGLHProject id printString)
1✔
835
                recordInfo.
1✔
836

1✔
837
        results := self repoApi mergeRequests allOfProject: aGLHProject id.
1✔
838
        parsedResults := (results collect: [ :projectsJson | self parseMergeRequestResult: projectsJson ]) flattened. 
1✔
839

1✔
840
        aGLHProject mergeRequests
1✔
841
                addAll: parsedResults
1✔
842
                unless: self blockOnIdEquality.
1✔
843

1✔
844
        mrs := self glhModel
1✔
845
                       addAll: aGLHProject mergeRequests
1✔
846
                       unless: self blockOnIdEquality.
1✔
847

1✔
848

1✔
849
        "gets it related commits"
1✔
850
        aGLHProject mergeRequests do: [ :mr |
1✔
851
                self importMergeRequestMergeCommits: mr ].
1✔
852

1✔
853

1✔
854
        self withCommitDiffs ifTrue: [
1✔
855
                aGLHProject mergeRequests do: [ :mr |
1✔
856
                        self importDiffOfMergeRequest: mr ] ].
1✔
857

1✔
858
        ^ mrs
1✔
859
]
1✔
860

861
{ #category : #'import - merge request' }
862
GitlabModelImporter >> importMergeRequests: aGLHProject since: fromDate until: toDate [
×
863

×
864
        | params result mergeRequests |
×
865
        ('import MR of Project ' , aGLHProject name) recordInfo.
×
866
        params := {
×
867
                          (#created_after
×
868
                           ->
×
869
                           (fromDate
×
870
                                    ifNotNil: [ fromDate asDateAndTime asString ]
×
871
                                    ifNil: [ '' ])).
×
872
                          (#created_before
×
873
                           ->
×
874
                           (toDate
×
875
                                    ifNotNil: [ toDate asDateAndTime asString ]
×
876
                                    ifNil: [ '' ])).
×
877
                          (#scope -> 'all') } asDictionary.
×
878

×
879
        result := self repoApi mergeRequests
×
880
                          allOfProject: aGLHProject id
×
881
                          withParams: params.
×
882
        mergeRequests := (result collect: [ :mergeRequestsJson |
×
883
                                  self parseMergeRequestResult: mergeRequestsJson ])
×
884
                                 flattened.
×
885

×
886
        aGLHProject mergeRequests
×
887
                addAll: mergeRequests
×
888
                unless: self blockOnIdEquality.
×
889

×
890
        "gets it related commits"
×
891
        aGLHProject mergeRequests do: [ :mr |
×
892
                self importMergeRequestMergeCommits: mr ].
×
893

×
894
        self withCommitDiffs ifTrue: [
×
895
                aGLHProject mergeRequests do: [ :mr |
×
896
                        self importDiffOfMergeRequest: mr ] ].
×
897

×
898
        self glhModel
×
899
                addAll: mergeRequests
×
900
                unless: (self blockEqualityOn: #iid).
×
901

×
902
        ^ mergeRequests
×
903
]
×
904

905
{ #category : #'import - merge request' }
906
GitlabModelImporter >> importMergeResquestApprovals: aGLPHEMergeRequest [
×
907

×
908
        | results parsedResult |
×
909
        (String streamContents: [ :str |
×
910
                 str << 'Check approvals of '.
×
911
                 aGLPHEMergeRequest printOn: str ]) recordInfo.
×
912
        results := self repoApi mergeRequests approvalsOf: aGLPHEMergeRequest iid inProject: aGLPHEMergeRequest project id.
×
913

×
914
        parsedResult := generalReader
×
915
                                on: results readStream;
×
916
                                next.
×
917

×
918
        (parsedResult at: #approved_by) do: [ :approvedUser |
×
919
                aGLPHEMergeRequest addApproved_by:
×
920
                        (self importUser: ((approvedUser at: #user) at: #id)) ].
×
921
        aGLPHEMergeRequest approved: (parsedResult at: #approved).
×
922
        ^ aGLPHEMergeRequest
×
923
]
×
924

925
{ #category : #'import - merge request' }
926
GitlabModelImporter >> importMergeResquestAuthor: aGLPHEMergeRequest [
1✔
927

1✔
928
        | authorID |
1✔
929
        aGLPHEMergeRequest author ifNotNil: [ ^ aGLPHEMergeRequest author ].
1✔
930
        authorID := aGLPHEMergeRequest cacheAt: #authorID ifAbsent: [
1✔
931
                            | result |
1✔
932
                            result := self repoApi mergeRequests
1✔
933
                                              get: aGLPHEMergeRequest iid
1✔
934
                                              inProject: aGLPHEMergeRequest project_id.
1✔
935

1✔
936
                            (generalReader
1✔
937
                                     on: result readStream;
1✔
938
                                     next) at: #author at: #id ].
1✔
939
        ^aGLPHEMergeRequest author: (self importUser: authorID)
1✔
940
]
1✔
941

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

1✔
945
        | authorID |
1✔
946
        aGLPHEMergeRequest merge_user ifNotNil: [
1✔
947
                ^ aGLPHEMergeRequest merge_user ].
1✔
948
        authorID := aGLPHEMergeRequest cacheAt: #mergeUserID ifAbsent: [
1✔
949
                            | result |
1✔
950
                            result := self repoApi mergeRequests
1✔
951
                                              get: aGLPHEMergeRequest iid
1✔
952
                                              inProject: aGLPHEMergeRequest project_id.
1✔
953
                            (generalReader
1✔
954
                                     on: result readStream;
1✔
955
                                     next)
1✔
956
                                    at: #merge_user
1✔
957
                                    ifPresent: [ :mergeUser |
1✔
958
                                    mergeUser ifNotNil: [ :mruser | mruser at: #id ] ] ].
1✔
959
        ^aGLPHEMergeRequest merge_user: (self importUser: authorID)
1✔
960
]
1✔
961

962
{ #category : #'import - notes' }
NEW
963
GitlabModelImporter >> importNotesfromMergeRequest: mergeRequest [
×
NEW
964
        | results notes |
×
NEW
965
        
×
NEW
966
        results := self repoApi notes allInMergeRequest: mergeRequest iid ofProject: mergeRequest project id.
×
NEW
967
        
×
NEW
968
        notes := results collect: [ :note | 
×
NEW
969
                self parseNoteJson: note ].
×
NEW
970
        "notes := self parseNoteJson: results."
×
NEW
971
        notes do: [ :tabNotes | tabNotes do: [ :note |
×
NEW
972
                        note author: (self importUser: (note author at: #id)).
×
NEW
973
                        note name: note id asString]. ].
×
NEW
974
        notes := notes flattened.
×
NEW
975
        notes := self glhModel addAll: notes unless: self blockOnIdEquality. 
×
NEW
976
        notes := mergeRequest note addAll: notes unless: self blockOnIdEquality. 
×
NEW
977
        ^notes
×
NEW
978
        
×
NEW
979
]
×
980

981
{ #category : #'import - commits' }
982
GitlabModelImporter >> importParentCommitsOfCommit: aGLHCommit since: aDate [
×
983

×
984
        | parentsIds commits |
×
985
        commits := OrderedCollection new.
×
986
        aGLHCommit created_at asDateAndTime < aDate asDateAndTime ifTrue: [
×
987
                 
×
988
                ^ commits
×
989
                          add: aGLHCommit;
×
990
                          yourself ].
×
991

×
992
        parentsIds := aGLHCommit parent_ids.
×
993

×
994
        commits addAll: (parentsIds collect: [ :id |
×
995
                         self
×
996
                                 importCommitOfProject: aGLHCommit repository project
×
997
                                 withId: id ]).
×
998

×
999

×
1000
        ^ (commits collect: [ :parentCommit |
×
1001
                   self importParentCommitsOfCommit: parentCommit since: aDate ])
×
1002
                  flatten
×
1003
]
×
1004

1005
{ #category : #'imports - pipelines' }
1006
GitlabModelImporter >> importPipelinesOfProject: aGLHProject [
1✔
1007

1✔
1008
        (self pipelinesOf: aGLHProject id) do: [ :pipeline |
1✔
1009
                self glhModel add: pipeline unless: self blockOnIdEquality .
1✔
1010
                aGLHProject pipelines add: pipeline unless: self blockOnIdEquality]
1✔
1011
]
1✔
1012

1013
{ #category : #'import - projects' }
1014
GitlabModelImporter >> importProject: aProjectID [
1✔
1015

1✔
1016
        | result projectResult |
1✔
1017
        ('Import project with id:  ' , aProjectID printString) recordInfo.
1✔
1018

1✔
1019
        (glhModel allWithType: GLHProject)
1✔
1020
                detect: [ :project | project id = aProjectID ]
1✔
1021
                ifFound: [ :project | ^ project ].
1✔
1022

1✔
1023
        result := self repoApi projects get: aProjectID.
1✔
1024
        projectResult := self parseProjectResult: result.
1✔
1025

1✔
1026
        ^ self completeImportProject: projectResult
1✔
1027
]
1✔
1028

1029
{ #category : #'import - projects' }
1030
GitlabModelImporter >> importProjects [
×
1031

×
1032
        | result projects |
×
1033
        ('import all Projects') recordInfo.
×
1034

×
1035

×
1036
        result := self repoApi projects all.
×
1037
        projects := (result collect: [ :projectsJson | self parseArrayOfProject: projectsJson ]) flattened.
×
1038
        
×
1039
        self glhModel addAll: projects unless: self blockOnIdEquality.
×
1040

×
1041
        ^ projects
×
1042
]
×
1043

1044
{ #category : #'import - projects' }
1045
GitlabModelImporter >> importProjects: aCollectionOfProjectID [
×
1046

×
1047

×
1048
        ^ aCollectionOfProjectID collect: [ :id | self importProject: id ]
×
1049
]
×
1050

1051
{ #category : #imports }
1052
GitlabModelImporter >> importProjectsSince: since [
×
1053
        "heavy import of all projects"
×
1054

×
1055
        "copy import from commits"
×
1056

×
1057
        | newlyFoundProjects page foundProject amount |
×
1058
        ('import all Projects since: ' , since printString) recordInfo.
×
1059

×
1060
        "number of projects per page"
×
1061
        amount := 100.
×
1062
        page := 0.
×
1063
        foundProject := OrderedCollection new.
×
1064
        newlyFoundProjects := { true }.
×
1065
        [ newlyFoundProjects isNotEmpty ] whileTrue: [
×
1066
                | results |
×
1067
                page := page + 1.
×
1068
                ('import projects page #' , page printString) recordInfo.
×
1069

×
1070
                results := self repoApi projects: amount since: since page: page.
×
1071

×
1072
                newlyFoundProjects := self glhModel
×
1073
                                              addAll: (self parseArrayOfProject: results)
×
1074
                                              unless: self blockOnIdEquality.
×
1075
                foundProject addAll: newlyFoundProjects ].
×
1076
]
×
1077

1078
{ #category : #'import - repositories' }
1079
GitlabModelImporter >> importRepository: aGLHRepository [
1✔
1080

1✔
1081
        | resultBranches branches |
1✔
1082
        [
1✔
1083
        ('import the repository of project ' , aGLHRepository project name)
1✔
1084
                recordInfo.
1✔
1085

1✔
1086
        resultBranches := self repoApi branches getAllFromProject:
1✔
1087
                                  aGLHRepository project id.
1✔
1088

1✔
1089
        branches := (resultBranches collect: [ :branchesJson |
1✔
1090
                             self parseBranchesResult: branchesJson ]) flattened.
1✔
1091

1✔
1092
        'import the branches of project ' recordInfo.
1✔
1093

1✔
1094
        branches := aGLHRepository branches
1✔
1095
                            addAll: branches
1✔
1096
                            unless: self blockOnNameEquality.
1✔
1097
        branches := self glhModel
1✔
1098
                            addAll: branches
1✔
1099
                            unless: self blockOnNameEquality.
1✔
1100

1✔
1101

1✔
1102
        self withFiles ifTrue: [
1✔
1103
                branches do: [ :branch | self importFilesOfBranch: branch ] ] ]
1✔
1104
                on: NeoJSONParseError
1✔
1105
                do: [
1✔
1106
                self inform: aGLHRepository project name , ' has no repository' ].
1✔
1107
        
1✔
1108
        withInitialCommits ifTrue: [
1✔
1109
                aGLHRepository branches do: [ :branch |
1✔
1110
                        self importCommitsOfBranch: branch ] ]
1✔
1111
]
1✔
1112

1113
{ #category : #'import - users' }
1114
GitlabModelImporter >> importUser: aUserID [
1✔
1115

1✔
1116
        | result userResult |
1✔
1117
        (self glhModel allWithType: GLHUser)
1✔
1118
                detect: [ :user | user id = aUserID ]
1✔
1119
                ifFound: [ :user | ^ user ].
1✔
1120
        ('Import user: ' , aUserID printString) recordInfo.
1✔
1121
        
1✔
1122
        result := self repoApi users get: aUserID.
1✔
1123
        userResult := self parseUserResult: result.
1✔
1124
        
1✔
1125
        userResult := self glhModel add: userResult unless: self blockOnIdEquality.
1✔
1126
        userCatalogue addUser: userResult.
1✔
1127
        ^ userResult 
1✔
1128
]
1✔
1129

1130
{ #category : #'import - users' }
1131
GitlabModelImporter >> importUserByUsername: anUsername [
1✔
1132

1✔
1133
        | dicUsername resultUser |
1✔
1134
        dicUsername := ((self glhModel allWithType: GLHUser) collect: [ :user |
1✔
1135
                                user username -> user ]) asSet asDictionary.
1✔
1136

1✔
1137
        dicUsername addAll: self userCatalogue collectUsernames.
1✔
1138

1✔
1139

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

1✔
1180
        self userCatalogue addUser: resultUser withName: anUsername.
1✔
1181

1✔
1182
        ^ resultUser
1✔
1183
]
1✔
1184

1185
{ #category : #initialization }
1186
GitlabModelImporter >> initReader [
1✔
1187

1✔
1188
        generalReader := NeoJSONReader new.
1✔
1189
        self configureReaderForCommit: generalReader.
1✔
1190
        self configureReaderForGroup: generalReader.
1✔
1191
        self configureReaderForDiffs: generalReader.
1✔
1192
        self configureReaderForMergeRequest: generalReader
1✔
1193
]
1✔
1194

1195
{ #category : #initialization }
1196
GitlabModelImporter >> initialize [
1✔
1197

1✔
1198
        super initialize.
1✔
1199
        withCommitDiffs := true.
1✔
1200
        withInitialCommits := false.
1✔
1201
        withInitialMergeRequest := false.
1✔
1202

1✔
1203
        self withCommitsSince: 1 week.
1✔
1204

1✔
1205
        self initReader
1✔
1206
]
1✔
1207

1208
{ #category : #private }
1209
GitlabModelImporter >> isServerError: aString [
1✔
1210
        ^ aString = '{"message":"500 Internal Server Error"}'
1✔
1211
]
1✔
1212

1213
{ #category : #'import - projects' }
1214
GitlabModelImporter >> loadAllProjectsFromRepositorySoftware [
×
1215
        "heavy import that load all the active project inside the model. Only import the project entities"
×
1216
        |projects|
×
1217
        
×
1218
        projects := self repoApi projects. 
×
1219
]
×
1220

1221
{ #category : #'private - parsing' }
1222
GitlabModelImporter >> newParseCommitResult: result [
×
1223

×
1224
        generalReader  on: result readStream.
×
1225

×
1226
        ^ generalReader nextAs: GLHCommit
×
1227
]
×
1228

1229
{ #category : #'private - parsing' }
1230
GitlabModelImporter >> newParseDiffResult: result [
1✔
1231

1✔
1232
        generalReader on: result readStream.
1✔
1233
        ^ generalReader nextAs: #ArrayOfDiffs
1✔
1234
]
1✔
1235

1236
{ #category : #'private - parsing' }
1237
GitlabModelImporter >> parseArrayOfProject: arrayOfProjects [
×
1238

×
1239
        | reader |
×
1240
        reader := NeoJSONReader on: arrayOfProjects readStream.
×
1241
        reader
×
1242
                for: #ArrayOfProjects
×
1243
                customDo: [ :customMappting |
×
1244
                customMappting listOfElementSchema: GLHProject ].
×
1245
        reader for: GLHProject do: [ :mapping |
×
1246
                mapping mapInstVar: #name to: #name.
×
1247
                mapping mapInstVar: #description to: #description.
×
1248
                mapping mapInstVar: #id to: #id.
×
1249
                mapping mapInstVar: #archived to: #archived.
×
1250
                mapping mapInstVar: #web_url to: #html_url.
×
1251
                mapping mapInstVar: #topics to: #topics ].
×
1252
        ^ reader nextAs: #ArrayOfProjects
×
1253
]
×
1254

1255
{ #category : #'private - parsing' }
1256
GitlabModelImporter >> parseBranchesResult: result [
1✔
1257

1✔
1258
        | reader |
1✔
1259
        reader := NeoJSONReader on: result readStream.
1✔
1260
        reader mapInstVarsFor: GLHBranch.
1✔
1261
        reader
1✔
1262
                for: #ArrayOfBranch
1✔
1263
                customDo: [ :customMappting | 
1✔
1264
                customMappting listOfElementSchema: GLHBranch ].
1✔
1265
        ^ reader nextAs: #ArrayOfBranch
1✔
1266
]
1✔
1267

1268
{ #category : #'private - parsing' }
1269
GitlabModelImporter >> parseCommitResult: result [
×
1270

×
1271
        | reader |
×
1272
        reader := NeoJSONReader on: result readStream.
×
1273

×
1274
        reader for: GLHCommit do: [ :mapping |
×
1275
                mapping mapInstVars:
×
1276
                        #( id short_id title author_name author_email committer_name
×
1277
                           committer_email message web_url ).
×
1278
                (mapping mapInstVar: #authored_date) valueSchema: DateAndTime.
×
1279
                (mapping mapInstVar: #committed_date) valueSchema: DateAndTime.
×
1280
                (mapping mapInstVar: #created_at) valueSchema: DateAndTime.
×
1281
                (mapping mapInstVar: #parent_ids) valueSchema: #ArrayOfIds.
×
1282
                mapping
×
1283
                        mapProperty: 'stats'
×
1284
                        getter: [ :el | "Not used" ]
×
1285
                        setter: [ :commit :value |
×
1286
                                commit deletions: (value at: #deletions).
×
1287
                                commit additions: (value at: #additions) ] ].
×
1288

×
1289
        reader for: DateAndTime customDo: [ :mapping |
×
1290
                mapping decoder: [ :string | DateAndTime fromString: string ] ].
×
1291

×
1292
        reader
×
1293
                for: #ArrayOfIds
×
1294
                customDo: [ :mapping | mapping decoder: [ :string | string ] ].
×
1295

×
1296

×
1297
        ^ reader nextAs: GLHCommit
×
1298
]
×
1299

1300
{ #category : #'private - parsing' }
1301
GitlabModelImporter >> parseCommitsResult: result [
1✔
1302

1✔
1303
        | reader |
1✔
1304
        reader := NeoJSONReader on: result readStream.
1✔
1305

1✔
1306
          reader for: GLHCommit do: [ :mapping |
1✔
1307
                mapping mapInstVars:
1✔
1308
                        #( id short_id title author_name author_email committer_name
1✔
1309
                           committer_email message web_url ).
1✔
1310
                (mapping mapInstVar: #authored_date) valueSchema: DateAndTime.
1✔
1311
                (mapping mapInstVar: #committed_date) valueSchema: DateAndTime.
1✔
1312
                (mapping mapInstVar: #created_at) valueSchema: DateAndTime.
1✔
1313
                (mapping mapInstVar: #parent_ids) valueSchema: #ArrayOfIds.
1✔
1314
                mapping
1✔
1315
                        mapProperty: 'stats'
1✔
1316
                        getter: [ :el | "Not used" ]
1✔
1317
                        setter: [ :commit :value |
1✔
1318
                                commit deletions: (value at: #deletions).
1✔
1319
                                commit additions: (value at: #additions) ] ].
1✔
1320

1✔
1321
        reader for: DateAndTime customDo: [ :mapping |
1✔
1322
                mapping decoder: [ :string | DateAndTime fromString: string ] ].
1✔
1323

1✔
1324
        reader
1✔
1325
                for: #ArrayOfIds
1✔
1326
                customDo: [ :mapping | mapping decoder: [ :string | string ] ].
1✔
1327
  
1✔
1328
        reader
1✔
1329
                for: #ArrayOfCommit
1✔
1330
                customDo: [ :customMappting |
1✔
1331
                customMappting listOfElementSchema: GLHCommit ].
1✔
1332

1✔
1333
        ^ reader nextAs: #ArrayOfCommit
1✔
1334
]
1✔
1335

1336
{ #category : #private }
1337
GitlabModelImporter >> parseDiffResult: result [
×
1338

×
1339
        | reader |
×
1340
        self
×
1341
                deprecated: 'Use #newParseDiffResult: instead'
×
1342
                on: '28 June 2024'
×
1343
                in:
×
1344
                'Pharo-11.0.0+build.726.sha.aece1b5473acf3830a0e082c1bc3a15d4ff3522b (64 Bit)'.
×
1345
        reader := NeoJSONReader on: result readStream.
×
1346
        reader for: GLHDiff do: [ :mapping |
×
1347
                mapping mapInstVars:
×
1348
                        #( deleted_file new_file new_path old_path renamed_file ).
×
1349
                mapping mapInstVar: #diffString to: #diff ].
×
1350

×
1351
        reader
×
1352
                for: #ArrayOfDiffs
×
1353
                customDo: [ :customMappting |
×
1354
                customMappting listOfElementSchema: GLHDiff ].
×
1355
        ^ reader nextAs: #ArrayOfDiffs
×
1356
]
×
1357

1358
{ #category : #'private - parsing' }
1359
GitlabModelImporter >> parseFileTreeResult: aResult [
×
1360

×
1361
        | reader |
×
1362
        reader := NeoJSONReader on: aResult readStream.
×
1363
        reader mapInstVarsFor: GLHApiFile.
×
1364
        reader
×
1365
                for: #ArrayOfFile
×
1366
                customDo: [ :customMappting | 
×
1367
                customMappting listOfElementSchema: GLHApiFile ].
×
1368
        ^ reader nextAs: #ArrayOfFile
×
1369
]
×
1370

1371
{ #category : #'private - parsing' }
1372
GitlabModelImporter >> parseGroupResult: aResult [
1✔
1373

1✔
1374
        | reader |
1✔
1375

1✔
1376
        reader := NeoJSONReader on: aResult readStream.
1✔
1377
        reader for: GLHGroup do: [ :mapping |
1✔
1378
                mapping mapInstVars.
1✔
1379
                (mapping mapInstVar: #projects) valueSchema: #ArrayOfProjects ].
1✔
1380
        reader mapInstVarsFor: GLHProject.
1✔
1381
        reader
1✔
1382
                for: #ArrayOfProjects
1✔
1383
                customDo: [ :customMappting |
1✔
1384
                customMappting listOfElementSchema: GLHProject ].
1✔
1385
        ^ reader nextAs: GLHGroup
1✔
1386
]
1✔
1387

1388
{ #category : #'private - parsing' }
1389
GitlabModelImporter >> parseJobsResult: result ofProject: aProject [
×
1390

×
1391
        | reader |
×
1392
        reader := NeoJSONReader on: result readStream.
×
1393
        reader for: GLHJob do: [ :mapping |
×
1394
                mapping mapInstVars: #( id allow_failure web_url name ).
×
1395

×
1396
                mapping
×
1397
                        mapProperty: #user
×
1398
                        getter: [ :object | #ignore ]
×
1399
                        setter: [ :object :value |
×
1400
                        object user: (self importUser: (value at: #id)) ].
×
1401

×
1402
                mapping
×
1403
                        mapProperty: #commit
×
1404
                        getter: [ :object | #ignore ]
×
1405
                        setter: [ :object :value |
×
1406
                                value ifNotNil: [
×
1407
                                        object commit:
×
1408
                                                (self importCommit: (value at: #id) ofProject: aProject) ] ].
×
1409

×
1410
                mapping
×
1411
                        mapProperty: #duration
×
1412
                        getter: [ :object | #ignore ]
×
1413
                        setter: [ :object :value |
×
1414
                        value ifNotNil: [ object duration: value seconds ] ] ].
×
1415

×
1416
        reader
×
1417
                for: #ArrayOfGLHJob
×
1418
                customDo: [ :customMappting |
×
1419
                customMappting listOfElementSchema: GLHJob ].
×
1420
        ^ reader nextAs: #ArrayOfGLHJob
×
1421
]
×
1422

1423
{ #category : #'private - parsing' }
1424
GitlabModelImporter >> parseMergeRequestResult: result [
1✔
1425

1✔
1426
        generalReader on: result readStream.
1✔
1427
        ^ generalReader nextAs: #ArrayOfMergeRequest
1✔
1428
]
1✔
1429

1430
{ #category : #'private - parsing' }
1431
GitlabModelImporter >> parseNoteJson: results [  
1✔
1432
    | reader |  
1✔
1433

1✔
1434
    "Créer un lecteur JSON"
1✔
1435
    reader := NeoJSONReader on: results readStream.    
1✔
1436

1✔
1437
    "Définir le mapping pour l'objet GLHNote"
1✔
1438
    reader for: GLHNote do: [ :mapping |  
1✔
1439
        mapping mapInstVars: #(id noteable_id attachment system confidential internal  
1✔
1440
                               noteable_iid resolvable imported imported_from  
1✔
1441
                               author body project_id noteable_type).  
1✔
1442

1✔
1443
        (mapping mapInstVar: #created_at) valueSchema: DateAndTime.  
1✔
1444
        (mapping mapInstVar: #updated_at) valueSchema: DateAndTime.  
1✔
1445
    ].    
1✔
1446

1✔
1447
    "Corriger la conversion des dates"
1✔
1448
    reader for: DateAndTime customDo: [ :mapping |  
1✔
1449
        mapping decoder: [ :string | DateAndTime readFrom: string readStream ] ].
1✔
1450

1✔
1451
        reader
1✔
1452
                for: #ArrayOfNote
1✔
1453
                customDo: [ :customMappting | 
1✔
1454
                customMappting listOfElementSchema: GLHNote ].
1✔
1455
         ^ reader nextAs: #ArrayOfNote
1✔
1456

1✔
1457
    "Retourner la Note"
1✔
1458
    "^ reader nextAs: GLHNote"
1✔
1459

1✔
1460

1✔
1461
]
1✔
1462

1463
{ #category : #'private - parsing' }
1464
GitlabModelImporter >> parsePipelinesResult: result [
×
1465

×
1466
        | reader |
×
1467
        
×
1468
        (result includesSubstring: '{"message":"40' )ifTrue: [ ^ {  } ].
×
1469
        
×
1470
        reader := NeoJSONReader on: result readStream.
×
1471
        reader mapInstVarsFor: GLHPipeline.
×
1472
        reader for: GLHPipeline do: [ :mapping |
×
1473
                mapping
×
1474
                        mapProperty: #created_at
×
1475
                        getter: [ :object | #ignore ]
×
1476
                        setter: [ :object :value |
×
1477
                        object runDate: (DateAndTime fromString: value) ] ].
×
1478
        reader
×
1479
                for: #ArrayOfPipelines
×
1480
                customDo: [ :customMappting |
×
1481
                customMappting listOfElementSchema: GLHPipeline ].
×
1482
        ^ reader nextAs: #ArrayOfPipelines
×
1483
]
×
1484

1485
{ #category : #'private - parsing' }
1486
GitlabModelImporter >> parseProjectResult: aResult [ 
1✔
1487
                | reader |
1✔
1488
        reader := NeoJSONReader on: aResult readStream.
1✔
1489
        reader for: GLHProject do: [ :mapping |
1✔
1490
                mapping mapInstVars. ].
1✔
1491
"        reader mapInstVarsFor: GLHProject."
1✔
1492

1✔
1493
        ^ reader nextAs: GLHProject
1✔
1494
]
1✔
1495

1✔
1496
{ #category : #'private - parsing' }
1✔
1497
GitlabModelImporter >> parseSubGroupResult: aResult [
1✔
1498

1✔
1499
        | reader |
1✔
1500
        reader := NeoJSONReader on: aResult readStream.
1✔
1501
        self configureReaderForGroup: reader.
1✔
1502
        ^ reader nextAs: #ArrayOfGroups
1✔
1503
]
1✔
1504

1✔
1505
{ #category : #'private - parsing' }
1✔
1506
GitlabModelImporter >> parseUserResult: result [
1✔
1507

1✔
1508
        | reader |
1✔
1509
        reader := NeoJSONReader on: result readStream.
1✔
1510
        reader mapInstVarsFor: GLHUser.
1✔
1511
        ^ reader nextAs: GLHUser
1✔
1512
]
1✔
1513

1✔
1514
{ #category : #'private - parsing' }
1✔
1515
GitlabModelImporter >> parseUsersResult: result [
1✔
1516

1✔
1517
        | reader |
1✔
1518
        reader := NeoJSONReader on: result readStream.
1✔
1519

1✔
1520
        reader mapInstVarsFor: GLHUser.
1✔
1521

1✔
1522
        reader
1✔
1523
                for: #ArrayOfUser
1✔
1524
                customDo: [ :customMappting |
1✔
1525
                customMappting listOfElementSchema: GLHUser ].
1✔
1526

1✔
1527
        ^ reader nextAs: #ArrayOfUser
1✔
1528
]
1✔
1529

1✔
1530
{ #category : #'imports - pipelines' }
1✔
1531
GitlabModelImporter >> pipelinesOf: aProjectID [
1✔
1532

1✔
1533
        | result |
1✔
1534
        ('Search pipelines of: ' , aProjectID printString) recordInfo.
1✔
1535
        result := self repoApi pipelines getAllInProject: aProjectID.
1✔
1536
        result isString ifTrue: [ ^ self parsePipelinesResult: result ].
1✔
1537

1✔
1538
        ^ (result collect: [ :pipelinesJson |
1✔
1539
                           self parsePipelinesResult: pipelinesJson ]) flattened
1✔
1540
]
1✔
1541

1✔
1542
{ #category : #accessing }
1✔
1543
GitlabModelImporter >> repoApi: anObject [
1✔
1544
        super repoApi: anObject.
1✔
1545
        self repoApi output: 'json'
1✔
1546
]
1✔
1547

1✔
1548
{ #category : #private }
1✔
1549
GitlabModelImporter >> selectEntityType: aType overAttribut: aSelector equalTo: value [
1✔
1550

1✔
1551
        ^ (self glhModel allWithType: aType)
1✔
1552
                select: [ :entity | (entity perform: aSelector) = value ]
1✔
1553
]
1✔
1554

1✔
1555
{ #category : #'import - groups' }
1✔
1556
GitlabModelImporter >> subGroupsOf: aGroupID [
1✔
1557

1✔
1558
        | results subgroups |
1✔
1559
        ('Search subgroup of: ' , aGroupID printString) recordInfo.
1✔
1560
        results := self repoApi groups subgroupsOf: aGroupID.
1✔
1561
        subgroups := (results collect: [ :subgroupsJson | self parseSubGroupResult: subgroupsJson ]) flattened.
1✔
1562
        
1✔
1563
        ^ subgroups
1✔
1564
]
1✔
1565

1✔
1566
{ #category : #accessing }
1✔
1567
GitlabModelImporter >> withInitialCommits: boolean [
1✔
1568
        withInitialCommits := boolean 
1✔
1569
]
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