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

moosetechnology / GitProjectHealth / 11667512120

04 Nov 2024 03:36PM UTC coverage: 59.207% (+0.2%) from 59.01%
11667512120

Pull #105

github

web-flow
Merge 0462ff346 into 3c4574e31
Pull Request #105: fix/add email user to the importer + tests

71 of 82 new or added lines in 3 files covered. (86.59%)

149 existing lines in 35 files now uncovered.

9582 of 16184 relevant lines covered (59.21%)

0.59 hits per line

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

92.64
/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 }
UNCOV
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 |
×
85
                            entry key asDate ]) asOrderedDictionary.
×
86

×
87
        ^ commits
×
88
]
×
89

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

1✔
93
        | commits response |
1✔
94
        
1✔
95
        ('GitAnalyzer, analyse commit Frequency on: ', onProject printString )
1✔
96
                recordInfo.
1✔
97
        
1✔
98
        response := {
1✔
99
                            (#numberOfCommit -> nil).
1✔
100
                            (#frequency -> nil) } asDictionary.
1✔
101

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

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

1✔
111
        ^ commits
1✔
112
]
1✔
113

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

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

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

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

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

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

1✔
155
                          creationDate := aGLHPMergeRequest created_at asDateAndTime.
1✔
156

1✔
157
                          mergedDate := aGLHPMergeRequest merged_at ifNil: [ ^ response ].
1✔
158

1✔
159
                          response
1✔
160
                                  at: #duration put: mergedDate - creationDate;
1✔
161
                                  at: #id_merge_commit put: aGLHPMergeRequest merge_commit_sha;
1✔
162
                                  at: #merged_at put: aGLHPMergeRequest merged_at;
1✔
163
                                  yourself ]
1✔
164
]
1✔
165

