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

moosetechnology / GitProjectHealth / 28085682787

24 Jun 2026 08:30AM UTC coverage: 77.78% (+0.02%) from 77.762%
28085682787

push

github

web-flow
Merge pull request #262 from moosetechnology/develop

Moose 13

199 of 228 new or added lines in 62 files covered. (87.28%)

23835 of 30644 relevant lines covered (77.78%)

0.78 hits per line

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

93.06
/src/GitLabHealth-Model-Analysis/GitAnalyzer.class.st
1
Class {
2
        #name : #GitAnalyzer,
3
        #superclass : #Object,
4
        #instVars : [
5
                'glModel',
6
                'fromCommit',
7
                'glhImporter',
8
                'onProject',
9
                'maxChildCommits'
10
        ],
11
        #category : #'GitLabHealth-Model-Analysis'
12
}
13

14
{ #category : #analyze }
15
GitAnalyzer >> analyseChurn [
1✔
16

1✔
17
        | commitFiles totalContribution childCommits access |
1✔
18
        access := ('' join: {
1✔
19
                                   'churn'.
1✔
20
                                   maxChildCommits }) asSymbol.
1✔
21

1✔
22
        ^ fromCommit cacheAt: access ifAbsentPut: [
1✔
23
                  ('GitAnalyzer, analyse chrun onProject: ' , onProject printString)
1✔
24
                          recordInfo.
1✔
25
                  childCommits := Set new.
1✔
26
                  totalContribution := self
1✔
27
                                               visitChildCommits: fromCommit childCommits
1✔
28
                                               toStoreThemIn: childCommits
1✔
29
                                               upto: self maxChildCommits.
1✔
30
                  totalContribution add: fromCommit. 
1✔
31
                  totalContribution := totalContribution sum: [ :commit | "nil if merge request commit"
1✔
32
                                               commit additions ifNil: [ 0 ] ].
1✔
33
                  commitFiles := self
1✔
34
                                         impactedFilesInFollowUpCommitsOf: fromCommit
1✔
35
                                         withMaxCommits: self maxChildCommits.
1✔
36
                        "a churned line is a line added on top of an already added line"
1✔
37
                  (self computeChurnOnFiles: commitFiles)
1✔
38
                          at: #totalContribution ifAbsentPut: totalContribution;
1✔
39
                          yourself ]
1✔
40
]
1✔
41

42
{ #category : #analyze }
43
GitAnalyzer >> analyseCommentContribution [
1✔
44

1✔
45
        | numberOfComments |
1✔
46
        ('GitAnalyzer, analyse comment contributions onProject: '
1✔
47
         , onProject printString) recordInfo.
1✔
48
        numberOfComments := 0.
1✔
49
        
1✔
50
        fromCommit diffs do: [ :diff |
1✔
51
                diff diffRanges do: [ :range |
1✔
52
                        range changes do: [ :change |
1✔
53
                                ((change isKindOf: GLHAddition) and: [
1✔
54
                                         (change sourceCode withoutPrefix: '+') trimLeft
1✔
55
                                                 beginsWithAnyOf: { '#'. '//'. '/*'. '*'. '*/' } ]) ifTrue: [
1✔
56
                                        numberOfComments := numberOfComments + 1 ] ] ] ].
1✔
57
        ^ numberOfComments
1✔
58
]
1✔
59

60
{ #category : #commit }
61
GitAnalyzer >> analyseCommitContribution [
1✔
62
        
1✔
63
        
1✔
64
        ('GitAnalyzer, analyse commit contribution of: ', fromCommit printString )
1✔
65
                recordInfo.
1✔
66
        
1✔
67
        ^ { (#addition -> fromCommit additions).
1✔
68
          (#deletion -> fromCommit deletions). } asDictionary 
1✔
69
]
1✔
70

71
{ #category : #analyze }
72
GitAnalyzer >> analyseCommitFrequencyFromCommits: initialCommits [
×
73

×
74
        | commits response |
×
75
        ('GitAnalyzer, analyse commit Frequency on: ' , onProject printString)
×
76
                recordInfo.
×
77

×
78
        response := {
×
79
                            (#numberOfCommit -> nil).
×
80
                            (#frequency -> nil) } asDictionary.
×
81

×
82

×
83
        commits := self arrangeCommitsByDate: initialCommits.
×
84
        commits := (commits associations sortAscending: [ :entry |
×
NEW
85
                            entry key ]) asOrderedDictionary.
×
86

×
87
        ^ commits
×
88
]
×
89

90
{ #category : #analyze }
91
GitAnalyzer >> analyseCommitFrequencySince: since until: until [
1✔
92

1✔
93
        | commits response |
1✔
94
        ('GitAnalyzer, analyse commit Frequency on: ' , onProject printString)
1✔
95
                recordInfo.
1✔
96

1✔
97
        response := {
1✔
98
                            (#numberOfCommit -> nil).
1✔
99
                            (#frequency -> nil) } asDictionary.
1✔
100

1✔
101
        commits := glhImporter
1✔
102
                           importCommitsOfProject: onProject
1✔
103
                           since: since
1✔
104
                           until: until.
1✔
105

1✔
106
        commits := self arrangeCommitsByDate: commits.
1✔
107
        commits := (commits associations sortAscending: [ :entry | entry key ])
1✔
108
                           asOrderedDictionary.
1✔
109

1✔
110
        ^ commits
1✔
111
]
1✔
112

113
{ #category : #analyze }
114
GitAnalyzer >> analyseDelayUntilFirstChurn [
1✔
115
        "return the first commit that modify the same lines of code as the fromCommit"
1✔
116

1✔
117
        | churn res access|
1✔
118
        
1✔
119
        access := ('' join: {
1✔
120
                                   'amandment'.
1✔
121
                                   maxChildCommits }) asSymbol.
1✔
122
        
1✔
123
        ^ fromCommit cacheAt: access ifPresent: [ :v | v ] ifAbsentPut: [
1✔
124
        
1✔
125
        ('GitAnalyzer, analyse amandment onProject: ', onProject printString )
1✔
126
                recordInfo.
1✔
127
        
1✔
128
        churn := self analyseChurn.
1✔
129

1✔
130
        res := self firstAmandmentFromChrun: churn.
1✔
131
         res]
1✔
132
]
1✔
133

134
{ #category : #analyze }
135
GitAnalyzer >> analyseMergeResquestValidation: aGLHPMergeRequest [
1✔
136

1✔
137
        | creationDate mergedDate closedDate currentDate  response |
1✔
138
        ('GitAnalyzer, analyse merge request delay of: '
1✔
139
         , aGLHPMergeRequest printString) recordInfo.
1✔
140

1✔
141
        ^ aGLHPMergeRequest 
1✔
142
                  cacheAt: #mergeRequestValidation
1✔
143
                  ifPresent: [ :v | v ]
1✔
144
                  ifAbsentPut: [
1✔
145
                          response := {
1✔
146
                                              (#id_merge_resquest -> aGLHPMergeRequest iid).
1✔
147
                                              (#id_merge_commit -> nil).
1✔
148
                                              (#created_at -> aGLHPMergeRequest created_at).
1✔
149
                                              (#open_duration -> nil).
1✔
150
                                
1✔
151
                                              (#merged_at -> nil).
1✔
152
                                              (#duration -> nil).
1✔
153
                                
1✔
154
                                              (#closed_at -> nil).
1✔
155
                                              (#close_duration -> nil).
1✔
156
                                              
1✔
157
                                              (#status -> aGLHPMergeRequest merge_status) }
1✔
158
                                              asDictionary.
1✔
159

1✔
160
                          creationDate := aGLHPMergeRequest created_at asDateAndTime.
1✔
161
            currentDate := DateAndTime now.  "Get the current timestamp"
1✔
162
            "Handle merged case"
1✔
163
            mergedDate := aGLHPMergeRequest merged_at ifNil: [ nil ].
1✔
164
            mergedDate ifNotNil: [
1✔
165
                response  
1✔
166
                    at: #duration put: mergedDate - creationDate;  
1✔
167
                    at: #id_merge_commit put: aGLHPMergeRequest merge_commit_sha;  
1✔
168
                    at: #merged_at put: aGLHPMergeRequest merged_at.  
1✔
169
            ].
1✔
170

1✔
171
           "Handle closed case"
1✔
172
            closedDate := aGLHPMergeRequest closed_at ifNil: [ nil ].
1✔
173
            closedDate ifNotNil: [
1✔
174
                response  
1✔
175
                    at: #close_duration put: closedDate - creationDate;  
1✔
176
                    at: #closed_at put: aGLHPMergeRequest closed_at.
1✔
177
            ].
1✔
178

1✔
179
            "Handle open case (niether merged nor closed)"
1✔
180
            (mergedDate isNil and: closedDate isNil) ifTrue: [
1✔
181
                response at: #open_duration put: currentDate - creationDate.
1✔
182
            ].
1✔
183

1✔
184
            response
1✔
185
        ].
1✔
186
]
1✔
187

188
{ #category : #filter }
189
GitAnalyzer >> arrangeCommitsByDate: commits [
1✔
190

1✔
191
        | date2commits |
1✔
192
        date2commits := Dictionary new.
1✔
193

1✔
194
        commits do: [ :commit |
1✔
195
                | date |
1✔
196
                date := commit created_at asDate.
1✔
197
                date2commits
1✔
198
                        at: date
1✔
199
                        ifPresent: [ :v | v add: commit ]
1✔
200
                        ifAbsentPut: [
1✔
201
                                OrderedCollection new
1✔
202
                                        add: commit;
1✔
203
                                        yourself ] ].
1✔
204
        ^ date2commits
1✔
205
]
1✔
206

207
{ #category : #churn }
208
GitAnalyzer >> computeChurnOnFiles: aCollection [
1✔
209

1✔
210
        | changesDic perFileChanges churns initialAuthor followingAuthors|
1✔
211
        "1 -> (a GLPHEChange -> NumberOfChurnDetected)"
1✔
212
        changesDic := Dictionary new.
1✔
213
        initialAuthor := fromCommit commitCreator. 
1✔
214
        
1✔
215

1✔
216
        perFileChanges := aCollection associations collect: [ :assoc |
1✔
217
                                  assoc key
1✔
218
                                  -> (self computeSpecificChurnOf: assoc value) ].
1✔
219

1✔
220

1✔
221
        churns := perFileChanges collect: [ :assoc |
1✔
222
                          | churnData file aLineOfChanges |
1✔
223
                          file := assoc key.
1✔
224
                          aLineOfChanges := assoc value.
1✔
225
                          churnData := aLineOfChanges values ifEmpty: [  nil ] ifNotEmpty: [
1✔
226
                                  | churnedContribution churnSpecificFromCommit churnOfAuthorOnly |
1✔
227
                                
1✔
228
                                  "the total churn on any LoC affected"
1✔
229
                                  churnedContribution := aLineOfChanges select: [ :a |
1✔
230
                                                                 a value  > 1 ].
1✔
231

1✔
232
                                  "the churn that coccurs specifically on the loc introduced by the initial commit"
1✔
233
                                  churnSpecificFromCommit := churnedContribution select: [ :a |
1✔
234
                                                                     (a key collect: [ :loc |
1✔
235
                                                                              loc diffRange diff commit ])
1✔
236
                                                                             includes: fromCommit ].
1✔
237

1✔
238
                                                "the churn made the author of the initial commits "
1✔
239
                                  churnOfAuthorOnly := churnSpecificFromCommit select: [ :a |
1✔
240
                                                                     (((a key collect: [ :loc |
1✔
241
                                                                              loc diffRange diff commit commitCreator ]) asSet) difference: {initialAuthor} asSet ) isEmpty
1✔
242
                                                                             ].
1✔
243
                                                
1✔
244

1✔
245
                                  {
1✔
246
                                                   (#churnFromInitialCommitLines
1✔
247
                                                    ->
1✔
248
                                                            ((churnSpecificFromCommit sum: #value) - churnSpecificFromCommit size)).
1✔
249
                                                                                (#churnFromCommitCreatorOnly
1✔
250
                                                    ->
1✔
251
                                                            ((churnOfAuthorOnly sum: #value) - churnOfAuthorOnly size)).
1✔
252
                                                   (#churnLoC
1✔
253
                                                    ->
1✔
254
                                                            ((churnedContribution sum: #value)
1✔
255
                                                             - churnedContribution size)) 
1✔
256
                                        } asDictionary ].
1✔
257

1✔
258
                          file -> churnData ].
1✔
259
        churns := churns reject: [ :file2churn | file2churn value isNil ].
1✔
260

1✔
261
        ^ {
1✔
262
                  (#churns -> churns).
1✔
263
                  (#details -> perFileChanges) } asDictionary
1✔
264
]
1✔
265

266
{ #category : #churn }
267
GitAnalyzer >> computeSpecificChurnOf: commit2Changes [
1✔
268

1✔
269
        | changesDic |
1✔
270
        "1 -> (a GLPHEChange -> NumberOfChurnDetected)"
1✔
271
        changesDic := OrderedDictionary new.
1✔
272

1✔
273

1✔
274
        (commit2Changes sortAscending: [ :assoc | assoc key created_at ])
1✔
275
                do: [ :entry |
1✔
276
                        | commit diffRanges |
1✔
277
                        commit := entry key.
1✔
278
                        diffRanges := entry value.
1✔
279

1✔
280
                        diffRanges do: [ :diff |
1✔
281
                                | from |
1✔
282
                                from := (diff originalLineRange
1✔
283
                                                 copyFrom: (diff originalLineRange indexOf: $-) + 1
1✔
284
                                                 to: (diff originalLineRange
1✔
285
                                                                  indexOf: $,
1✔
286
                                                                  ifAbsent: [ diff originalLineRange size + 1 ]) - 1)
1✔
287
                                                asString asNumber.
1✔
288
                                from = 0 ifTrue: [ from := 1 ].
1✔
289
                                self insertDiff: diff into: changesDic startingFrom: from ] ].
1✔
290

1✔
291

1✔
292

1✔
293
        ^ self sortChangeDic: changesDic
1✔
294
]
1✔
295

296
{ #category : #accessing }
297
GitAnalyzer >> firstAmandmentFromChrun: aChurnAnalysis [ 
1✔
298
        |details whereChangesOccurs firstCommitsPerFile|
1✔
299
        
1✔
300
        whereChangesOccurs := (aChurnAnalysis at: #churns ) select: [ :file | (file value at: #churnLoC) > 0 ].
1✔
301
        
1✔
302
        details := whereChangesOccurs collect: [ :file |
1✔
303
                ((aChurnAnalysis at: #details) detect: [ :entry | entry key = file key] )
1✔
304
                 ].
1✔
305
        
1✔
306
        firstCommitsPerFile := details collect: [ :perFile |
1✔
307
                |changes firstCommits first|
1✔
308
                changes := perFile value.
1✔
309
                changes := changes select: [ :line2changes | line2changes value value > 1  ].
1✔
310
                firstCommits := (changes collect: [ :line2changes |  line2changes key second diffRange diff commit ]) values. 
1✔
311
                first := (firstCommits sortAscending: [:c | c created_at ]) first.
1✔
312
                 ].
1✔
313
        
1✔
314

1✔
315
        ^ (firstCommitsPerFile sortAscending: [:c | c created_at ]) ifEmpty: nil ifNotEmpty: [ :v | v first ]  . 
1✔
316

1✔
317
]
1✔
318

319
{ #category : #accessing }
320
GitAnalyzer >> fromCommit: aCommit [
1✔
321
        fromCommit := aCommit. 
1✔
322
]
1✔
323

324
{ #category : #accessing }
325
GitAnalyzer >> glhImporter: anImporter [
1✔
326
        glhImporter := anImporter .
1✔
327
]
1✔
328

329
{ #category : #'as yet unclassified' }
330
GitAnalyzer >> impactedFilesInFollowUpCommitsOf: aGLHCommit [
×
331

×
332
        ^ self
×
333
                  impactedFilesInFollowUpCommitsOf: aGLHCommit
×
334
                  withMaxCommits: self maxChildCommits. 
×
335
]
×
336

337
{ #category : #churn }
338
GitAnalyzer >> impactedFilesInFollowUpCommitsOf: aGLHCommit withMaxCommits: max [
1✔
339

1✔
340
        | commitFiles |
1✔
341
        commitFiles := (fromCommit diffs collect: [ :diff |
1✔
342
                                diff new_path -> (Set new
1✔
343
                                         add: aGLHCommit -> diff diffRanges;
1✔
344
                                         yourself) ]) asDictionary.
1✔
345

1✔
346
        self
1✔
347
                visitChildCommits: fromCommit childCommits
1✔
348
                lookingForFiles: commitFiles upto: max.
1✔
349

1✔
350
        ^ commitFiles
1✔
351
]
1✔
352

353
{ #category : #initialization }
354
GitAnalyzer >> initialize [
1✔
355

1✔
356
        glModel := GLHModel new.
1✔
357
        fromCommit := GLHCommit new.
1✔
358
        glhImporter := GitlabModelImporter new.
1✔
359
        onProject := GLHProject new.
1✔
360
        maxChildCommits := -1
1✔
361
]
1✔
362

363
{ #category : #insertion }
364
GitAnalyzer >> insertDiff: aGLPHEDiffRange into: fileChangesDic startingFrom: from [ 
1✔
365
        |index|
1✔
366
        index := from. 
1✔
367
        aGLPHEDiffRange changes do: [ :aChange |
1✔
368
        
1✔
369
                aChange isAddition ifTrue: [ 
1✔
370
                        fileChangesDic at: index ifPresent: [ :current | 
1✔
371
                         
1✔
372
                        current key add: aChange.
1✔
373
                        current value: current value + 1.  ] ifAbsentPut: [((OrderedCollection new add: aChange; yourself) -> 1 ) ].
1✔
374
                         ].
1✔
375
                
1✔
376
                aChange isDeletion ifFalse: [ index := index + 1 ]. 
1✔
377
                
1✔
378
                 ]
1✔
379
]
1✔
380

381
{ #category : #accessing }
382
GitAnalyzer >> maxChildCommit: max [ 
1✔
383
        maxChildCommits := max
1✔
384
]
1✔
385

386
{ #category : #accessing }
387
GitAnalyzer >> maxChildCommits [
1✔
388
        ^ maxChildCommits
1✔
389
]
1✔
390

391
{ #category : #'as yet unclassified' }
392
GitAnalyzer >> onModel: agitHealthModel [
1✔
393
        glModel := agitHealthModel
1✔
394
]
1✔
395

396
{ #category : #accessing }
397
GitAnalyzer >> onProject: aGLHProject [ 
1✔
398
        onProject := aGLHProject
1✔
399
]
1✔
400

401
{ #category : #sorting }
402
GitAnalyzer >> sortChangeDic: aCollection [ 
1✔
403
        ^ (aCollection associations sortAscending: [ :e | e key ] ) asOrderedDictionary 
1✔
404
]
1✔
405

406
{ #category : #visiting }
407
GitAnalyzer >> visitChildCommits: commits lookingForFiles: commitFiles [
×
408

×
409
        ^ self visitChildCommits:  commits lookingForFiles: commitFiles upto: -1 
×
410
]
×
411

412
{ #category : #visiting }
413
GitAnalyzer >> visitChildCommits: commits lookingForFiles: commitFiles upto: nCommits [
1✔
414

1✔
415
        commits ifEmpty: [ ^ commitFiles ].
1✔
416
        (nCommits = 0) ifTrue: [ ^ commitFiles ].
1✔
417

1✔
418
        commits do: [ :commit |
1✔
419
                | files |
1✔
420
                files := commit diffs collect: [ :diff | diff ].
1✔
421

1✔
422
                files do: [ :diff |
1✔
423
                        commitFiles
1✔
424
                                at: diff new_path
1✔
425
                                ifPresent: [ :v | v add: commit -> diff diffRanges ]
1✔
426
                                ifAbsent: [  ] ].
1✔
427

1✔
428
                self
1✔
429
                        visitChildCommits: commit childCommits
1✔
430
                        lookingForFiles: commitFiles
1✔
431
                        upto: nCommits - 1 ].
1✔
432

1✔
433
        ^ commitFiles
1✔
434
]
1✔
435

436
{ #category : #visiting }
437
GitAnalyzer >> visitChildCommits: commits toStoreThemIn: commitsFound upto: nCommits [
1✔
438

1✔
439
        commits ifEmpty: [ ^ commitsFound ].
1✔
440
        nCommits = 0 ifTrue: [ ^ commitsFound ].
1✔
441

1✔
442
        commits do: [ :commit |
1✔
443
                commitsFound add: commit.
1✔
444

1✔
445
                self
1✔
446
                        visitChildCommits: commit childCommits
1✔
447
                        toStoreThemIn: commitsFound
1✔
448
                        upto: nCommits - 1 ].
1✔
449

1✔
450
        ^ commitsFound
1✔
451
]
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