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

moosetechnology / GitProjectHealth / 10417352781

16 Aug 2024 08:53AM UTC coverage: 19.039%. First build
10417352781

Pull #27

github

web-flow
Merge 5daf3535b into 7ae7aaeb7
Pull Request #27: feat(metrics): average time between commits

0 of 78 new or added lines in 3 files covered. (0.0%)

1585 of 8325 relevant lines covered (19.04%)

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 : #exporting }
121
GitMetricExporter >> debugExportOver: aCollectionOfDateWeekMonthOrYear [
×
122

×
123
        | period |
×
124
        over := Date.
×
125

×
126
        period := runningPeriods first.
×
127

×
128

×
129
        1 halt.
×
130
        "Code Contribution "
×
131

×
132
        (entities collect: (self blockCodeAdditionSince: period)) recordInfo.
×
133
        (entities collect: (self blockCodeDeletionSince: period)) recordInfo.
×
134

×
135
        "Commit frequencies "
×
136
        (entities collect: (self blockCommitFrequencySince: period))
×
137
                recordInfo.
×
138

×
139
        "comment contribution "
×
140
        (entities collect: (self blockCommentsContributionSince: period))
×
141
                recordInfo.
×
142

×
143
        "merge Request Duration "
×
144
        (entities collect: (self blockMergeRequestDurationSince: period))
×
145
                recordInfo.
×
146

×
147
        "code churn"
×
148
        (entities collect: (self blockCodeChurnSince: period)) recordInfo.
×
149

×
150
        "delay Until First Churn"
×
151
        (entities collect: (self blockDelayUntilFirstChurnSince: period))
×
152
                recordInfo.
×
153

×
154

×
155
        'Done computing debug' recordInfo
×
156
]
×
157