166
{ #category : #filter }
167
GitAnalyzer >> arrangeCommitsByDate: commits [
1✔
168

1✔
169
        | date2commits |
1✔
170
        date2commits := Dictionary new.
1✔
171

1✔
172
        commits do: [ :commit |
1✔
173
                | date |
1✔
174
                date := commit created_at asDate.
1✔
175
                date2commits
1✔
176
                        at: date printString
1✔
177
                        ifPresent: [ :v | v add: commit ]
1✔
178
                        ifAbsentPut: [
1✔
179
                                OrderedCollection new
1✔
180
                                        add: commit;
1✔
181
                                        yourself ] ].
1✔
182
        ^ date2commits
1✔
183
]
1✔
184

185
{ #category : #churn }
186
GitAnalyzer >> computeChurnOnFiles: aCollection [
1✔
187

1✔
188
        | changesDic perFileChanges churns initialAuthor followingAuthors|
1✔
189
        "1 -> (a GLPHEChange -> NumberOfChurnDetected)"
1✔
190
        changesDic := Dictionary new.
1✔
191
        initialAuthor := fromCommit commitCreator. 
1✔
192
        
1✔
193

1✔
194
        perFileChanges := aCollection associations collect: [ :assoc |
1✔
195
                                  assoc key
1✔
196
                                  -> (self computeSpecificChurnOf: assoc value) ].
1✔
197

1✔
198

1✔
199
        churns := perFileChanges collect: [ :assoc |
1✔
200
                          | churnData file aLineOfChanges |
1✔
201
                          file := assoc key.
1✔
202
                          aLineOfChanges := assoc value.
1✔
203
                          churnData := aLineOfChanges values ifEmpty: [  nil ] ifNotEmpty: [
1✔
204
                                  | churnedContribution churnSpecificFromCommit churnOfAuthorOnly |
1✔
205
                                
1✔
206
                                  "the total churn on any LoC affected"
1✔
207
                                  churnedContribution := aLineOfChanges select: [ :a |
1✔
208
                                                                 a value  > 1 ].
1✔
209

1✔
210
                                  "the churn that coccurs specifically on the loc introduced by the initial commit"
1✔
211
                                  churnSpecificFromCommit := churnedContribution select: [ :a |
1✔
212
                                                                     (a key collect: [ :loc |
1✔
213
                                                                              loc diffRange diff commit ])
1✔
214
                                                                             includes: fromCommit ].
1✔
215

1✔
216
                                                "the churn made the author of the initial commits "
1✔
217
                                  churnOfAuthorOnly := churnSpecificFromCommit select: [ :a |
1✔
218
                                                                     (((a key collect: [ :loc |
1✔
219
                                                                              loc diffRange diff commit commitCreator ]) asSet) difference: {initialAuthor} asSet ) isEmpty
1✔
220
                                                                             ].
1✔
221
                                                
1✔
222

1✔
223
                                  {
1✔
224
                                                   (#churnFromInitialCommitLines
1✔
225
                                                    ->
1✔
226
                                                            ((churnSpecificFromCommit sum: #value) - churnSpecificFromCommit size)).
1✔
227
                                                                                (#churnFromCommitCreatorOnly
1✔
228
                                                    ->
1✔
229
                                                            ((churnOfAuthorOnly sum: #value) - churnOfAuthorOnly size)).
1✔
230
                                                   (#churnLoC
1✔
231
                                                    ->
1✔
232
                                                            ((churnedContribution sum: #value)
1✔
233
                                                             - churnedContribution size)) 
1✔
234
                                        } asDictionary ].
1✔
235

1✔
236
                          file -> churnData ].
1✔
237
        churns := churns reject: [ :file2churn | file2churn value isNil ].
1✔
238

1✔
239
        ^ {
1✔
240
                  (#churns -> churns).
1✔
241
                  (#details -> perFileChanges) } asDictionary
1✔
242
]
1✔
243

244
{ #category : #churn }
245
GitAnalyzer >> computeSpecificChurnOf: commit2Changes [
1✔
246

1✔
247
        | changesDic |
1✔
248
        "1 -> (a GLPHEChange -> NumberOfChurnDetected)"
1✔
249
        changesDic := OrderedDictionary new.
1✔
250

1✔
251

1✔
252
        (commit2Changes sortAscending: [ :assoc | assoc key created_at ])
1✔
253
                do: [ :entry |
1✔
254
                        | commit diffRanges |
1✔
255
                        commit := entry key.
1✔
256
                        diffRanges := entry value.
1✔
257

1✔
258
                        diffRanges do: [ :diff |
1✔
259
                                | from |
1✔
260
                                from := (diff originalLineRange
1✔
261
                                                 copyFrom: (diff originalLineRange indexOf: $-) + 1
1✔
262
                                                 to: (diff originalLineRange
1✔
263
                                                                  indexOf: $,
1✔
264
                                                                  ifAbsent: [ diff originalLineRange size + 1 ]) - 1)
1✔
265
                                                asString asNumber.
1✔
266
                                from = 0 ifTrue: [ from := 1 ].
1✔
267
                                self insertDiff: diff into: changesDic startingFrom: from ] ].
1✔
268

1✔
269

1✔
270

1✔
271
        ^ self sortChangeDic: changesDic
1✔
272
]
1✔
273

274
{ #category : #accessing }
275
GitAnalyzer >> firstAmandmentFromChrun: aChurnAnalysis [ 
1✔
276
        |details whereChangesOccurs firstCommitsPerFile|
1✔
277
        
1✔
278
        whereChangesOccurs := (aChurnAnalysis at: #churns ) select: [ :file | (file value at: #churnLoC) > 0 ].
1✔
279
        
1✔
280
        details := whereChangesOccurs collect: [ :file |
1✔
281
                ((aChurnAnalysis at: #details) detect: [ :entry | entry key = file key] )
1✔
282
                 ].
1✔
283
        
1✔
284
        firstCommitsPerFile := details collect: [ :perFile |
1✔
285
                |changes firstCommits first|
1✔
286
                changes := perFile value.
1✔
287
                changes := changes select: [ :line2changes | line2changes value value > 1  ].
1✔
288
                firstCommits := (changes collect: [ :line2changes |  line2changes key second diffRange diff commit ]) values. 
1✔
289
                first := (firstCommits sortAscending: [:c | c created_at ]) first.
1✔
290
                 ].
1✔
291
        
1✔
292

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

1✔
295
]
1✔
296

297
{ #category : #accessing }
298
GitAnalyzer >> fromCommit: aCommit [
1✔
299
        fromCommit := aCommit. 
1✔
300
]
1✔
301

302
{ #category : #accessing }
303
GitAnalyzer >> glhImporter: anImporter [
1✔
304
        glhImporter := anImporter .
1✔
305
]
1✔
306

307
{ #category : #'as yet unclassified' }
UNCOV
308
GitAnalyzer >> impactedFilesInFollowUpCommitsOf: aGLHCommit [
×
309

×
310
        ^ self
×
311
                  impactedFilesInFollowUpCommitsOf: aGLHCommit
×
312
                  withMaxCommits: self maxChildCommits. 
×
313
]
×
314

315
{ #category : #churn }
316
GitAnalyzer >> impactedFilesInFollowUpCommitsOf: aGLHCommit withMaxCommits: max [
1✔
317

1✔
318
        | commitFiles |
1✔
319
        commitFiles := (fromCommit diffs collect: [ :diff |
1✔
320
                                diff new_path -> (Set new
1✔
321
                                         add: aGLHCommit -> diff diffRanges;
1✔
322
                                         yourself) ]) asDictionary.
1✔
323

1✔
324
        self
1✔
325
                visitChildCommits: fromCommit childCommits
1✔
326
                lookingForFiles: commitFiles upto: max.
1✔
327

1✔
328
        ^ commitFiles
1✔
329
]
1✔
330

331
{ #category : #initialization }
332
GitAnalyzer >> initialize [
1✔
333

1✔
334
        glModel := GLHModel new.
1✔
335
        fromCommit := GLHCommit new.
1✔
336
        glhImporter := GLPHModelImporter new.
1✔
337
        onProject := GLHProject new.
1✔
338
        maxChildCommits := -1
1✔
339
]
1✔
340

341
{ #category : #insertion }
342
GitAnalyzer >> insertDiff: aGLPHEDiffRange into: fileChangesDic startingFrom: from [ 
1✔
343
        |index|
1✔
344
        index := from. 
1✔
345
        aGLPHEDiffRange changes do: [ :aChange |
1✔
346
        
1✔
347
                aChange isAddition ifTrue: [ 
1✔
348
                        fileChangesDic at: index ifPresent: [ :current | 
1✔
349
                         
1✔
350
                        current key add: aChange.
1✔
351
                        current value: current value + 1.  ] ifAbsentPut: [((OrderedCollection new add: aChange; yourself) -> 1 ) ].
1✔
352
                         ].
1✔
353
                
1✔
354
                aChange isDeletion ifFalse: [ index := index + 1 ]. 
1✔
355
                
1✔
356
                 ]
1✔
357
]
1✔
358

359
{ #category : #accessing }
360
GitAnalyzer >> maxChildCommit: max [ 
1✔
361
        maxChildCommits := max
1✔
362
]
1✔
363

364
{ #category : #accessing }
365
GitAnalyzer >> maxChildCommits [
1✔
366
        ^ maxChildCommits
1✔
367
]
1✔
368

369
{ #category : #'as yet unclassified' }
370
GitAnalyzer >> onModel: agitHealthModel [
1✔
371
        glModel := agitHealthModel
1✔
372
]
1✔
373

374
{ #category : #accessing }
375
GitAnalyzer >> onProject: aGLHProject [ 
1✔
376
        onProject := aGLHProject
1✔
377
]
1✔
378

379
{ #category : #sorting }
380
GitAnalyzer >> sortChangeDic: aCollection [ 
1✔
381
        ^ (aCollection associations sortAscending: [ :e | e key ] ) asOrderedDictionary 
1✔
382
]
1✔
383

384
{ #category : #visiting }
UNCOV
385
GitAnalyzer >> visitChildCommits: commits lookingForFiles: commitFiles [
×
386

×
387
        ^ self visitChildCommits:  commits lookingForFiles: commitFiles upto: -1 
×
388
]
×
389

390
{ #category : #visiting }
391
GitAnalyzer >> visitChildCommits: commits lookingForFiles: commitFiles upto: nCommits [
1✔
392

1✔
393
        commits ifEmpty: [ ^ commitFiles ].
1✔
394
        (nCommits = 0) ifTrue: [ ^ commitFiles ].
1✔
395

1✔
396
        commits do: [ :commit |
1✔
397
                | files |
1✔
398
                files := commit diffs collect: [ :diff | diff ].
1✔
399

1✔
400
                files do: [ :diff |
1✔
401
                        commitFiles
1✔
402
                                at: diff new_path
1✔
403
                                ifPresent: [ :v | v add: commit -> diff diffRanges ]
1✔
404
                                ifAbsent: [  ] ].
1✔
405

1✔
406
                self
1✔
407
                        visitChildCommits: commit childCommits
1✔
408
                        lookingForFiles: commitFiles
1✔
409
                        upto: nCommits - 1 ].
1✔
410

1✔
411
        ^ commitFiles
1✔
412
]
1✔
413

414
{ #category : #visiting }
415
GitAnalyzer >> visitChildCommits: commits toStoreThemIn: commitsFound upto: nCommits [
1✔
416

1✔
417
        commits ifEmpty: [ ^ commitsFound ].
1✔
418
        nCommits = 0 ifTrue: [ ^ commitsFound ].
1✔
419

1✔
420
        commits do: [ :commit |
1✔
421
                commitsFound add: commit.
1✔
422

1✔
423
                self
1✔
424
                        visitChildCommits: commit childCommits
1✔
425
                        toStoreThemIn: commitsFound
1✔
426
                        upto: nCommits - 1 ].
1✔
427

1✔
428
        ^ commitsFound
1✔
429
]
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