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

moosetechnology / GitProjectHealth / 10181483665

31 Jul 2024 01:47PM UTC coverage: 31.966%. First build
10181483665

Pull #14

github

web-flow
Merge ebbeae3d7 into 95cdd7973
Pull Request #14: fix loading commit and add API global access support to some metrics

1 of 3 new or added lines in 2 files covered. (33.33%)

2533 of 7924 relevant lines covered (31.97%)

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

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

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

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

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

36
{ #category : #'as yet unclassified' }
37
GitMetricExporter >> addCodeChurnExporter: exportBrowserModel [
×
38

×
39
        | columnName |
×
40
        maxCommitWindow := 3.
×
41
        runningPeriods do: [ :period |
×
42
                columnName := ('churn % (W=' , maxCommitWindow printString , ') '
×
43
                               , period printString) asSymbol.
×
44

×
45
                exportBrowserModel
×
46
                        addColumnForQuery: (self blockCodeChurnSince: period)
×
47
                        withName: columnName.
×
48

×
49
         ].
×
50
]
×
51

52
{ #category : #'as yet unclassified' }
53
GitMetricExporter >> addCommentContributionExporter: exportBrowserModel [
×
54

×
55
        | columnName |
×
56
        Smalltalk snapshot: true andQuit: false.
×
57

×
58
        runningPeriods do: [ :period |
×
59
                columnName := ('comment contribution (avg) ' , period printString)
×
60
                                      asSymbol.
×
61

×
62
                exportBrowserModel
×
63
                        addColumnForQuery: (self blockCommentsContributionSince: period)
×
64
                        withName: columnName ]
×
65
]
×
66

67
{ #category : #'as yet unclassified' }
68
GitMetricExporter >> addContributionExporter: exportBrowserModel [
×
69

×
70
        | columnName |
×
71
        "Code Contribution "
×
72
        runningPeriods do: [ :period |
×
73
                columnName := ('code addition (avg) ' , period printString) asSymbol.
×
74

×
75
                exportBrowserModel
×
76
                        addColumnForQuery: (self blockCodeAdditionSince: period)
×
77
                        withName: columnName.
×
78

×
79
                columnName := ('code deletion (avg) ' , period printString) asSymbol.
×
80
                exportBrowserModel
×
81
                        addColumnForQuery: (self blockCodeDeletionSince: period)
×
82
                        withName: columnName.
×
83

×
84
         ]
×
85
]
×
86

87
{ #category : #'as yet unclassified' }
88
GitMetricExporter >> addDelayUntilFirstChurnExporter: exportBrowserModel [
×
89

×
90
        | columnName |
×
91
        runningPeriods do: [ :period |
×
92
                columnName := ('delay Until First Churn (W=' , maxCommitWindow printString , ') '
×
93
                               , period printString) asSymbol.
×
94

×
95
                exportBrowserModel
×
96
                        addColumnForQuery: (self blockDelayUntilFirstChurnSince: period)
×
97
                        withName: columnName ]
×
98
]
×
99

100
{ #category : #'as yet unclassified' }
101
GitMetricExporter >> addEntitiesFromUserNames: userNames [
×
102
        "import all the project since a certain time"
×
103

×
104
        'Import all projects from the Git repository' recordInfo.
×
105
        projectCache := projectCache ifNil: [
×
106
                                glhImporter importProjectsSince: sinceTimeLimit ].
×
107

×
108
        "then collect the project in which the user has be seen commited"
×
109
        entities addAll: (userNames collect: [ :username |
×
110
                         | projects metrics i size |
×
111
                         projects := self findParticipationOfCommitAuthorNamed: username amongProjects: projectCache.
×
112

×
113
                         metrics := GitMetric4User new.
×
114
                         metrics
×
115
                                 glhImporter: glhImporter;
×
116
                                 findUserNamed: username.
×
117

×
118

×
119

×
120
                         i := 0.
×
121
                         size := projects size.
×
122
                         metrics itsProjects: (projects collect: [ :p |
×
123
                                          (' ' join: {
×
124
                                                           'complete import of project:'.
×
125
                                                           p name printString.
×
126
                                                           '['.
×
127
                                                           (i := i + 1) printString.
×
128
                                                           '/'.
×
129
                                                           size.
×
130
                                                           ']' }) recordInfo.
×
131

×
132
                                          p id -> (glhImporter completeImportProject: p) ]) asDictionary.
×
133

×
134
                         metrics ]).
×
135

×
136
        ^ self
×
137
]
×
138

139
{ #category : #'as yet unclassified' }
140
GitMetricExporter >> addEntitiesFromUserNamesAndProjects: usersWithProjects [
×
141

×
142
        entities addAll: (usersWithProjects associations collect: [ :assoc |
×
143
                            | username projects metrics |
×
144
                            username := assoc key.
×
145
                            projects := assoc value.
×
146

×
147
                            metrics := GitMetric4User new.
×
148
                            metrics
×
149
                                    glhImporter: glhImporter;
×
150
                                    findUserNamed: username.
×
151
                            metrics loadProjectsFromIds: projects.
×
152

×
153
                            metrics ]).
×
154

×
155
        ^ self
×
156
]
×
157

158
{ #category : #'as yet unclassified' }
159
GitMetricExporter >> addFrequencyCommitExporter: exportBrowserModel [
×
160

×
161
        | columnName |
×
162
        runningPeriods do: [ :period |
×
163
                columnName := ('commits frequency (avg) ' , period printString)
×
164
                                      asSymbol.
×
165

×
166
                exportBrowserModel
×
167
                        addColumnForQuery: (self blockCommitFrequencySince: period)
×
168
                        withName: columnName ]
×
169
]
×
170

171
{ #category : #'as yet unclassified' }
172
GitMetricExporter >> addMergeRequestDurationExporter: exportBrowserModel [
×
173

×
174
        | columnName |
×
175
        runningPeriods do: [ :period |
×
176
                columnName := ('merge Request Duration ' , period printString)
×
177
                                      asSymbol.
×
178

×
179
                exportBrowserModel
×
180
                        addColumnForQuery: (self blockMergeRequestDurationSince: period)
×
181
                        withName: columnName ]
×
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
          
×
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 := Date.
×
281

×
282
        period := runningPeriods first.
×
283

×
284

×
285
        1 halt.
×
286
        "Code Contribution "
×
287

×
288
        (entities collect: (self blockCodeAdditionSince: period)) recordInfo.
×
289
        (entities collect: (self blockCodeDeletionSince: period)) recordInfo.
×
290

×
291
        "Commit frequencies "
×
292
        (entities collect: (self blockCommitFrequencySince: period))
×
293
                recordInfo.
×
294

×
295
        "comment contribution "
×
296
        (entities collect: (self blockCommentsContributionSince: period))
×
297
                recordInfo.
×
298

×
299
        "merge Request Duration "
×
300
        (entities collect: (self blockMergeRequestDurationSince: period))
×
301
                recordInfo.
×
302

×
303
        "code churn"
×
304
        (entities collect: (self blockCodeChurnSince: period)) recordInfo.
×
305

×
306
        "delay Until First Churn"
×
307
        (entities collect: (self blockDelayUntilFirstChurnSince: period))
×
308
                recordInfo.
×
309

×
310

×
311
        'Done computing debug' recordInfo
×
312
]
×
313

314
{ #category : #accessing }
315
GitMetricExporter >> entities: aCollection [ 
×
316
        entities := aCollection
×
317
]
×
318

319
{ #category : #'as yet unclassified' }
320
GitMetricExporter >> exportAverageOver: aCollectionOfDateWeekMonthOrYear [
×
321

×
322
        | file exportBrowserModel |
×
323
        exportBrowserModel := MiExportModel new.
×
324
        exportBrowserModel entitiesList: entities.
×
325
        exportBrowserModel removeColumnForQueryNamed: #Type.
×
326
        exportBrowserModel removeColumnForQueryNamed: #Name.
×
327

×
328
        exportBrowserModel
×
329
                addColumnForQuery: [ :metrics | metrics user name printString ]
×
330
                withName: #'User name'.
×
331

×
332
        "Code Contribution "
×
333
        self addContributionExporter: exportBrowserModel.
×
334

×
335
        "Commit frequencies "
×
336
        self addFrequencyCommitExporter: exportBrowserModel.
×
337

×
338
        "comment contribution "
×
339
        self addCommentContributionExporter: exportBrowserModel.
×
340

×
341
        "merge Request Duration "
×
342
        self addMergeRequestDurationExporter: exportBrowserModel.
×
343

×
344
        "code churn"
×
345
        self addCodeChurnExporter: exportBrowserModel.
×
346

×
347
        "delay Until First Churn"
×
348
        self addDelayUntilFirstChurnExporter: exportBrowserModel.
×
349
        
×
350
        self addMergeRequestDurationExporter: exportBrowserModel.
×
351

×
352
        aCollectionOfDateWeekMonthOrYear do: [ :aDateWeekMonthOrYear |
×
353
                over := aDateWeekMonthOrYear.
×
354
                file := self constructFilePath: over.
×
355

×
356
                file writeStreamDo: [ :aStream |
×
357
                        aStream
×
358
                                << 'sep=,';
×
359
                                << OSPlatform current lineEnding.
×
360
                        exportBrowserModel writeCSVOn: aStream ] ].
×
361

×
362
        'Done computing' recordInfo
×
363
]
×
364

365
{ #category : #'as yet unclassified' }
366
GitMetricExporter >> exportFor: usersWithProjects [
×
367

×
368
        self exportFor: usersWithProjects over: { Date. Week . Month . Year }.
×
369
]
×
370

371
{ #category : #'as yet unclassified' }
372
GitMetricExporter >> exportFor: usersWithProjects over: aCollectionOfDateWeekMonthOrYear [
×
373

×
374
        entities ifNil: [
×
375
                self addEntitiesFromUserNamesAndProjects: usersWithProjects ].
×
376

×
377
        self exportFor: aCollectionOfDateWeekMonthOrYear. 
×
378
]
×
379

380
{ #category : #projects }
381
GitMetricExporter >> findParticipationOfCommitAuthorNamed: username amongProjects: aCollectionOfProjects [
×
382

×
383
        | response itsProjects i size |
×
384
        i := 1.
×
385
        size := aCollectionOfProjects size.
×
386
        itsProjects := aCollectionOfProjects select: [ :project |
×
387
                               (' ' join: {
×
388
                                                'search'.
×
389
                                                username printString.
×
390
                                                'in Project:'.
×
391
                                                project name printString.
×
392
                                                '['.
×
393
                                                (i := i + 1) printString.
×
394
                                                '/'.
×
395
                                                size.
×
396
                                                ']' }) recordInfo.
×
397

×
398
                               response := glhImporter glhApi
×
399
                                                   commitsOfUser: username
×
400
                                                   inProject: project id
×
401
                                                   since: '01 january 2023' asDateAndTime
×
402
                                                   until: Date today asDateAndTime.
×
403
                               response := glhImporter parseCommitsResult: response.
×
NEW
404
                               response isNotEmpty
×
NEW
405
                 ].
×
406

×
407
        ^ itsProjects
×
408
]
×
409

410
{ #category : #'as yet unclassified' }
411
GitMetricExporter >> findProjectsOfUser: aCollection [ 
×
412
        self shouldBeImplemented.
×
413
]
×
414

415
{ #category : #accessing }
416
GitMetricExporter >> glhImporter: anImporter [
×
417

×
418
        glhImporter := anImporter withInitialCommits: false; yourself. 
×
419
]
×
420

421
{ #category : #initialization }
422
GitMetricExporter >> initialize [
×
423

×
424
        entities := OrderedCollection new.
×
425
        "set up the minimal date from which we are looking for the commits a particular user in projects"
×
426
        sinceTimeLimit := '1 january 2024' asDateAndTime.
×
427
        runningPeriods := OrderedCollection new.
×
428
        maxCommitWindow := 3.
×
429
        over := Date
×
430
]
×
431

432
{ #category : #accessing }
433
GitMetricExporter >> label: aString [ 
×
434
        label := aString
×
435
]
×
436

437
{ #category : #accessing }
438
GitMetricExporter >> maxCommitWindow: anInteger [
×
439
        maxCommitWindow := anInteger abs
×
440
]
×
441

442
{ #category : #'as yet unclassified' }
443
GitMetricExporter >> onlyImportProjectsOfGroup: groupId [
×
444

×
445
        | group |
×
446
        group := GLHModelImporter current importGroup: groupId.
×
447
        projectCache := (group toScope: GLHProject)
×
448
]
×
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