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

moosetechnology / GitProjectHealth / 10075779876

24 Jul 2024 11:28AM UTC coverage: 31.874% (-0.4%) from 32.312%
10075779876

Pull #9

github

web-flow
Merge 3f514973e into 30d38cc2f
Pull Request #9: Refactoring/metrics interface

84 of 391 new or added lines in 10 files covered. (21.48%)

13 existing lines in 2 files now uncovered.

2526 of 7925 relevant lines covered (31.87%)

0.32 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
                'beforeExp',
7
                'duringExp',
8
                'label',
9
                'entities',
10
                'projectCache',
11
                'sinceTimeLimit',
12
                'runningPeriods',
13
                'maxCommitWindow',
14
                'over'
15
        ],
16
        #category : #'GitLabHealth-Model-Analysis'
17
}
18

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

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

28
{ #category : #'as yet unclassified' }
29
GitMetricExporter >> addCodeChurnExporter: exportBrowserModel [
×
30

×
31
        | columnName |
×
32
        maxCommitWindow := 3.
×
33
        runningPeriods do: [ :period |
×
34
                columnName := ('churn % (W=' , maxCommitWindow printString , ') '
×
35
                               , period printString) asSymbol.
×
36

×
37
                exportBrowserModel
×
38
                        addColumnForQuery: (self blockCodeChurnSince: period)
×
39
                        withName: columnName.
×
40

×
NEW
41
         ].
×
42
]
×
43

44
{ #category : #'as yet unclassified' }
45
GitMetricExporter >> addCommentContributionExporter: exportBrowserModel [
×
46

×
47
        | columnName |
×
48
        Smalltalk snapshot: true andQuit: false.
×
49

×
50
        runningPeriods do: [ :period |
×
51
                columnName := ('comment contribution (avg) ' , period printString)
×
52
                                      asSymbol.
×
53

×
54
                exportBrowserModel
×
55
                        addColumnForQuery: (self blockCommentsContributionSince: period)
×
56
                        withName: columnName ]
×
57
]
×
58

59
{ #category : #'as yet unclassified' }
60
GitMetricExporter >> addContributionExporter: exportBrowserModel [
×
61

×
62
        | columnName |
×
63
        "Code Contribution "
×
64
        runningPeriods do: [ :period |
×
65
                columnName := ('code addition (avg) ' , period printString) asSymbol.
×
66

×
67
                exportBrowserModel
×
68
                        addColumnForQuery: (self blockCodeAdditionSince: period)
×
69
                        withName: columnName.
×
70

×
71
                columnName := ('code deletion (avg) ' , period printString) asSymbol.
×
72
                exportBrowserModel
×
73
                        addColumnForQuery: (self blockCodeDeletionSince: period)
×
74
                        withName: columnName.
×
75

×
NEW
76
         ]
×
77
]
×
78

79
{ #category : #'as yet unclassified' }
80
GitMetricExporter >> addDelayUntilFirstChurnExporter: exportBrowserModel [
×
81

×
82
        | columnName |
×
83
        runningPeriods do: [ :period |
×
84
                columnName := ('delay Until First Churn (W=' , maxCommitWindow printString , ') '
×
85
                               , period printString) asSymbol.
×
86

×
87
                exportBrowserModel
×
88
                        addColumnForQuery: (self blockDelayUntilFirstChurnSince: period)
×
89
                        withName: columnName ]
×
90
]
×
91

92
{ #category : #'as yet unclassified' }
93
GitMetricExporter >> addEntitiesFromUserNames: userNames [
×
94

×
95
        projectCache := projectCache ifNil: [
×
96
                                glhImporter importProjectsSince: sinceTimeLimit ].
×
97

×
98
        entities addAll: (userNames collect: [ :username |
×
99
                         | projects metrics |
×
100
                         projects := self findProjectsOfUser: username inside: projectCache.
×
101

×
102
                         metrics := GitMetric4User new.
×
103
                         metrics
×
104
                                 glhImporter: glhImporter;
×
105
                                 findUserNamed: username.
×
NEW
106
                        
×
NEW
107
                         metrics itsProjects: (projects collect: [ :p |
×
NEW
108
                                        MyLogs logProgress: 'complete import of project #' over: projects.
×
NEW
109
                                         
×
110
                                          p id -> (glhImporter completeImportProject: p) ]) asDictionary.
×
111

×
112
                         metrics ]).
×
113

×
114
        ^ self
×
115
]
×
116

117
{ #category : #'as yet unclassified' }
118
GitMetricExporter >> addEntitiesFromUserNamesAndProjects: usersWithProjects [
×
119

×
120
        entities addAll: (usersWithProjects associations collect: [ :assoc |
×
121
                            | username projects metrics |
×
122
                            username := assoc key.
×
123
                            projects := assoc value.
×
124

×
125
                            metrics := GitMetric4User new.
×
126
                            metrics
×
127
                                    glhImporter: glhImporter;
×
128
                                    findUserNamed: username.
×
129
                            metrics loadProjects: projects.
×
130

×
131
                            metrics ]).
×
132

×
133
        ^ self
×
134
]
×
135

136
{ #category : #'as yet unclassified' }
137
GitMetricExporter >> addFrequencyCommitExporter: exportBrowserModel [
×
138

×
139
        | columnName |
×
140
        runningPeriods do: [ :period |
×
141
                columnName := ('commits frequency (avg) ' , period printString)
×
142
                                      asSymbol.
×
143

×
144
                exportBrowserModel
×
145
                        addColumnForQuery: (self blockCommitFrequencySince: period)
×
146
                        withName: columnName ]
×
147
]
×
148

149
{ #category : #'as yet unclassified' }
150
GitMetricExporter >> addMergeRequestDurationExporter: exportBrowserModel [
×
151

×
152
        | columnName |
×
153
        runningPeriods do: [ :period |
×
154
                columnName := ('merge Request Duration ' , period printString)
×
155
                                      asSymbol.
×
156

×
157
                exportBrowserModel
×
158
                        addColumnForQuery: (self blockMergeRequestDurationSince: period)
×
159
                        withName: columnName ]
×
160
]
×
161

162
{ #category : #adding }
NEW
163
GitMetricExporter >> addPeriodFrom: since to: until [
×
NEW
164

×
NEW
165
        runningPeriods add: {
×
NEW
166
                        (#since -> since asDate).
×
NEW
167
                        (#until -> until asDate) } asDictionary.
×
NEW
168
        
×
NEW
169
        ^runningPeriods 
×
NEW
170
]
×
171

172
{ #category : #'as yet unclassified' }
173
GitMetricExporter >> beforeDic: aDictionnarySinceUntil [
×
174

×
NEW
175
        self
×
NEW
176
                deprecated: 'Use #addPeriodFrom:to: instead'
×
NEW
177
                on: '11 July 2024'
×
NEW
178
                in:
×
NEW
179
                'Pharo-11.0.0+build.726.sha.aece1b5473acf3830a0e082c1bc3a15d4ff3522b (64 Bit)'.
×
NEW
180

×
181
        beforeExp := aDictionnarySinceUntil
×
182
]
×
183

184
{ #category : #'as yet unclassified' }
185
GitMetricExporter >> blockCodeAdditionSince: period [
×
186

×
187
        ^ [ :metrics |
×
188
          ((metrics
×
189
                    codeContributionsSince: (period at: #since)
×
190
                    until: (period at: #until)
×
191
                    overA: over) at: #avgAddition) printString ]
×
192
]
×
193

194
{ #category : #'as yet unclassified' }
195
GitMetricExporter >> blockCodeChurnSince: period [
×
196
        "comment stating purpose of instance-side method"
×
197

×
198
        "scope: class-variables  &  instance-variables"
×
199

×
200
        ^ [ :metrics |
×
201
          ((metrics
×
202
                    codeChurnSince: (period at: #since)
×
203
                    until: (period at: #until)
×
204
                    onACommitWindowOf: maxCommitWindow
×
205
                    overA: over) at: #churn) printString ]
×
206
]
×
207

208
{ #category : #'as yet unclassified' }
209
GitMetricExporter >> blockCodeDeletionSince: period [
×
210

×
211
        ^ [ :metrics |
×
212
          ((metrics
×
213
                    codeContributionsSince: (period at: #since)
×
214
                    until: (period at: #until)
×
215
                    overA: over) at: #avgDeletion) printString ]
×
216
]
×
217

218
{ #category : #'as yet unclassified' }
219
GitMetricExporter >> blockCommentsContributionSince: period [
×
220

×
221
        ^ [ :metrics |
×
222
          ((metrics
×
223
                    commentsContributionsSince: (period at: #since)
×
224
                    until: (period at: #until)
×
225
                    overA: over) at: #avgComments) printString ]
×
226
]
×
227

228
{ #category : #'as yet unclassified' }
229
GitMetricExporter >> blockCommitFrequencySince: period [
×
230

×
231
        ^ [ :metrics |
×
232
          ((metrics
×
233
                    commitFrequencySince: (period at: #since)
×
234
                    until: (period at: #until)
×
235
                    overA: over) at: #averageFloat) printString ]
×
236
]
×
237

238
{ #category : #'as yet unclassified' }
239
GitMetricExporter >> blockDelayUntilFirstChurnSince: period [
×
240
        "comment stating purpose of instance-side method"
×
241

×
242
        "scope: class-variables  &  instance-variables"
×
243

×
244
        ^ [ :metrics |
×
245
          ((metrics
×
246
                    delayUntilFirstChurnSince: (period at: #since)
×
247
                    until: (period at: #until)
×
248
                         onACommitWindowOf: maxCommitWindow
×
249
                    overA: over) at: #avgDelay) printString ]
×
250
]
×
251

252
{ #category : #'as yet unclassified' }
253
GitMetricExporter >> blockMergeRequestDurationSince: period [
×
254
        
×
255
        ^ [ :metrics |
×
256
                                Smalltalk snapshot: true andQuit: false.
×
257
                                ((metrics
×
258
                                          mergeRequestDurationSince: (period at: #since)
×
259
                                          until: (period at: #until)
×
260
                                          overA: over) at: #avgDuration) printString ]
×
261
]
×
262

263
{ #category : #'as yet unclassified' }
264
GitMetricExporter >> constructFilePath: runningOver [
×
265

×
266
        | file |
×
267
        file := (FileLocator home
×
268
                 /
×
269
                         ('GitlabHealth-' , label printString , '-' , runningOver printString
×
270
                          , '-'
×
271
                          , (DateAndTime now printString replaceAll: $: with: $-)
×
272
                          , '.csv')) asFileReference.
×
273
        ^ file
×
274
]
×
275

276
{ #category : #'as yet unclassified' }
277
GitMetricExporter >> debugExportOver: aCollectionOfDateWeekMonthOrYear [
×
278

×
279
        | period |
×
280
        over := Week.
×
281

×
282
        period := runningPeriods second.
×
283

×
284

×
285
        1 halt.
×
286
        "Code Contribution "
×
287
        entities collect: (self blockCodeAdditionSince: period).
×
288
        entities collect: (self blockCodeDeletionSince: period).
×
289

×
290
        "Commit frequencies "
×
291
        entities collect: (self blockCommitFrequencySince: period).
×
292

×
293
        "comment contribution "
×
294
        entities collect: (self blockCommentsContributionSince: period).
×
295

×
296
        "merge Request Duration "
×
297
        entities collect: (self blockMergeRequestDurationSince: period).
×
298

×
299
        "code churn"
×
300
        entities collect: (self blockCodeChurnSince: period).
×
301

×
302
        "delay Until First Churn"
×
303
        entities collect: (self blockDelayUntilFirstChurnSince: period).
×
304

×
305

×
306
        'Done computing debug' recordInfo
×
307
]
×
308

309
{ #category : #'as yet unclassified' }
310
GitMetricExporter >> duringDic: aDictionnarySinceUntil [
×
NEW
311

×
NEW
312
        self
×
NEW
313
                deprecated: 'Use #addPeriodFrom:to: instead'
×
NEW
314
                on: '11 July 2024'
×
NEW
315
                in:
×
NEW
316
                'Pharo-11.0.0+build.726.sha.aece1b5473acf3830a0e082c1bc3a15d4ff3522b (64 Bit)'.
×
NEW
317

×
318
        duringExp := aDictionnarySinceUntil
×
319
]
×
320

321
{ #category : #accessing }
322
GitMetricExporter >> entities: aCollection [ 
×
323
        entities := aCollection
×
324
]
×
325

326
{ #category : #'as yet unclassified' }
327
GitMetricExporter >> exportFor: usersWithProjects [
×
328

×
329
        self exportFor: usersWithProjects over: { Date. Week . Month . Year }.
×
330
]
×
331

332
{ #category : #'as yet unclassified' }
333
GitMetricExporter >> exportFor: usersWithProjects over: aCollectionOfDateWeekMonthOrYear [
×
334

×
335
        entities ifNil: [
×
336
                self addEntitiesFromUserNamesAndProjects: usersWithProjects ].
×
337

×
338
        self exportFor: aCollectionOfDateWeekMonthOrYear. 
×
339
]
×
340

341
{ #category : #'as yet unclassified' }
342
GitMetricExporter >> exportOver: aCollectionOfDateWeekMonthOrYear [
×
343

×
344
        | file exportBrowserModel |
×
345
        exportBrowserModel := MiExportModel new.
×
346
        exportBrowserModel entitiesList: entities.
×
347
        exportBrowserModel removeColumnForQueryNamed: #Type.
×
348
        exportBrowserModel removeColumnForQueryNamed: #Name.
×
349

×
350
        exportBrowserModel
×
351
                addColumnForQuery: [ :metrics | metrics user name printString ]
×
352
                withName: #'User name'.
×
353

×
354
        "Code Contribution "
×
355
        self addContributionExporter: exportBrowserModel.
×
356

×
357
        "Commit frequencies "
×
358
        self addFrequencyCommitExporter: exportBrowserModel.
×
359

×
360
        "comment contribution "
×
361
        self addCommentContributionExporter: exportBrowserModel.
×
362

×
363
        "merge Request Duration "
×
364
        self addMergeRequestDurationExporter: exportBrowserModel.
×
365

×
366
        "code churn"
×
367
        self addCodeChurnExporter: exportBrowserModel.
×
368

×
369
        "delay Until First Churn"
×
370
        self addDelayUntilFirstChurnExporter: exportBrowserModel.
×
371

×
372
        aCollectionOfDateWeekMonthOrYear do: [ :aDateWeekMonthOrYear |
×
373
                over := aDateWeekMonthOrYear.
×
374
                file := self constructFilePath: over.
×
375

×
376
                file writeStreamDo: [ :aStream |
×
377
                        aStream
×
378
                                << 'sep=,';
×
379
                                << OSPlatform current lineEnding.
×
380
                        exportBrowserModel writeCSVOn: aStream ] ].
×
381

×
382
        'Done computing' recordInfo
×
383
]
×
384

385
{ #category : #'as yet unclassified' }
386
GitMetricExporter >> findProjectsOfUser: aCollection [ 
×
387
        self shouldBeImplemented.
×
388
]
×
389

390
{ #category : #projects }
391
GitMetricExporter >> findProjectsOfUser: username inside: aCollectionOfProjects [
×
392

×
393
        | response itsProjects |
×
394
        itsProjects := aCollectionOfProjects select: [ :project |
×
395
                               response := glhImporter glhApi
×
396
                                                   commitsOfUser: username
×
397
                                                   inProject: project id since: '01 january 2023' asDateAndTime  until: '24 may 2024' asDateAndTime.
×
398
                               response := glhImporter parseCommitsResult: response.
×
399

×
400
                               response isNotEmpty ].
×
401

×
402
        ^ itsProjects
×
403
]
×
404

405
{ #category : #accessing }
406
GitMetricExporter >> glhImporter: anImporter [
×
407

×
408
        glhImporter := anImporter withInitialCommits: false; yourself. 
×
409
]
×
410

411
{ #category : #initialization }
412
GitMetricExporter >> initialize [
×
413

×
414
        entities := OrderedCollection new.
×
NEW
415
        "set up the minimal date from which we are looking for the commits a particular user in projects"
×
NEW
416
        sinceTimeLimit := '1 january 2024' asDateAndTime.
×
NEW
417
        runningPeriods := OrderedCollection new.
×
NEW
418
        maxCommitWindow := 3.
×
419
        over := Date
×
420
]
×
421

422
{ #category : #accessing }
423
GitMetricExporter >> label: aString [ 
×
424
        label := aString
×
425
]
×
426

427
{ #category : #accessing }
NEW
428
GitMetricExporter >> maxCommitWindow: anInteger [
×
NEW
429
        maxCommitWindow := anInteger abs
×
NEW
430
]
×
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