158
{ #category : #accessing }
159
GitMetricExporter >> entities: aCollection [ 
×
160
        entities := aCollection
×
161
]
×
162

163
{ #category : #exporting }
164
GitMetricExporter >> exportFor: usersWithProjects [
×
165

×
166
        self exportFor: usersWithProjects over: { Date. Week . Month . Year }.
×
167
]
×
168

169
{ #category : #exporting }
170
GitMetricExporter >> exportFor: usersWithProjects over: aCollectionOfDateWeekMonthOrYear [
×
171

×
172
        entities ifNil: [
×
173
                self addEntitiesFromUserNamesAndProjects: usersWithProjects ].
×
174

×
175
        self exportFor: aCollectionOfDateWeekMonthOrYear. 
×
176
]
×
177

178
{ #category : #exporting }
179
GitMetricExporter >> exportInCSVOver: aCollectionOfDateWeekMonthOrYear [
×
180

×
181
        | exportBrowserModel file |
×
182
        exportBrowserModel := MiExportModel new.
×
183

×
184
        self analyses ifNil: [ self generateAnalyses ].
×
185
        exportBrowserModel entitiesList: self analyses.
×
186

×
187
        exportBrowserModel removeColumnForQueryNamed: #Type.
×
188
        exportBrowserModel removeColumnForQueryNamed: #Name.
×
189

×
190
        exportBrowserModel
×
191
                addColumnForQuery: [ :analysis | analysis username ]
×
192
                withName: #'User name'.
×
193

×
194
        exportBrowserModel
×
195
                addColumnForQuery: [ :analysis | analysis period ]
×
196
                withName: #Period.
×
197

×
198
        "Code Contribution "
×
199
        exportBrowserModel
×
200
                addColumnForQuery: [ :analysis | analysis codeAddition ]
×
201
                withName: 'code addition (avg)' asSymbol.
×
202

×
203
        exportBrowserModel
×
204
                addColumnForQuery: [ :analysis | analysis codeDeletion ]
×
205
                withName: 'code deletion (avg)' asSymbol.
×
206

×
207
        "Commit frequencies "
×
208
        exportBrowserModel
×
209
                addColumnForQuery: [ :analysis | analysis commitFrequency ]
×
210
                withName: 'commits frequency (avg) ' asSymbol.
×
211

×
212
        "comment contribution "
×
213
        exportBrowserModel
×
214
                addColumnForQuery: [ :analysis | analysis commentContribution ]
×
215
                withName: 'comment contribution (avg)' asSymbol.
×
216

×
217
        "merge Request Duration "
×
218
        exportBrowserModel
×
219
                addColumnForQuery: [ :analysis | analysis mergeRequestDuration ]
×
220
                withName: 'merge Request Duration ' asSymbol.
×
221

×
222
        "code churn"
×
223
        exportBrowserModel
×
224
                addColumnForQuery: [ :analysis | analysis codeChurn ]
×
225
                withName:
×
226
                'churn % (W=' , maxCommitWindow printString , ') ' asSymbol.
×
227

×
228
        "delay Until First Churn"
×
229
        exportBrowserModel
×
230
                addColumnForQuery: [ :analysis | analysis delayUntilFirstChurn ]
×
231
                withName:
×
232
                        'delay Until First Churn (W=' , maxCommitWindow printString
×
233
                        , ') ' asSymbol.
×
NEW
234
                        
×
NEW
235
        "average time between commits"
×
NEW
236
        exportBrowserModel
×
NEW
237
                addColumnForQuery: [ :analysis | analysis averageTimeBetweenCommits  ]
×
NEW
238
                withName:
×
NEW
239
                        'average time between commits' asSymbol.
×
240

×
241
        aCollectionOfDateWeekMonthOrYear do: [ :aDateWeekMonthOrYear |
×
242
                over := aDateWeekMonthOrYear.
×
243
                file := self constructFilePath: over.
×
244

×
245
                file writeStreamDo: [ :aStream |
×
246
                        aStream
×
247
                                << 'sep=,';
×
248
                                << OSPlatform current lineEnding.
×
249
                        exportBrowserModel writeCSVOn: aStream ] ].
×
250

×
251
        'Done computing' recordInfo
×
252
]
×
253

254
{ #category : #exporting }
255
GitMetricExporter >> exportInDB: repository [
×
256

×
257
        repository enableSingleton.
×
258

×
259
        self analyses ifNil: [ self generateAnalyses ].
×
260
        self analyses do: [ :analysis | analysis save ]
×
261
]
×
262

263
{ #category : #projects }
264
GitMetricExporter >> findParticipationOfCommitAuthorNamed: username amongProjects: aCollectionOfProjects [
×
265

×
266
        | response itsProjects i size |
×
267
        i := 1.
×
268
        size := aCollectionOfProjects size.
×
269
        itsProjects := aCollectionOfProjects select: [ :project |
×
270
                               (' ' join: {
×
271
                                                'search'.
×
272
                                                username printString.
×
273
                                                'in Project:'.
×
274
                                                project name printString.
×
275
                                                '['.
×
276
                                                (i := i + 1) printString.
×
277
                                                '/'.
×
278
                                                size.
×
279
                                                ']' }) recordInfo.
×
280

×
281
                               response := glhImporter glhApi
×
282
                                                   commitsOfUser: username
×
283
                                                   inProject: project id
×
284
                                                   since: '01 january 2023' asDateAndTime
×
285
                                                   until: Date today asDateAndTime.
×
286
                               response := glhImporter parseCommitsResult: response.
×
287
                               response isNotEmpty
×
288
                 ].
×
289

×
290
        ^ itsProjects
×
291
]
×
292

293
{ #category : #projects }
294
GitMetricExporter >> findProjectsOfUser: aCollection [ 
×
295
        self shouldBeImplemented.
×
296
]
×
297

298
{ #category : #analysis }
299
GitMetricExporter >> generateAnalyses [
×
300

×
301
        | newAnalyses |
×
302
        newAnalyses := OrderedCollection new.
×
303

×
304
        runningPeriods do: [ :period |
×
305
                newAnalyses addAll: (entities collect: [ :entity |
×
306
                        entity
×
307
                                generateAnalysisForPeriod: period
×
308
                                over: over
×
309
                                withMaxCommitWindows: maxCommitWindow ]) ].
×
310

×
311
        self analyses: newAnalyses.
×
312

×
313
        ^ newAnalyses
×
314
]
×
315

316
{ #category : #accessing }
317
GitMetricExporter >> glhImporter: anImporter [
×
318

×
319
        glhImporter := anImporter withInitialCommits: false; yourself. 
×
320
]
×
321

322
{ #category : #initialization }
323
GitMetricExporter >> initialize [
×
324

×
325
        entities := OrderedCollection new.
×
326
        "set up the minimal date from which we are looking for the commits a particular user in projects"
×
327
        sinceTimeLimit := '2024-01-01' asDateAndTime..
×
328
        runningPeriods := OrderedCollection new.
×
329
        maxCommitWindow := 3.
×
330
        over := Date
×
331
]
×
332

333
{ #category : #accessing }
334
GitMetricExporter >> label: aString [ 
×
335
        label := aString
×
336
]
×
337

338
{ #category : #accessing }
339
GitMetricExporter >> maxCommitWindow: anInteger [
×
340
        maxCommitWindow := anInteger abs
×
341
]
×
342

343
{ #category : #adding }
344
GitMetricExporter >> onlyImportProjectsOfGroup: groupId [
×
345

×
346
        | group |
×
347
        group := glhImporter importGroup: groupId.
×
348
        projectCache := group toScope: GLHProject
×
349
]
×
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