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

moosetechnology / GitProjectHealth / 18011396276

25 Sep 2025 02:48PM UTC coverage: 77.799% (+4.5%) from 73.342%
18011396276

Pull #233

github

web-flow
Merge db91cdc35 into dd8ffa1f6
Pull Request #233: V2.0.0 : Refactoring importers

4095 of 4342 new or added lines in 42 files covered. (94.31%)

26 existing lines in 6 files now uncovered.

22407 of 28801 relevant lines covered (77.8%)

0.78 hits per line

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

63.87
/src/GitProjectHealth-Model-Importer/GitModelImporter.class.st
1
"
2
I am a superclass for Model importer.
3
I am a try of normalization for the different importer.
4

5
I also define some contract so it is easier to switch from one importer to another
6
"
7
Class {
8
        #name : #GitModelImporter,
9
        #superclass : #Object,
10
        #instVars : [
11
                'withCommitsSince',
12
                'withFiles',
13
                'glhModel',
14
                'userCatalogue',
15
                'repoApi',
16
                'withCommitDiffs',
17
                'generalReader'
18
        ],
19
        #classVars : [
20
                'currentImporter'
21
        ],
22
        #category : #'GitProjectHealth-Model-Importer'
23
}
24

25
{ #category : #bitbucket }
NEW
26
GitModelImporter class >> forBitbucketHostOn: anHostURL withToken: anApiToken [
×
NEW
27
        
×
NEW
28
        ^ self forBitbucketHostOn: anHostURL withToken: anApiToken andModel: GLHModel new. 
×
NEW
29
]
×
30

31
{ #category : #bitbucket }
NEW
32
GitModelImporter class >> forBitbucketHostOn: anHostURL withToken: anApiToken andModel: aGitModel [
×
NEW
33
        
×
NEW
34
        | bitbucketApi bitBucketImporter |
×
NEW
35
        bitbucketApi := BitbucketApi new
×
NEW
36
                host: anHostURL;
×
NEW
37
                bearerToken: anApiToken.
×
NEW
38

×
NEW
39
        bitBucketImporter := BitBucketModelImporter new
×
NEW
40
                     repoApi: bitbucketApi;
×
NEW
41
                     glhModel: aGitModel;
×
NEW
42
                     withFiles: false;
×
NEW
43
                     withCommitsSince: 3 day;
×
NEW
44
                     withCommitDiffs: false.
×
NEW
45
        ^bitBucketImporter 
×
NEW
46
]
×
47

48
{ #category : #github }
NEW
49
GitModelImporter class >> forGithubWithToken: anApiToken [
×
NEW
50
        ^ self forGithubWithToken: anApiToken andModel: GLHModel new
×
NEW
51
]
×
52

53
{ #category : #github }
NEW
54
GitModelImporter class >> forGithubWithToken: anApiToken andModel: aGitModel [
×
NEW
55

×
NEW
56
        | githubImport |
×
NEW
57
        githubImport := GithubModelImporter new
×
NEW
58
                                glhModel: aGitModel;
×
NEW
59
                                privateToken: anApiToken;
×
NEW
60
                                withCommitsSince: 3 day;
×
NEW
61
                                yourself.
×
NEW
62
        ^ githubImport
×
NEW
63
]
×
64

65
{ #category : #gitlab }
NEW
66
GitModelImporter class >> forGitlabHostOn: anHostURL withToken: anApiToken [ 
×
NEW
67
        ^ self forGitlabHostOn: anHostURL withToken: anApiToken andModel: GLHModel new. 
×
NEW
68
]
×
69

70
{ #category : #gitlab }
NEW
71
GitModelImporter class >> forGitlabHostOn: anHostURL withToken: anApiToken andModel: aGitModel [
×
NEW
72
        "use it when accessing onpremise or custom gitlab platform"
×
NEW
73
        | glphApi gitlabImporter |
×
NEW
74
        
×
NEW
75
        glphApi := GitlabApi new
×
NEW
76
    privateToken: anApiToken;
×
NEW
77
    hostUrl: anHostURL;
×
NEW
78
         output: 'json';
×
NEW
79
    yourself.
×
NEW
80

×
NEW
81
        gitlabImporter := GitlabModelImporter new
×
NEW
82
    repoApi: glphApi;
×
NEW
83
    glhModel: aGitModel;
×
NEW
84
         withFiles: false;
×
NEW
85
         withCommitsSince: 3 day;
×
NEW
86
         withCommitDiffs: false.
×
NEW
87
                
×
NEW
88
        ^ gitlabImporter 
×
NEW
89
]
×
90

91
{ #category : #gitlab }
NEW
92
GitModelImporter class >> forGitlabWithToken: anApiToken [
×
NEW
93
        ^ self forGitlabHostOn: 'https://gitlab.com/api/v4' withToken: anApiToken andModel: GLHModel new. 
×
NEW
94
]
×
95

96
{ #category : #gitlab }
NEW
97
GitModelImporter class >> forGitlabWithToken: anApiToken andModel: aGitModel [
×
NEW
98
        ^ self forGitlabHostOn: 'https://gitlab.com/api/v4' withToken: anApiToken andModel: aGitModel
×
NEW
99
]
×
100

101
{ #category : #'accessing - global variables' }
102
GitModelImporter class >> importers [
×
103
        ^ currentImporter 
×
104
]
×
105

106
{ #category : #'class initialization' }
NEW
107
GitModelImporter class >> initialize [ 
×
NEW
108
        currentImporter := Dictionary new. 
×
NEW
109
]
×
110

111
{ #category : #initialization }
112
GitModelImporter class >> reset [
×
113
        currentImporter := OrderedDictionary new.
×
114
]
×
115

116
{ #category : #initialization }
117
GitModelImporter >> beWithFiles [
×
118

×
119
        withFiles := true
×
120
]
×
121

122
{ #category : #initialization }
123
GitModelImporter >> beWithoutFiles [
×
124

×
125
        withFiles := false
×
126
]
×
127

128
{ #category : #equality }
129
GitModelImporter >> blockEqualityOn: aSymbol [
1✔
130
        ^ [ :existing :new |
1✔
131
          (existing perform: aSymbol) = (new perform: aSymbol) ]
1✔
132
]
1✔
133

134
{ #category : #equality }
135
GitModelImporter >> blockEqualityOn: aSymbol andOn: aSecondSymbol [
×
136
        ^ (self blockEqualityOn: aSymbol) and: [ self blockEqualityOn: aSecondSymbol ]
×
137
]
×
138

139
{ #category : #equality }
140
GitModelImporter >> blockForBranchEquality [
1✔
141
        ^ [ :existing :new |
1✔
142
          (existing name = new name) and: [ existing repository project id = new repository project id ] ]
1✔
143
        
1✔
144
]
1✔
145

146
{ #category : #equality }
147
GitModelImporter >> blockForDiffEquality [
1✔
148
        ^ [ :existing :new |
1✔
149
                        existing diffString size = new diffString size and: [
1✔
150
                                existing diffString = new diffString ] ]
1✔
151
]
1✔
152

153
{ #category : #equality }
154
GitModelImporter >> blockForDiffRangeEquality [
1✔
155

1✔
156
        ^ [ :existing :new |
1✔
157
          existing diff mooseID = new diff mooseID and: [
1✔
158
                  existing originalLineRange = new originalLineRange and: [
1✔
159
                          existing newLineRange = new newLineRange ] ] ]
1✔
160
]
1✔
161

162
{ #category : #equality }
163
GitModelImporter >> blockOnIdEquality [
1✔
164

1✔
165
        ^ [ :existing :new |
1✔
166
          existing id = new id ]
1✔
167
]
1✔
168

169
{ #category : #equality }
170
GitModelImporter >> blockOnNameEquality [
1✔
171

1✔
172
        ^ self blockEqualityOn: #name
1✔
173
]
1✔
174

175
{ #category : #utils }
176
GitModelImporter >> chainsCommitsFrom: commitsCollection [
1✔
177

1✔
178
        | dic |
1✔
179
        ('Chains ' , commitsCollection size printString , ' commits')
1✔
180
                recordInfo.
1✔
181

1✔
182
        dic := ((self glhModel allWithType: GLHCommit) collect: [ :commit |
1✔
183
                        commit id -> commit ]) asSet asDictionary.
1✔
184

1✔
185
        commitsCollection do: [ :commit |
1✔
186
                commit parent_ids do: [ :parentId |
1✔
187
                        dic
1✔
188
                                at: parentId
1✔
189
                                ifPresent: [ :parentCommit |
1✔
190
                                        parentCommit childCommits
1✔
191
                                                add: commit
1✔
192
                                                unless: [ :existing :new | existing id = new id ] ]
1✔
193
                                ifAbsent: [  ] ] ].
1✔
194
        ^ commitsCollection
1✔
195
]
1✔
196

197
{ #category : #'import - commits' }
198
GitModelImporter >> completeImportedCommit: aGLHCommit [ 
×
199
        
×
200
        
×
201
        ('completing commit: ' , aGLHCommit short_id printString) recordInfo.
×
202
        self importCreatorOfCommit: aGLHCommit.
×
203

×
204
        self withCommitDiffs ifTrue: [
×
205
                | diffs |
×
206
                aGLHCommit diffs ifEmpty: [
×
207
                        diffs := self importDiffOfCommit: aGLHCommit.
×
208
                        self glhModel addAll: diffs unless: self blockForDiffEquality ] ].
×
209

×
210
        ^ aGLHCommit
×
211
]
×
212

213
{ #category : #'import - projects' }
NEW
214
GitModelImporter >> completeImportedProject: aGLHProject [
×
NEW
215
]
×
216

217
{ #category : #'private - configure reader' }
218
GitModelImporter >> configureReaderForBranch: reader [
1✔
219

1✔
220
        reader mapInstVarsFor: GLHBranch.
1✔
221

1✔
222
        reader
1✔
223
                for: #ArrayOfBranch
1✔
224
                customDo: [ :customMappting |
1✔
225
                customMappting listOfElementSchema: GLHBranch ]
1✔
226
]
1✔
227

228
{ #category : #'private - configure reader' }
229
GitModelImporter >> configureReaderForCommit: reader [
1✔
230
        
1✔
231
        reader mapInstVarsFor: GLHCommit .
1✔
232
        
1✔
233
        reader
1✔
234
                for: #ArrayOfCommit
1✔
235
                customDo: [ :customMappting |
1✔
236
                customMappting listOfElementSchema: GLHCommit ]
1✔
237
]
1✔
238

239
{ #category : #'private - configure reader' }
240
GitModelImporter >> configureReaderForDiff: reader [
1✔
241

1✔
242
        reader mapInstVarsFor: GLHDiff.
1✔
243

1✔
244
        reader
1✔
245
                for: #ArrayOfDiff
1✔
246
                customDo: [ :customMappting |
1✔
247
                customMappting listOfElementSchema: GLHDiff ]
1✔
248
]
1✔
249

250
{ #category : #'private - configure reader' }
251
GitModelImporter >> configureReaderForGroup: reader [
1✔
252

1✔
253
        reader mapInstVarsFor: GLHGroup.
1✔
254

1✔
255
        reader
1✔
256
                for: #ArrayOfGroup
1✔
257
                customDo: [ :customMappting |
1✔
258
                customMappting listOfElementSchema: GLHGroup ]
1✔
259
]
1✔
260

261
{ #category : #'private - configure reader' }
NEW
262
GitModelImporter >> configureReaderForIssue: reader [
×
NEW
263

×
NEW
264
        reader mapInstVarsFor: GLHIssue.
×
NEW
265

×
NEW
266
        reader
×
NEW
267
                for: #ArrayOfIssue
×
NEW
268
                customDo: [ :customMappting |
×
NEW
269
                customMappting listOfElementSchema: GLHIssue ]
×
NEW
270
]
×
271

272
{ #category : #'private - configure reader' }
273
GitModelImporter >> configureReaderForJob: reader [
1✔
274

1✔
275
        reader mapInstVarsFor: GLHJob .
1✔
276

1✔
277
        reader for: #ArrayOfJob customDo: [ :customMappting |
1✔
278
                customMappting listOfElementSchema: GLHJob ]
1✔
279
]
1✔
280

281
{ #category : #'private - configure reader' }
282
GitModelImporter >> configureReaderForMergeRequest: reader [
1✔
283

1✔
284
        reader mapInstVarsFor: GLHMergeRequest.
1✔
285

1✔
286
        reader for: #ArrayOfMergeRequest customDo: [ :customMappting |
1✔
287
                customMappting listOfElementSchema: GLHMergeRequest ]
1✔
288
]
1✔
289

290
{ #category : #'private - configure reader' }
NEW
291
GitModelImporter >> configureReaderForMilestone: reader [
×
NEW
292

×
NEW
293
        reader mapInstVarsFor: GLHMilestone.
×
NEW
294

×
NEW
295
        reader
×
NEW
296
                for: #ArrayOfMilestone
×
NEW
297
                customDo: [ :customMappting |
×
NEW
298
                customMappting listOfElementSchema: GLHMilestone ]
×
NEW
299
]
×
300

301
{ #category : #'private - configure reader' }
302
GitModelImporter >> configureReaderForNote: reader [
1✔
303

1✔
304
        reader mapInstVarsFor: GLHNote .
1✔
305

1✔
306
        reader
1✔
307
                for: #ArrayOfNote
1✔
308
                customDo: [ :customMappting |
1✔
309
                customMappting listOfElementSchema: GLHNote ]
1✔
310
]
1✔
311

312
{ #category : #'private - configure reader' }
313
GitModelImporter >> configureReaderForPipeline: reader [
1✔
314

1✔
315
        reader mapInstVarsFor: GLHPipeline.
1✔
316

1✔
317
        reader
1✔
318
                for: #ArrayOfPipeline
1✔
319
                customDo: [ :customMappting |
1✔
320
                customMappting listOfElementSchema: GLHPipeline ]
1✔
321
]
1✔
322

323
{ #category : #'private - configure reader' }
324
GitModelImporter >> configureReaderForProject: reader [
1✔
325

1✔
326
        reader mapInstVarsFor: GLHProject.
1✔
327

1✔
328
        reader
1✔
329
                for: #ArrayOfProject
1✔
330
                customDo: [ :customMappting |
1✔
331
                customMappting listOfElementSchema: GLHProject ]
1✔
332
]
1✔
333

334
{ #category : #'private - configure reader' }
335
GitModelImporter >> configureReaderForRelease: reader [
1✔
336

1✔
337
        reader mapInstVarsFor: GLHRelease.
1✔
338

1✔
339
        reader
1✔
340
                for: #ArrayOfRelease
1✔
341
                customDo: [ :customMappting |
1✔
342
                customMappting listOfElementSchema: GLHRelease ]
1✔
343
]
1✔
344

345
{ #category : #'private - configure reader' }
NEW
346
GitModelImporter >> configureReaderForTag: reader [
×
NEW
347

×
NEW
348
        reader mapInstVarsFor: GLHTag.
×
NEW
349

×
NEW
350
        reader
×
NEW
351
                for: #ArrayOfTag
×
NEW
352
                customDo: [ :customMappting |
×
NEW
353
                customMappting listOfElementSchema: GLHTag ]
×
NEW
354
]
×
355

356
{ #category : #'private - configure reader' }
357
GitModelImporter >> configureReaderForUser: reader [
1✔
358

1✔
359
        reader mapInstVarsFor: GLHUser.
1✔
360

1✔
361
        reader
1✔
362
                for: #ArrayOfUser
1✔
363
                customDo: [ :customMappting |
1✔
364
                customMappting listOfElementSchema: GLHUser ].
1✔
365
        
1✔
366
]
1✔
367

368
{ #category : #utils }
369
GitModelImporter >> filterCommitChanges: aCollection [
1✔
370

1✔
371
        ^ aCollection reject: [ :line |
1✔
372
                  | trimmedLine |
1✔
373
                  trimmedLine := line trimLeft.
1✔
374
                  (trimmedLine beginsWith: '---') or: [
1✔
375
                          (trimmedLine beginsWith: '+++') or: [
1✔
376
                                  trimmedLine beginsWith: '\ No newline at end of file' ] ] ]
1✔
377
]
1✔
378

379
{ #category : #accessing }
380
GitModelImporter >> glhModel [
1✔
381

1✔
382
        ^ glhModel
1✔
383
]
1✔
384

385
{ #category : #accessing }
386
GitModelImporter >> glhModel: anObject [
1✔
387

1✔
388
        glhModel := anObject
1✔
389
]
1✔
390

391
{ #category : #'import - commits' }
392
GitModelImporter >> importAndLoadLatestsCommitsOfProject: aGLHProject [
393

394
        self subclassResponsibility 
395
]
396

397
{ #category : #'import - users' }
NEW
398
GitModelImporter >> importAuthorOfCommit: aGLHCommit [
×
NEW
399

×
NEW
400
        self
×
NEW
401
                deprecated: 'Use importCreatorOfCommit: instead of current one'
×
NEW
402
                on: '19 September 2025'
×
NEW
403
                in:
×
NEW
404
                'Pharo-12.0.0+SNAPSHOT.build.1571.sha.cf5fcd22e66957962c97dffc58b0393b7f368147 (64 Bit)'.
×
NEW
405

×
NEW
406
        self subclassResponsibility
×
NEW
407
]
×
408

409
{ #category : #'import - repositories' }
410
GitModelImporter >> importBranchesOf: aGLHProject [
411

412
        ^ self subclassResponsibility
413
]
414

415
{ #category : #'import - commits' }
416
GitModelImporter >> importCommit: aCommitID ofProject: aGLHProject [
417

418
        self subclassResponsibility 
419
]
420

421
{ #category : #'import - commits' }
422
GitModelImporter >> importCommitsOfBranch: aGLHBranch [
423
        self subclassResponsibility 
424
        
425
        
426
]
427

428
{ #category : #'import - commits' }
429
GitModelImporter >> importCommitsOfProject: aGLHProject since: since until: until [
430

431
        self subclassResponsibility 
432
]
433

434
{ #category : #'import - projects' }
NEW
435
GitModelImporter >> importContributedProjectsOfUser: aGLHUser [
×
NEW
436
]
×
437

438
{ #category : #'import - users' }
439
GitModelImporter >> importCreatorOfCommit: aGLHCommit [
1✔
440

1✔
441
        
1✔
442
        aGLHCommit commitCreator ifNil: [
1✔
443
                aGLHCommit commitCreator:
1✔
444
                        (self importUserByUsername: aGLHCommit author_name) ].
1✔
445
        self userCatalogue
1✔
446
                addUser: aGLHCommit commitCreator
1✔
447
                withProject: aGLHCommit repository project id.
1✔
448
        ^ aGLHCommit commitCreator
1✔
449
]
1✔
450

451
{ #category : #'import - diffs' }
452
GitModelImporter >> importDiffOfCommit: aCommit [
453

454
        self subclassResponsibility 
455
]
456

457
{ #category : #'import - diffs' }
458
GitModelImporter >> importDiffRangesForDiff: aGLHDiff [
1✔
459

1✔
460
        | diffRanges |
1✔
461
        aGLHDiff diffRanges ifNotEmpty: [
1✔
462
                ('Diffs already imported for ' , aGLHDiff printString) recordInfo.
1✔
463
                ^ aGLHDiff diffRanges ].
1✔
464

1✔
465
        ('Import changes of diff ' , aGLHDiff printString) recordInfo.
1✔
466
        "the import of 'diffRanges' entites is technically done inside the parseDiffString"
1✔
467

1✔
468
        diffRanges := self glhModel
1✔
469
                              addAll: (self parseDiffString: aGLHDiff)
1✔
470
                              unless: self blockForDiffRangeEquality.
1✔
471
        ^ aGLHDiff diffRanges
1✔
472
                  addAll: diffRanges
1✔
473
                  unless: self blockForDiffRangeEquality
1✔
474
]
1✔
475

476
{ #category : #'import - groups' }
477
GitModelImporter >> importGroup: aGroupID [
478

479
        self subclassResponsibility
480
]
481

482
{ #category : #'import - issues' }
483
GitModelImporter >> importIssuesOfProject: aGLHProject [
484
        self subclassResponsibility 
485
]
486

487
{ #category : #'import - jobs' }
488
GitModelImporter >> importJobsOf: aGLHPipeline [
489
        self subclassResponsibility 
490
]
491

492
{ #category : #'import - commits' }
493
GitModelImporter >> importLatestCommitsOfProject: aGLHProject [
494
        "limited to the last 50 commits"
495

496
        self subclassResponsibility 
497
]
498

499
{ #category : #'import - merge-requests' }
500
GitModelImporter >> importLatestMergeRequestsOfProject: aGLHProject [
501
        self subclassResponsibility 
502
]
503

504
{ #category : #'import - pipelines' }
505
GitModelImporter >> importLatestPipelinesOfProject: aGLHProject [
506
        self subclassResponsibility 
507
        
508
]
509

510
{ #category : #'import - releases' }
511
GitModelImporter >> importLatestReleaseOfProject: aGLHProject [
512
        ^ self subclassResponsibility 
513
]
514

515
{ #category : #'import - merge-requests' }
NEW
516
GitModelImporter >> importMergeRequestCommits: mergeRequest [
×
NEW
517
]
×
518

519
{ #category : #'import - merge-requests' }
520
GitModelImporter >> importMergeRequestMergeCommits: aGLHMergeRequest [
521

522
        self subclassResponsibility 
523
]
524

525
{ #category : #'import - merge-requests' }
526
GitModelImporter >> importMergeRequestsOfProject: aGLHProject [
527

528
        self subclassResponsibility 
529
]
530

531
{ #category : #'import - merge-requests' }
532
GitModelImporter >> importMergeRequestsOfProject: aGLHProject since: fromDate until: toDate [
533
        self subclassResponsibility 
534
]
535

536
{ #category : #'import - merge-requests' }
NEW
537
GitModelImporter >> importMergeResquestAuthor: mergeRequest [
×
NEW
538
]
×
539

540
{ #category : #'import - merge-requests' }
NEW
541
GitModelImporter >> importMergeResquestMerger: mergeRequest [
×
NEW
542
]
×
543

544
{ #category : #'import - milestones' }
545
GitModelImporter >> importMilestonesOfProject: aGLHProject [
546
        self subclassResponsibility 
547
]
548

549
{ #category : #'import - notes' }
550
GitModelImporter >> importNotesOfMergeRequest: mergeRequest [
551

552
        self subclassResponsibility
553
]
554

555
{ #category : #'import - pipelines' }
556
GitModelImporter >> importPipeline: aPipelineId OfProject: aGLHProject [
557

558
        self subclassResponsibility 
559
]
560

561
{ #category : #'import - merge-requests' }
562
GitModelImporter >> importPipelinesOfProject: aGLHProject [
563
        ^ self subclassResponsibility 
564
]
565

566
{ #category : #'import - projects' }
567
GitModelImporter >> importProject: id [
568
        "id can be a string or an integer depending on the APi implementation"
569

570
        "return the project created or retrieved"
571

572
        ^ self subclassResponsibility
573
]
574

575
{ #category : #'import - projects' }
NEW
576
GitModelImporter >> importProject: aProjectID ofGroup: aGroup [
×
NEW
577
]
×
578

579
{ #category : #'import - projects' }
580
GitModelImporter >> importProjects: aCollectionOfProjectID [
×
581

×
582

×
583
        ^ aCollectionOfProjectID collect: [ :id | self importProject: id ]
×
584
]
×
585

586
{ #category : #'import - projects' }
587
GitModelImporter >> importProjectsOfUser: aGLHUser [
588
        "https://docs.github.com/fr/rest/repos/repos?apiVersion=2022-11-28#list-repositories-for-a-user"
589
        
590
        self subclassResponsibility 
591
]
592

593
{ #category : #'import - commits' }
NEW
594
GitModelImporter >> importRefCommitOfBranch: aGLHBranch [
×
NEW
595
        |commit|
×
NEW
596
        commit := self
×
NEW
597
                                 importCommit: aGLHBranch sha
×
NEW
598
                                 ofProject: aGLHBranch repository project.
×
NEW
599
        commit := aGLHBranch commits
×
NEW
600
                add: commit
×
NEW
601
                unless: self blockOnIdEquality.
×
NEW
602
        ^ commit
×
NEW
603
]
×
604

605
{ #category : #'import - releases' }
606
GitModelImporter >> importRelease: aReleaseID ofProject: aGLHProject [
607
        self subclassResponsibility 
608
]
609

610
{ #category : #'import - tags' }
611
GitModelImporter >> importTagsForProject: aGLHProject [
612
        self subclassResponsibility 
613
]
614

615
{ #category : #'import - users' }
616
GitModelImporter >> importUser: aUserID [
617
        self subclassResponsibility 
618
]
619

620
{ #category : #'import - users' }
621
GitModelImporter >> importUserByUsername: username [
622

623
        self subclassResponsibility 
624
]
625

626
{ #category : #'private - configure reader' }
627
GitModelImporter >> initReader [
1✔
628

1✔
629
        | configurators |
1✔
630
        generalReader := NeoJSONReader new.
1✔
631

1✔
632
        "will be reuse for all reader next"
1✔
633
        "indique ce que doit faire le reader lorsqu'il parse une DateAndTime object"
1✔
634
        generalReader for: DateAndTime customDo: [ :mapping |
1✔
635
                mapping decoder: [ :string |
1✔
636
                        string ifNil: [ nil ] ifNotNil: [ DateAndTime fromString: string ] ] ].
1✔
637

1✔
638
        configurators := self class selectors select: [ :m |
1✔
639
                                 m beginsWith: #configureReaderFor ].
1✔
640

1✔
641
        configurators do: [ :configureReader |
1✔
642
                self perform: configureReader with: generalReader ]
1✔
643
]
1✔
644

645
{ #category : #initialization }
646
GitModelImporter >> initialize [
1✔
647

1✔
648
        super initialize.
1✔
649
        self withFiles: false. 
1✔
650
        self withCommitsSince: (Date today - 1 week) asDateAndTime.
1✔
651
        userCatalogue := GLHUserCatalogueV2 new
1✔
652
                                 anImporter: self;
1✔
653
                                 yourself.
1✔
654

1✔
655
        self initReader
1✔
656
]
1✔
657

658
{ #category : #initialization }
659
GitModelImporter >> makeGlobal [
×
660
        ^ self makeGlobal: DateAndTime now printString.
×
661
]
×
662

663
{ #category : #initialization }
664
GitModelImporter >> makeGlobal: aLabel [ 
×
665

×
666
        currentImporter := GithubModelImporter importers ifNil: [ OrderedDictionary new ].
×
667
        currentImporter at: aLabel put: self. 
×
668
        ^ currentImporter 
×
669
]
×
670

671
{ #category : #parsing }
672
GitModelImporter >> parseDiffString: aDiff [
1✔
673
        "parse diff string to create entities for each lines"
1✔
674

1✔
675
        | lines range index firstChangeRange |
1✔
676
        lines := aDiff diffString lines.
1✔
677
        index := 0.
1✔
678
        range := nil.
1✔
679

1✔
680
        lines ifEmpty: [ ^ aDiff diffRanges ].
1✔
681
        lines := self filterCommitChanges: lines.
1✔
682
        lines ifEmpty: [ ^ aDiff diffRanges ].
1✔
683
        (lines first beginsWith: '@@') ifFalse: [ ^ aDiff diffRanges ].
1✔
684

1✔
685
        lines do: [ :line |
1✔
686
                | aChange |
1✔
687
                firstChangeRange := false.
1✔
688
                (line trim beginsWith: #'@@') ifTrue: [
1✔
689
                        range := GLHDiffRange newFrom: line.
1✔
690
                        firstChangeRange := true.
1✔
691
                        range := aDiff diffRanges add: range unless: [ :existing :new |
1✔
692
                                         existing originalLineRange = new originalLineRange and: [
1✔
693
                                                 existing newLineRange = new newLineRange ] ] ].
1✔
694

1✔
695
                self withCommitDiffs ifTrue: [
1✔
696
                        firstChangeRange ifFalse: [
1✔
697
                                aChange := GLHChange newFrom: line.
1✔
698
                                aChange relativeIndex: index.
1✔
699
                                aChange := range changes add: aChange unless: [ :existing :new |
1✔
700
                                                   existing sourceCode = new sourceCode and: [
1✔
701
                                                           existing index = new index ] ].
1✔
702
                                index := index + 1 ] ] ].
1✔
703

1✔
704
        "add changes to the diff range"
1✔
705
        aDiff diffRanges do: [ :diffRange |
1✔
706
                self glhModel addAll: diffRange changes unless: [ :existing :new |
1✔
707
                        existing diffRange mooseID = new diffRange mooseID and: [
1✔
708
                                existing sourceCode = new sourceCode and: [
1✔
709
                                        existing index = new index ] ] ] ].
1✔
710

1✔
711
        ^ aDiff diffRanges
1✔
712
]
1✔
713

714
{ #category : #accessing }
715
GitModelImporter >> repoApi [
1✔
716

1✔
717
        ^ repoApi
1✔
718
]
1✔
719

720
{ #category : #accessing }
721
GitModelImporter >> repoApi: anObject [
1✔
722

1✔
723
        repoApi := anObject
1✔
724
]
1✔
725

726
{ #category : #accessing }
727
GitModelImporter >> userCatalogue [
1✔
728
        ^ userCatalogue 
1✔
729
]
1✔
730

731
{ #category : #accessing }
732
GitModelImporter >> userCatalogue: aGLHUserCatalogue [
×
733

×
734
        userCatalogue := aGLHUserCatalogue.
×
735
        aGLHUserCatalogue anImporter: self. 
×
736
]
×
737

738
{ #category : #accessing }
739
GitModelImporter >> withCommitDiffs [
1✔
740

1✔
741
        ^ withCommitDiffs
1✔
742
]
1✔
743

744
{ #category : #accessing }
745
GitModelImporter >> withCommitDiffs: anObject [
1✔
746

1✔
747
        withCommitDiffs := anObject
1✔
748
]
1✔
749

750
{ #category : #accessing }
751
GitModelImporter >> withCommitsSince [
1✔
752

1✔
753
        ^ withCommitsSince
1✔
754
]
1✔
755

756
{ #category : #accessing }
757
GitModelImporter >> withCommitsSince: someDays [
1✔
758
        "substract the current date with a given number of days. Use to retrieve the commits submit in the last giving days"
1✔
759

1✔
760
        "(GitlabModelImporter new withCommitsSince: 1 week ) >>> (Date today - 1 week) asDateAndTime"
1✔
761

1✔
762
        "(GitlabModelImporter new withCommitsSince: 30 day ) >>> (Date today - 30 day) asDateAndTime"
1✔
763

1✔
764
        (someDays isKindOf: DateAndTime)
1✔
765
                ifTrue: [ withCommitsSince := someDays ]
1✔
766
                ifFalse: [
1✔
767
                withCommitsSince := (DateAndTime today - someDays) ].
1✔
768
        ^ withCommitsSince
1✔
769
]
1✔
770

771
{ #category : #accessing }
772
GitModelImporter >> withFiles [
1✔
773

1✔
774
        ^ withFiles
1✔
775
]
1✔
776

777
{ #category : #accessing }
778
GitModelImporter >> withFiles: anObject [
1✔
779

1✔
780
        withFiles := anObject
1✔
781
]
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