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

moosetechnology / GitProjectHealth / 10420133625

16 Aug 2024 12:43PM UTC coverage: 19.266%. First build
10420133625

Pull #29

github

web-flow
Merge f323a8a7f into 7ae7aaeb7
Pull Request #29: refactor: define over in the generateAnalysis method

0 of 51 new or added lines in 2 files covered. (0.0%)

1585 of 8227 relevant lines covered (19.27%)

0.19 hits per line

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

0.0
/src/GitLabHealth-Model-Analysis/GitMetricExporter.class.st
1
Class {
2
        #name : #GitMetricExporter,
3
        #superclass : #Object,
4
        #instVars : [
5
                'glhImporter',
6
                'label',
7
                'entities',
8
                'projectCache',
9
                'sinceTimeLimit',
10
                'runningPeriods',
11
                'maxCommitWindow',
12
                'over',
13
                'analyses'
14
        ],
15
        #category : #'GitLabHealth-Model-Analysis'
16
}
17

18
{ #category : #'as yet unclassified' }
19
GitMetricExporter class >> demoPeriod [
×
20

×
21
        ^ self new
×
22
                  addAPeriodFrom: '01 march 2023' to: '31 may 2023';
×
23
                  addAPeriodFrom: '01 december 2023' to: '29 february 2024';
×
24
                  addAPeriodFrom: '01 march 2024' to: '31 may 2024'
×
25
]
×
26

27
{ #category : #adding }
28
GitMetricExporter >> addAPeriodFrom: since to: until [
×
29

×
30
        runningPeriods add: {
×
31
                        (#since -> since asDate).
×
32
                        (#until -> until asDate) } asDictionary.
×
33
        
×
34
        ^runningPeriods 
×
35
]
×
36

37
{ #category : #adding }
38
GitMetricExporter >> addEntitiesFromUserNames: userNames [
×
39
        "import all the project since a certain time"
×
40

×
41
        'Import all projects from the Git repository' recordInfo.
×
42
        projectCache := projectCache ifNil: [
×
43
                                glhImporter importProjectsSince: sinceTimeLimit ].
×
44

×
45
        "then collect the project in which the user has be seen commited"
×
46
        entities addAll: (userNames collect: [ :username |
×
47
                         | projects metrics i size |
×
48
                         projects := self findParticipationOfCommitAuthorNamed: username amongProjects: projectCache.
×
49

×
50
                         metrics := GitMetric4User new.
×
51
                         metrics
×
52
                                 glhImporter: glhImporter;
×
53
                                 findUserNamed: username.
×
54

×
55

×
56

×
57
                         i := 0.
×
58
                         size := projects size.
×
59
                         metrics itsProjects: (projects collect: [ :p |
×
60
                                          (' ' join: {
×
61
                                                           'complete import of project:'.
×
62
                                                           p name printString.
×
63
                                                           '['.
×
64
                                                           (i := i + 1) printString.
×
65
                                                           '/'.
×
66
                                                           size.
×
67
                                                           ']' }) recordInfo.
×
68

×
69
                                          p id -> (glhImporter completeImportProject: p) ]) asDictionary.
×
70

×
71
                         metrics ]).
×
72

×
73
        ^ self
×
74
]
×
75

76
{ #category : #adding }
77
GitMetricExporter >> addEntitiesFromUserNamesAndProjects: usersWithProjects [
×
78

×
79
        entities addAll: (usersWithProjects associations collect: [ :assoc |
×
80
                            | username projects metrics |
×
81
                            username := assoc key.
×
82
                            projects := assoc value.
×
83

×
84
                            metrics := GitMetric4User new.
×
85
                            metrics
×
86
                                    glhImporter: glhImporter;
×
87
                                    findUserNamed: username.
×
88
                            metrics loadProjectsFromIds: projects.
×
89

×
90
                            metrics ]).
×
91

×
92
        ^ self
×
93
]
×
94

95
{ #category : #accessing }
96
GitMetricExporter >> analyses [
×
97

×
98
        ^ analyses
×
99
]
×
100

101
{ #category : #accessing }
102
GitMetricExporter >> analyses: anObject [
×
103

×
104
        analyses := anObject
×
105
]
×
106

107
{ #category : #utilities }
108
GitMetricExporter >> constructFilePath: runningOver [
×
109

×
110
        | file |
×
111
        file := (FileLocator home
×
112
                 /
×
113
                         ('GitlabHealth-' , label printString , '-' , runningOver printString
×
114
                          , '-'
×
115
                          , (DateAndTime now printString replaceAll: $: with: $-)
×
116
                          , '.csv')) asFileReference.
×
117
        ^ file
×
118
]
×
119

120
{ #category : #accessing }
121
GitMetricExporter >> entities: aCollection [ 
×
122
        entities := aCollection
×
123
]
×
124

125
{ #category : #exporting }
126
GitMetricExporter >> exportFor: usersWithProjects [
×
127

×
128
        self exportFor: usersWithProjects over: { Date. Week . Month . Year }.
×
129
]
×
130

131
{ #category : #exporting }
132
GitMetricExporter >> exportFor: usersWithProjects over: aCollectionOfDateWeekMonthOrYear [
×
133

×
134
        entities ifNil: [
×
135
                self addEntitiesFromUserNamesAndProjects: usersWithProjects ].
×
136

×
137
        self exportFor: aCollectionOfDateWeekMonthOrYear. 
×
138
]
×
139

140
{ #category : #exporting }
NEW
141
GitMetricExporter >> exportInCSV [
×
142

×
143
        | exportBrowserModel file |
×
144
        exportBrowserModel := MiExportModel new.
×
145

×
146
        self analyses ifNil: [ self generateAnalyses ].
×
147
        exportBrowserModel entitiesList: self analyses.
×
148

×
149
        exportBrowserModel removeColumnForQueryNamed: #Type.
×
150
        exportBrowserModel removeColumnForQueryNamed: #Name.
×
151

×
152
        exportBrowserModel
×
153
                addColumnForQuery: [ :analysis | analysis username ]
×
154
                withName: #'User name'.
×
155

×
156
        exportBrowserModel
×
157
                addColumnForQuery: [ :analysis | analysis period ]
×
158
                withName: #Period.
×
159

×
160
        "Code Contribution "
×
161
        exportBrowserModel
×
162
                addColumnForQuery: [ :analysis | analysis codeAddition ]
×
163
                withName: 'code addition (avg)' asSymbol.
×
164

×
165
        exportBrowserModel
×
166
                addColumnForQuery: [ :analysis | analysis codeDeletion ]
×
167
                withName: 'code deletion (avg)' asSymbol.
×
168

×
169
        "Commit frequencies "
×
170
        exportBrowserModel
×
171
                addColumnForQuery: [ :analysis | analysis commitFrequency ]
×
172
                withName: 'commits frequency (avg) ' asSymbol.
×
173

×
174
        "comment contribution "
×
175
        exportBrowserModel
×
176
                addColumnForQuery: [ :analysis | analysis commentContribution ]
×
177
                withName: 'comment contribution (avg)' asSymbol.
×
178

×
179
        "merge Request Duration "
×
180
        exportBrowserModel
×
181
                addColumnForQuery: [ :analysis | analysis mergeRequestDuration ]
×
182
                withName: 'merge Request Duration ' asSymbol.
×
183

×
184
        "code churn"
×
185
        exportBrowserModel
×
186
                addColumnForQuery: [ :analysis | analysis codeChurn ]
×
187
                withName:
×
188
                'churn % (W=' , maxCommitWindow printString , ') ' asSymbol.
×
189

×
190
        "delay Until First Churn"
×
191
        exportBrowserModel
×
192
                addColumnForQuery: [ :analysis | analysis delayUntilFirstChurn ]
×
193
                withName:
×
194
                        'delay Until First Churn (W=' , maxCommitWindow printString
×
195
                        , ') ' asSymbol.
×
196

×
NEW
197
        file := self constructFilePath: over.
×
NEW
198
        file writeStreamDo: [ :aStream |
×
NEW
199
                aStream
×
NEW
200
                        << 'sep=,';
×
NEW
201
                        << OSPlatform current lineEnding.
×
NEW
202
                exportBrowserModel writeCSVOn: aStream ].
×
203

×
204
        'Done computing' recordInfo
×
205
]
×
206

207
{ #category : #exporting }
208
GitMetricExporter >> exportInDB: repository [
×
209

×
210
        repository enableSingleton.
×
211

×
212
        self analyses ifNil: [ self generateAnalyses ].
×
213
        self analyses do: [ :analysis | analysis save ]
×
214
]
×
215

216
{ #category : #projects }
217
GitMetricExporter >> findParticipationOfCommitAuthorNamed: username amongProjects: aCollectionOfProjects [
×
218

×
219
        | response itsProjects i size |
×
220
        i := 1.
×
221
        size := aCollectionOfProjects size.
×
222
        itsProjects := aCollectionOfProjects select: [ :project |
×
223
                               (' ' join: {
×
224
                                                'search'.
×
225
                                                username printString.
×
226
                                                'in Project:'.
×
227
                                                project name printString.
×
228
                                                '['.
×
229
                                                (i := i + 1) printString.
×
230
                                                '/'.
×
231
                                                size.
×
232
                                                ']' }) recordInfo.
×
233

×
234
                               response := glhImporter glhApi
×
235
                                                   commitsOfUser: username
×
236
                                                   inProject: project id
×
237
                                                   since: '01 january 2023' asDateAndTime
×
238
                                                   until: Date today asDateAndTime.
×
239
                               response := glhImporter parseCommitsResult: response.
×
240
                               response isNotEmpty
×
241
                 ].
×
242

×
243
        ^ itsProjects
×
244
]
×
245

246
{ #category : #projects }
247
GitMetricExporter >> findProjectsOfUser: aCollection [ 
×
248
        self shouldBeImplemented.
×
249
]
×
250

251
{ #category : #analysis }
252
GitMetricExporter >> generateAnalyses [
×
253

×
254
        | newAnalyses |
×
255
        newAnalyses := OrderedCollection new.
×
256

×
257
        runningPeriods do: [ :period |
×
258
                newAnalyses addAll: (entities collect: [ :entity |
×
259
                        entity
×
260
                                generateAnalysisForPeriod: period
×
261
                                over: over
×
262
                                withMaxCommitWindows: maxCommitWindow ]) ].
×
263

×
264
        self analyses: newAnalyses.
×
265

×
266
        ^ newAnalyses
×
267
]
×
268

269
{ #category : #analysis }
NEW
270
GitMetricExporter >> generateAnalysesOver: aDateWeekMonthOrYear [
×
NEW
271

×
NEW
272
        | newAnalyses |
×
NEW
273
        over := aDateWeekMonthOrYear.
×
NEW
274
        newAnalyses := OrderedCollection new.
×
NEW
275

×
NEW
276
        runningPeriods do: [ :period |
×
NEW
277
                newAnalyses addAll: (entities collect: [ :entity |
×
NEW
278
                        entity
×
NEW
279
                                generateAnalysisForPeriod: period
×
NEW
280
                                over: over
×
NEW
281
                                withMaxCommitWindows: maxCommitWindow ]) ].
×
NEW
282

×
NEW
283
        self analyses: newAnalyses.
×
NEW
284

×
NEW
285
        ^ newAnalyses
×
NEW
286
]
×
287

288
{ #category : #accessing }
289
GitMetricExporter >> glhImporter: anImporter [
×
290

×
291
        glhImporter := anImporter withInitialCommits: false; yourself. 
×
292
]
×
293

294
{ #category : #initialization }
295
GitMetricExporter >> initialize [
×
296

×
297
        entities := OrderedCollection new.
×
298
        "set up the minimal date from which we are looking for the commits a particular user in projects"
×
299
        sinceTimeLimit := '2024-01-01' asDateAndTime..
×
300
        runningPeriods := OrderedCollection new.
×
301
        maxCommitWindow := 3.
×
302
        over := Date
×
303
]
×
304

305
{ #category : #accessing }
306
GitMetricExporter >> label: aString [ 
×
307
        label := aString
×
308
]
×
309

310
{ #category : #accessing }
311
GitMetricExporter >> maxCommitWindow: anInteger [
×
312
        maxCommitWindow := anInteger abs
×
313
]
×
314

315
{ #category : #adding }
316
GitMetricExporter >> onlyImportProjectsOfGroup: groupId [
×
317

×
318
        | group |
×
319
        group := glhImporter importGroup: groupId.
×
320
        projectCache := group toScope: GLHProject
×
321
]
×
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