• 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/GitMetric4User.class.st
1
Class {
2
        #name : #GitMetric4User,
3
        #superclass : #GitMetric,
4
        #instVars : [
5
                'itsCommits',
6
                'itsMergeRequests'
7
        ],
8
        #category : #'GitLabHealth-Model-Analysis'
9
}
10

11
{ #category : #churn }
12
GitMetric4User >> codeChurnSince: since until: until onACommitWindowOf: commitLimit overA: aDateWeekMonthOrYear [
×
13

×
14
        | commits res groupedByDate totalContributions userCommits |
×
15
        "for each commit, we get its churn result (a dictionnary)"
×
16
        'GitMetric4User: code churn' recordInfo.
×
17
        totalContributions := OrderedCollection new.
×
18
        groupedByDate := self
×
19
                                 setupGroupedDateFrom: since
×
20
                                 to: until
×
21
                                 over: aDateWeekMonthOrYear.
×
22
        gitAnalyzer := GitAnalyzer new
×
23
                               glhImporter: glhImporter;
×
24
                               onModel: glhModel;
×
25
                               maxChildCommit: commitLimit.
×
26
        glhImporter withCommitDiffs: false.
×
27
        commits := self
×
28
                           loadCommitsFromProjectsIds: itsProjects keys
×
29
                           since: since
×
30
                           until: until.
×
31
        glhImporter withCommitDiffs: true.
×
32
        userCommits := commits reject: [ :commit |
×
33
                               commit commitCreator ~= user ].
×
34
        commits := self
×
35
                           foundSuccessorOf: userCommits
×
36
                           andCompleteImportForMax: commitLimit.
×
37

×
38

×
39
        res := commits collect: [ :commit |
×
40
                       commit -> (gitAnalyzer
×
41
                                fromCommit: commit;
×
42
                                analyseChurn) ].
×
43
        res do: [ :commits4Churns |
×
44
                | commit allChurnsInCommit sumChurnInCommit overDate contribution churnOnCommit |
×
45
                commit := commits4Churns key.
×
46
                allChurnsInCommit := commits4Churns value.
×
47
                sumChurnInCommit := (allChurnsInCommit at: #churns) sum: [ :churn |
×
48
                                            | numerator |
×
49
                                            numerator := churn value at: #churnLoC.
×
50
                                            numerator ].
×
51
                contribution := allChurnsInCommit at: #totalContribution.
×
52
                totalContributions add: contribution.
×
53
                churnOnCommit := {
×
54
                                         (#churnOnCommit -> sumChurnInCommit).
×
55
                                         (#LoCOnCommit -> contribution) } asDictionary.
×
56
                overDate := self
×
57
                                    transformDate: commit created_at
×
58
                                    to: aDateWeekMonthOrYear.
×
59
                groupedByDate
×
60
                        at: overDate printString
×
61
                        ifPresent: [ :array | array add: churnOnCommit ]
×
62
                        ifAbsentPut: [
×
63
                                OrderedCollection new
×
64
                                        add: churnOnCommit;
×
65
                                        yourself ] ].
×
66
        groupedByDate := groupedByDate collect: [ :churnsAtDate |
×
67
                                 | totalChurn totalContribution percentage |
×
68
                                 totalChurn := churnsAtDate sum: [ :churn |
×
69
                                                       churn at: #churnOnCommit ].
×
70
                                 totalContribution := churnsAtDate sum: [ :churn |
×
71
                                                              churn at: #LoCOnCommit ].
×
72
                                 totalContribution = 0
×
73
                                         ifTrue: [ percentage := 0 asFloat ]
×
74
                                         ifFalse: [
×
75
                                         percentage := (totalChurn * 100
×
76
                                                        / totalContribution) asFloat ].
×
77
                                 {
×
78
                                         (#churn -> totalChurn).
×
79
                                         (#contribution -> totalContribution).
×
80
                                         (#percentage -> percentage) } asDictionary ].
×
81
        ^ {
×
82
                  (#details -> groupedByDate).
×
83
                  (#totalContribution -> (totalContributions
×
84
                            ifEmpty: [ 0 ]
×
85
                            ifNotEmpty: [ totalContributions sum ])).
×
86
                  (#totalChurn -> (groupedByDate sum: [ :date | date at: #churn ])).
×
87
                  (#churn
×
88
                   ->
×
89
                   (groupedByDate collect: [ :date | date at: #percentage ]) average).
×
90
                  (#overEach -> aDateWeekMonthOrYear name).
×
91
                  (#forOver -> (groupedByDate keys size printString
×
92
                    , aDateWeekMonthOrYear printString)).
×
93
                  (#userCommits -> commits size).
×
94
                  (#churnWindow -> commitLimit) } asDictionary
×
95
]
×
96

97
{ #category : #metrics }
98
GitMetric4User >> codeContributionsSince: since until: until overA: aDateWeekMonthOrYear [
×
99

×
100
        | commits contributions groupedByDate |
×
101
        'GitMetric4User: code contribution' recordInfo.
×
102

×
103
        groupedByDate := self
×
104
                                 setupGroupedDateFrom: since
×
105
                                 to: until
×
106
                                 over: aDateWeekMonthOrYear.
×
107

×
108
        gitAnalyzer := GitAnalyzer new
×
109
                               onModel: glhModel;
×
110
                               glhImporter: glhImporter.
×
111

×
112
        glhImporter withCommitDiffs: false.
×
113
        commits := self
×
114
                           loadCommitsFromProjectsIds: itsProjects keys
×
115
                           since: since
×
116
                           until: until.
×
117
        glhImporter withCommitDiffs: true.
×
118
        commits := commits reject: [ :commit | commit commitCreator ~= user ].
×
119

×
120
        contributions := commits collect: [ :commit |
×
121
                                 commit -> (gitAnalyzer
×
122
                                          fromCommit: commit;
×
123
                                          analyseCommitContribution) ].
×
124

×
125
        contributions do: [ :assoc |
×
126
                | dateOver |
×
127
                dateOver := self
×
128
                                    transformDate: assoc key created_at
×
129
                                    to: aDateWeekMonthOrYear.
×
130
                groupedByDate
×
131
                        at: dateOver printString
×
132
                        ifPresent: [ :v | v add: assoc value ]
×
133
                        ifAbsentPut: [
×
134
                                OrderedCollection new
×
135
                                        add: assoc value;
×
136
                                        yourself ] ].
×
137

×
138
        groupedByDate := groupedByDate collect: [ :contribs |
×
139
                                 | totalAdd totalDele |
×
140
                                 totalAdd := contribs sum: [ :v | v at: #addition ].
×
141
                                 totalDele := contribs sum: [ :v | v at: #deletion ].
×
142
                                 {
×
143
                                         (#addition -> totalAdd).
×
144
                                         (#deletion -> totalDele) } asDictionary ].
×
145

×
146
        ^ {
×
147
                  (#overEach -> aDateWeekMonthOrYear name).
×
148
                  (#forOver -> (groupedByDate keys size printString
×
149
                    , aDateWeekMonthOrYear printString)).
×
150
                  (#avgAddition
×
151
                   ->
×
152
                   (groupedByDate collect: [ :d | d at: #addition ]) average asFloat).
×
153
                  (#avgDeletion
×
154
                   ->
×
155
                   (groupedByDate collect: [ :d | d at: #deletion ]) average asFloat).
×
156
                  (#details -> groupedByDate).
×
157
                  (#userCommits -> commits size) } asDictionary
×
158
]
×
159

160
{ #category : #metrics }
161
GitMetric4User >> commentsContributionsSince: since until: until overA: aDateWeekMonthOrYear [
×
162

×
163
        | commits contributions groupedByDate |
×
164
        'GitMetric4User: comment contribution' recordInfo.
×
165

×
166
        groupedByDate := self
×
167
                                 setupGroupedDateFrom: since
×
168
                                 to: until
×
169
                                 over: aDateWeekMonthOrYear.
×
170

×
171
        gitAnalyzer := GitAnalyzer new
×
172
                               onModel: glhModel;
×
173
                               glhImporter: glhImporter.
×
174

×
175
        glhImporter withCommitDiffs: false.
×
176
        commits := self
×
177
                           loadCommitsFromProjectsIds: itsProjects keys
×
178
                           since: since
×
179
                           until: until.
×
180
        glhImporter withCommitDiffs: true.
×
181
        commits := commits reject: [ :commit | commit commitCreator ~= user ].
×
182
        commits do: [ :commit | glhImporter completeImportedCommit: commit ].
×
183

×
184

×
185
        contributions := commits collect: [ :commit |
×
186
                                 commit -> (gitAnalyzer
×
187
                                          fromCommit: commit;
×
188
                                          analyseCommentContribution) ].
×
189

×
190

×
191
        contributions do: [ :assoc |
×
192
                | dateOver |
×
193
                dateOver := self
×
194
                                    transformDate: assoc key created_at
×
195
                                    to: aDateWeekMonthOrYear.
×
196
                groupedByDate
×
197
                        at: dateOver printString
×
198
                        ifPresent: [ :v | v add: assoc value ]
×
199
                        ifAbsentPut: [
×
200
                                OrderedCollection new
×
201
                                        add: assoc value;
×
202
                                        yourself ] ].
×
203

×
204
        groupedByDate := groupedByDate collect: [ :contribs |
×
205
                                 contribs
×
206
                                         ifNotEmpty: [ contribs sum ]
×
207
                                         ifEmpty: [ 0 ] ].
×
208

×
209

×
210
        ^ {
×
211
                  (#details -> groupedByDate).
×
212
                  (#totalComments -> groupedByDate values sum).
×
213
                  (#avgComments -> groupedByDate values average asFloat).
×
214
                  (#overEach -> aDateWeekMonthOrYear name).
×
215
                  (#forOver -> (groupedByDate keys size printString
×
216
                    , aDateWeekMonthOrYear printString)).
×
217
                  (#userCommits -> commits size) } asDictionary
×
218
]
×
219

220
{ #category : #metrics }
221
GitMetric4User >> commitFrequencySince: since until: until overA: aDateWeekMonthOrYear [
×
222

×
223
        | periods total groupedByDate userCommits |
×
224
        'GitMetric4User: commit frequency' recordInfo.
×
225

×
226
        groupedByDate := self
×
227
                                 setupGroupedDateFrom: since
×
228
                                 to: until
×
229
                                 over: aDateWeekMonthOrYear.
×
230

×
231
        glhImporter withCommitDiffs: false.
×
232
        userCommits := self
×
233
                               loadCommitsFromProjectsIds: itsProjects keys
×
234
                               since: since
×
235
                               until: until.
×
236
        glhImporter withCommitDiffs: true.
×
237
        userCommits := userCommits reject: [ :c | c commitCreator ~= user ].
×
238

×
239
        userCommits do: [ :c |
×
240
                | dateOver |
×
241
                dateOver := self
×
242
                                    transformDate: c created_at
×
243
                                    to: aDateWeekMonthOrYear.
×
244
                groupedByDate at: dateOver printString ifPresent: [ :v | v add: c ] ].
×
245

×
246
        periods := groupedByDate keys size.
×
247
        total := groupedByDate values sum: [ :commits | commits size ].
×
248

×
249

×
250
        ^ {
×
251
                  (#averageFrac -> (total / periods)).
×
252
                  (#averageFloat -> (total / periods) asFloat).
×
253
                  (#userCommit -> total).
×
254
                  (#forOver -> (groupedByDate keys size printString
×
255
                    , aDateWeekMonthOrYear printString)).
×
256
                  (#periode -> aDateWeekMonthOrYear name).
×
257
                  (#details -> groupedByDate) } asOrderedDictionary
×
258
]
×
259

260
{ #category : #metrics }
261
GitMetric4User >> commitsProducedOnProject: projectId since: sinceDate until: untilDate [
×
262

×
263
        | frequencies |
×
264
        
×
265
        
×
266
        gitAnalyzer := GitAnalyzer new 
×
267
        glhImporter: glhImporter; 
×
268
        onModel: glhModel.
×
269
         
×
270
        frequencies := gitAnalyzer
×
271
                               onProject: (itsProjects at: projectId);
×
272
                               analyseCommitFrequencySince: sinceDate
×
273
                               until: untilDate. 
×
274
        
×
275
        "complete each commit "
×
276
        frequencies values flattened do: [ :commit |
×
277
                glhImporter completeImportedCommit: commit.
×
278
                 ].
×
279
        
×
280
        "Filter the associations in the 'frequencies' collection, removing any commits not created by the specified 'user'. "
×
281
        frequencies associations do: [ :assoc |
×
282
                |commits| 
×
283
                commits := assoc value.
×
284
                assoc value: (commits reject: [ :commit | commit commitCreator ~= user ]). 
×
285
        ].
×
286
        
×
287
        ^ frequencies 
×
288
]
×
289

290
{ #category : #metrics }
291
GitMetric4User >> commitsProducedOnProject: aProjectId since: since until: until overA: aWeekOrMonthOrYear [
×
292
        "'aWeekOrMonthOrYear' should be the class of Data, Week, Month or Year"
×
293

×
294
        | frequency aggregatedFrequencies |
×
295
        aggregatedFrequencies := self
×
296
                                         setupGroupedDateFrom: since
×
297
                                         to: until
×
298
                                         over: aWeekOrMonthOrYear.
×
299

×
300
        frequency := self
×
301
                             commitsProducedOnProject: aProjectId
×
302
                             since: since
×
303
                             until: until.
×
304

×
305
        frequency associations do: [ :assoc |
×
306
                | date commits overDate |
×
307
                date := assoc key.
×
308
                commits := assoc value.
×
309

×
310
                commits ifNotEmpty: [ " convert the date as its week date. For some english reason, the week start in sunday so we should add a + 1 day "
×
311
                        overDate := self transformDate: date to: aWeekOrMonthOrYear.
×
312
                        aggregatedFrequencies
×
313
                                at: overDate printString
×
314
                                ifPresent: [ :collection | collection addAll: commits ]
×
315
                                ifAbsentPut: [ commits ] ] ].
×
316

×
317
        ^ aggregatedFrequencies
×
318
]
×
319

320
{ #category : #churn }
321
GitMetric4User >> delayUntilFirstChurnSince: since until: until onACommitWindowOf: maxCommitWindow overA: aDateWeekMonthOrYear [
×
322

×
323
        | commits groupedByDate res avg userCommits |
×
324
        'GitMetric4User: delay until first churn' recordInfo.
×
325

×
326
        groupedByDate := self
×
327
                                 setupGroupedDateFrom: since
×
328
                                 to: until
×
329
                                 over: aDateWeekMonthOrYear.
×
330

×
331
        glhImporter withCommitDiffs: false.
×
332
        commits := self
×
333
                           loadCommitsFromProjectsIds: itsProjects keys
×
334
                           since: since
×
335
                           until: until.
×
336
        glhImporter withCommitDiffs: true.
×
337

×
338
        userCommits := commits reject: [ :commit |
×
339
                               commit commitCreator ~= user ].
×
340
        commits := self
×
341
                           foundSuccessorOf: userCommits
×
342
                           andCompleteImportForMax: maxCommitWindow.
×
343

×
344

×
345
        "class commit by dates, filter none user commits"
×
346
        commits do: [ :commit |
×
347
                commit commitCreator = user ifTrue: [
×
348
                        | overDate |
×
349
                        overDate := self
×
350
                                            transformDate: commit created_at
×
351
                                            to: aDateWeekMonthOrYear.
×
352

×
353
                        groupedByDate
×
354
                                at: overDate printString
×
355
                                ifPresent: [ :arrayOfCommits | arrayOfCommits add: commit ]
×
356
                                ifAbsentPut: [
×
357
                                        OrderedCollection new
×
358
                                                add: commit;
×
359
                                                yourself ] ] ].
×
360

×
361

×
362

×
363
        res := groupedByDate collect: [ :commits4Date |
×
364
                       | durationFromA2B |
×
365
                       commits4Date collect: [ :commitA |
×
366
                               | commitB |
×
367
                               commitB := GitAnalyzer new
×
368
                                                  glhImporter: glhImporter;
×
369
                                                  onModel: glhModel;
×
370
                                                  fromCommit: commitA;
×
371
                                                  maxChildCommit: maxCommitWindow;
×
372
                                                  analyseDelayUntilFirstChurn.
×
373

×
374
                               durationFromA2B := commitB
×
375
                                                          ifNil: [ 0 ]
×
376
                                                          ifNotNil: [
×
377
                                                          commitB created_at - commitA created_at ].
×
378
                               durationFromA2B ] ].
×
379

×
380

×
381

×
382
        res := res collect: [ :durationsByDate |
×
383
                       | filtered |
×
384
                       filtered := durationsByDate reject: [ :value | value = 0 ].
×
385
                       filtered isEmpty
×
386
                               ifTrue: [ nil ]
×
387
                               ifFalse: [
×
388
                               (filtered sum: [ :v | v asDuration asSeconds]) / filtered size ] ].
×
389

×
390
        res := res reject: #isNil.
×
391

×
392
        res
×
393
                ifEmpty: [ avg := nil ]
×
394
                ifNotEmpty: [ avg := res values average asFloat ].
×
395

×
396

×
397
        ^ {
×
398
                  (#avgDelay -> avg).
×
399
                  (#overEach -> aDateWeekMonthOrYear name).
×
400
                  (#forOver -> (groupedByDate keys size printString
×
401
                    , aDateWeekMonthOrYear printString)).
×
402
                  (#details -> groupedByDate) } asDictionary
×
403
]
×
404

405
{ #category : #churn }
406
GitMetric4User >> delayUntilFirstChurnSince: since until: until overA: aDateWeekMonthOrYear [
×
407

×
408
        | commits groupedByDate res avg |
×
409
        self
×
410
                deprecated:
×
411
                'Use #delayUntilFirstChurnSince:until:onACommitWindowOf:overA: instead'
×
412
                on: '1 July 2024'
×
413
                in:
×
414
                'Pharo-11.0.0+build.726.sha.aece1b5473acf3830a0e082c1bc3a15d4ff3522b (64 Bit)'.
×
415

×
416
        'GitMetric4User: delay until first churn' recordInfo.
×
417

×
418
        groupedByDate := self
×
419
                                 setupGroupedDateFrom: since
×
420
                                 to: until
×
421
                                 over: aDateWeekMonthOrYear.
×
422

×
423
        commits := self
×
424
                           loadCommitsFromProjectsIds: itsProjects keys
×
425
                           since: since
×
426
                           until: until.
×
427

×
428
        "class commit by dates, filter none user commits"
×
429
        commits do: [ :commit |
×
430
                commit commitCreator = user ifTrue: [
×
431
                        | overDate |
×
432
                        overDate := self
×
433
                                            transformDate: commit created_at
×
434
                                            to: aDateWeekMonthOrYear.
×
435

×
436
                        groupedByDate
×
437
                                at: overDate printString
×
438
                                ifPresent: [ :arrayOfCommits | arrayOfCommits add: commit ]
×
439
                                ifAbsentPut: [
×
440
                                        OrderedCollection new
×
441
                                                add: commit;
×
442
                                                yourself ] ] ].
×
443

×
444

×
445

×
446
        res := groupedByDate collect: [ :commits4Date |
×
447
                       | durationFromA2B |
×
448
                       commits4Date collect: [ :commitA |
×
449
                               | commitB |
×
450
                               commitB := GitAnalyzer new
×
451
                                                  glhImporter: glhImporter;
×
452
                                                  onModel: glhModel;
×
453
                                                  fromCommit: commitA;
×
454
                                                  maxChildCommit: 5;
×
455
                                                  analyseDelayUntilFirstChurn.
×
456

×
457
                               durationFromA2B := commitB
×
458
                                                          ifNil: [ 0 ]
×
459
                                                          ifNotNil: [
×
460
                                                          commitB created_at - commitA created_at ].
×
461
                               durationFromA2B ] ].
×
462

×
463

×
464

×
465
        res := res collect: [ :durationsByDate |
×
466
                       | filtered |
×
467
                       filtered := durationsByDate reject: [ :value | value = 0 ].
×
468
                       filtered isEmpty
×
469
                               ifTrue: [ nil ]
×
470
                               ifFalse: [
×
471
                               (filtered sum: [ :v | v asDuration ]) / filtered size ] ].
×
472

×
473
        res := res reject: #isNil.
×
474

×
475
        res
×
476
                ifEmpty: [ avg := nil ]
×
477
                ifNotEmpty: [ avg := res values sum / res keys size ].
×
478

×
479

×
480
        ^ {
×
481
                  (#avgDelay -> avg).
×
482
                  (#overEach -> aDateWeekMonthOrYear name).
×
483
                  (#forOver -> (groupedByDate keys size printString
×
484
                    , aDateWeekMonthOrYear printString)).
×
485
                  (#details -> groupedByDate) } asDictionary
×
486
]
×
487

488
{ #category : #churn }
489
GitMetric4User >> foundSuccessorOf: userCommits andCompleteImportForMax: commitLimit [
×
490

×
491
        | analyzingCommits i size|
×
492
        analyzingCommits := Set new.
×
493
        glhImporter withCommitDiffs: true.
×
494

×
495
        userCommits do: [ :c |
×
496
                gitAnalyzer
×
497
                        visitChildCommits: c childCommits
×
498
                        toStoreThemIn: analyzingCommits
×
499
                        upto: commitLimit ].
×
500

×
501
        i := 0.
×
502
        size := analyzingCommits size. 
×
503
        analyzingCommits do: [ :c |
×
504
                ('import complete commits  [' , (i:=i+1) printString, '/', size printString , ']'  ) recordInfo.
×
505
                glhImporter completeImportedCommit: c ].
×
506

×
507
        ^ analyzingCommits
×
508
]
×
509

510
{ #category : #analysis }
NEW
511
GitMetric4User >> generateAnalysisForPeriod: period over: aDateWeekMonthOrYear withMaxCommitWindows: maxCommitWindow [
×
512

×
NEW
513
        | contribution commitFrequency commentContribution mergeRequestDuration codeChurn delayUntilFirstChurn |
×
514
        
×
NEW
515
                contribution := self
×
516
                                codeContributionsSince: (period at: #since)
×
517
                                until: (period at: #until)
×
NEW
518
                                overA: aDateWeekMonthOrYear.
×
519

×
NEW
520
                commitFrequency := self
×
521
                                    commitFrequencySince: (period at: #since)
×
522
                                    until: (period at: #until)
×
NEW
523
                                    overA: aDateWeekMonthOrYear.
×
524

×
NEW
525
                commentContribution := self
×
526
                                        commentsContributionsSince:
×
527
                                        (period at: #since)
×
528
                                        until: (period at: #until)
×
NEW
529
                                        overA: aDateWeekMonthOrYear.
×
530

×
NEW
531
                mergeRequestDuration := self
×
532
                                         mergeRequestDurationSince:
×
533
                                         (period at: #since)
×
534
                                         until: (period at: #until)
×
NEW
535
                                         overA: aDateWeekMonthOrYear.
×
536

×
NEW
537
                codeChurn := self
×
538
                              codeChurnSince: (period at: #since)
×
539
                              until: (period at: #until)
×
540
                              onACommitWindowOf: maxCommitWindow
×
NEW
541
                              overA: aDateWeekMonthOrYear.
×
542

×
NEW
543
                delayUntilFirstChurn := self
×
544
                                         delayUntilFirstChurnSince:
×
545
                                         (period at: #since)
×
546
                                         until: (period at: #until)
×
547
                                         onACommitWindowOf: maxCommitWindow
×
NEW
548
                                         overA: aDateWeekMonthOrYear.
×
NEW
549

×
NEW
550
                ^ AnalysisReport new
×
NEW
551
                          username: self user name;
×
NEW
552
                          period: period;
×
NEW
553
                          codeAddition: (contribution at: #avgAddition);
×
NEW
554
                          codeDeletion: (contribution at: #avgDeletion);
×
NEW
555
                          commitFrequency: (commitFrequency at: #averageFloat);
×
NEW
556
                          commentContribution: (commentContribution at: #avgComments);
×
NEW
557
                          mergeRequestDuration: (mergeRequestDuration at: #avgDuration);
×
NEW
558
                          codeChurn: (codeChurn at: #churn);
×
NEW
559
                          delayUntilFirstChurn: (delayUntilFirstChurn at: #avgDelay)
×
NEW
560
        
×
NEW
561
        
×
562
]
×
563

564
{ #category : #initialization }
565
GitMetric4User >> initialize [
×
566

×
567
        user := GLHUser new.
×
568
        itsProjects := Dictionary new.
×
569
        itsCommits := Dictionary new.
×
570
        itsMergeRequests := Dictionary new
×
571
]
×
572

573
{ #category : #accessing }
574
GitMetric4User >> itsProjects: projects [
×
575
        itsProjects := projects .
×
576
]
×
577

578
{ #category : #churn }
579
GitMetric4User >> loadCommitOfProjects: aCollection since: aTimespan [
×
580
        |commits|
×
581
        
×
582
        commits := (aCollection collect: [ :id |
×
583
                 glhImporter
×
584
                        importCommitsOProject: (itsProjects at: id)
×
585
                        since: aTimespan
×
586
                        until: nil ]) flattened.
×
587

×
588
        commits do: [ :commit |
×
589
                glhImporter completeImportedCommit: commit. 
×
590
                 ].
×
591

×
592
        ^ self userCommits.
×
593
]
×
594

595
{ #category : #metrics }
596
GitMetric4User >> mergeRequestDurationSince: since until: until overA: aDateWeekMonthOrYear [
×
597

×
598
        | mergeRequest res groupedByDate filterGroups avg |
×
599
        groupedByDate := self
×
600
                                 setupGroupedDateFrom: since
×
601
                                 to: until
×
602
                                 over: aDateWeekMonthOrYear.
×
603

×
604
        gitAnalyzer := GitAnalyzer new
×
605
                               glhImporter: glhImporter;
×
606
                               onModel: glhModel.
×
607

×
608
        glhImporter withCommitDiffs: false.
×
609
        mergeRequest := self
×
610
                                loadMergeRequestsFromProjectsIds: itsProjects keys
×
611
                                since: since
×
612
                                until: until.
×
613
        glhImporter withCommitDiffs: true.
×
614

×
615
        mergeRequest ifEmpty: [
×
616
                ^ {
×
617
                          (#avgDuration -> nil).
×
618
                          (#overEach -> aDateWeekMonthOrYear name).
×
619
                          (#forOver -> (groupedByDate keys size printString
×
620
                            , aDateWeekMonthOrYear printString)).
×
621
                          (#totalMergeRequest -> 0).
×
622
                          (#details -> nil) } asDictionary ].
×
623

×
624
        res := mergeRequest collect: [ :mr |
×
625
                       gitAnalyzer analyseMergeResquestValidation: mr ].
×
626

×
627

×
628
        res do: [ :dic |
×
629
                | overDate |
×
630
                overDate := self
×
631
                                    transformDate: (dic at: #created_at)
×
632
                                    to: aDateWeekMonthOrYear.
×
633

×
634
                groupedByDate
×
635
                        at: overDate printString
×
636
                        ifPresent: [ :durations | durations add: (dic at: #duration) ]
×
637
                        ifAbsentPut: [
×
638
                                OrderedCollection new
×
639
                                        add: (dic at: #duration);
×
640
                                        yourself ] ].
×
641

×
642

×
643
        filterGroups := groupedByDate reject: [ :array | array isEmpty ].
×
644

×
645
        filterGroups associations do: [ :assoc |
×
646
                | sum denominator |
×
647
                denominator := assoc value size.
×
648

×
649
                sum := assoc value sum: [ :v |
×
650
                               v ifNil: [
×
651
                                       denominator := denominator - 1.
×
652
                                       0 asDuration ] ].
×
653
                denominator = 0 ifTrue: [ denominator := 1 ].
×
654

×
655
                filterGroups at: assoc key put: sum / denominator ].
×
656

×
657

×
658
        filterGroups keys
×
659
                ifEmpty: [ avg := 0 ]
×
660
                ifNotEmpty: [
×
661
                avg := filterGroups values sum / filterGroups keys size ].
×
662

×
663

×
664
        ^ {
×
665
                  (#avgDuration -> avg).
×
666
                  (#overEach -> aDateWeekMonthOrYear name).
×
667
                  (#forOver -> (groupedByDate keys size printString
×
668
                    , aDateWeekMonthOrYear printString)).
×
669
                  (#totalMergeRequest -> mergeRequest size).
×
670
                  (#details -> groupedByDate) } asDictionary
×
671
]
×
672

673
{ #category : #accessing }
674
GitMetric4User >> user [
×
675
        ^ user
×
676
]
×
677

678
{ #category : #accessing }
679
GitMetric4User >> user: anUser [
×
680
        user := anUser. 
×
681
]
×
682

683
{ #category : #accessing }
684
GitMetric4User >> userCommits [
×
685
        ^ user commits
×
686
]
×
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