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

moosetechnology / GitProjectHealth / 13942501049

19 Mar 2025 08:54AM UTC coverage: 70.207% (+2.2%) from 68.041%
13942501049

Pull #163

github

web-flow
Merge branch 'main' into develop
Pull Request #163: add more metric to main

2397 of 3773 new or added lines in 42 files covered. (63.53%)

1 existing line in 1 file now uncovered.

13708 of 19525 relevant lines covered (70.21%)

0.7 hits per line

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

92.47
/src/GitLabHealth-Model-Analysis/CodeChurnOnMergedMergeRequestProjectMetric.class.st
1
Class {
2
        #name : #CodeChurnOnMergedMergeRequestProjectMetric,
3
        #superclass : #ProjectMetric,
4
        #instVars : [
5
                'maxCommitWindow'
6
        ],
7
        #category : #'GitLabHealth-Model-Analysis'
8
}
9

10
{ #category : #calculating }
11
CodeChurnOnMergedMergeRequestProjectMetric >> calculate [
1✔
12

1✔
13
        | res groupedByDate totalContributions gitAnalyzer parentsCommits |
1✔
14
        projectMergeRequests ifNil: [ self load ].
1✔
15

1✔
16
        totalContributions := OrderedCollection new.
1✔
17

1✔
18

1✔
19
        groupedByDate := self setupGroupedDate.
1✔
20

1✔
21
        parentsCommits := projectMergeRequests collect: [ :mr |
1✔
22
                                  | parentCommit mergedCommit |
1✔
23
                                  mergedCommit := mr mergedCommit.
1✔
24
                                  mergedCommit parentCommits
1✔
25
                                          addAll:
1✔
26
                                                  (mergedCommit parent_ids collect: [ :id |
1✔
27
                                                           glhImporter
1✔
28
                                                                   importCommit: id
1✔
29
                                                                   ofProject: project ])
1✔
30
                                          unless: glhImporter blockOnIdEquality.
1✔
31
                                  parentCommit := (mergedCommit parentCommits sort: [
1✔
32
                                                           :c1
1✔
33
                                                           :c2 | "oldest commit first"
1✔
34
                                                           c1 created_at < c2 created_at ])
1✔
35
                                                          first ].
1✔
36

1✔
37

1✔
38
        gitAnalyzer := GitAnalyzer new maxChildCommit: 1.
1✔
39
        res := parentsCommits collect: [ :commit |
1✔
40
                       commit -> (gitAnalyzer
1✔
41
                                fromCommit: commit;
1✔
42
                                analyseChurn) ].
1✔
43

1✔
44
        res do: [ :commits4Churns |
1✔
45
                | commit allChurnsInCommit sumChurnInCommit overDate contribution churnOnCommit |
1✔
46
                commit := commits4Churns key.
1✔
47
                allChurnsInCommit := commits4Churns value.
1✔
48
                sumChurnInCommit := (allChurnsInCommit at: #churns) sum: [ :churn |
1✔
49
                                            | numerator |
1✔
50
                                            numerator := churn value at: #churnLoC.
1✔
51
                                            numerator ].
1✔
52
                contribution := allChurnsInCommit at: #totalContribution.
1✔
53
                totalContributions add: contribution.
1✔
54
                churnOnCommit := {
1✔
55
                                         (#churnOnCommit -> sumChurnInCommit).
1✔
56
                                         (#LoCOnCommit -> contribution) } asDictionary.
1✔
57
                overDate := self transformDate: commit created_at to: over.
1✔
58
                groupedByDate
1✔
59
                        at: overDate printString
1✔
60
                        ifPresent: [ :array | array add: churnOnCommit ]
1✔
61
                        ifAbsentPut: [
1✔
62
                                OrderedCollection new
1✔
63
                                        add: churnOnCommit;
1✔
64
                                        yourself ] ].
1✔
65
        groupedByDate := groupedByDate collect: [ :churnsAtDate |
1✔
66
                                 | totalChurn totalContribution percentage |
1✔
67
                                 totalChurn := churnsAtDate sum: [ :churn |
1✔
68
                                                       churn at: #churnOnCommit ].
1✔
69
                                 totalContribution := churnsAtDate sum: [ :churn |
1✔
70
                                                              churn at: #LoCOnCommit ].
1✔
71
                                 totalContribution = 0
1✔
72
                                         ifTrue: [ percentage := 0 asFloat ]
1✔
73
                                         ifFalse: [
1✔
74
                                         percentage := (totalChurn * 100
1✔
75
                                                        / totalContribution) asFloat ].
1✔
76
                                 {
1✔
77
                                         (#churn -> totalChurn).
1✔
78
                                         (#contribution -> totalContribution).
1✔
79
                                         (#percentage -> percentage) } asDictionary ].
1✔
80

1✔
81
        ^ (groupedByDate collect: [ :date | date at: #percentage ]) average
1✔
82
]
1✔
83

84
{ #category : #accessing }
NEW
85
CodeChurnOnMergedMergeRequestProjectMetric >> description [
×
NEW
86

×
NEW
87
        ^ 'churn % made by a MR (avg by MR)'
×
NEW
88
]
×
89

90
{ #category : #initialization }
91
CodeChurnOnMergedMergeRequestProjectMetric >> initialize [ 
1✔
92
        maxCommitWindow := 3. 
1✔
93
]
1✔
94

95
{ #category : #loading }
96
CodeChurnOnMergedMergeRequestProjectMetric >> load [
1✔
97

1✔
98
        projectMergeRequests := self
1✔
99
                                        loadMergeRequestsSince: (period at: #since)
1✔
100
                                        until: (period at: #until).
1✔
101
                
1✔
102
                projectMergeRequests := projectMergeRequests select: [ :mr |
1✔
103
                                        mr state = #merged ].
1✔
104
        
1✔
105
                projectMergeRequests do: [ :mr | glhImporter importMergeRequestMergeCommits: mr ]
1✔
106
]
1✔
107

108
{ #category : #accessing }
NEW
109
CodeChurnOnMergedMergeRequestProjectMetric >> maxCommitWindow: anInteger [ 
×
NEW
110
        maxCommitWindow := anInteger
×
NEW
111
]
×
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

© 2025 Coveralls, Inc