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

moosetechnology / GitProjectHealth / 11461547576

22 Oct 2024 01:44PM UTC coverage: 59.724% (+0.6%) from 59.117%
11461547576

push

github

web-flow
Merge pull request #85 from moosetechnology/feat/code-contribution-by-mr

feat(metrics): code contribution by mr

251 of 263 new or added lines in 5 files covered. (95.44%)

1 existing line in 1 file now uncovered.

9449 of 15821 relevant lines covered (59.72%)

0.6 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
                'jiraImporter',
7
                'label',
8
                'entities',
9
                'projectCache',
10
                'sinceTimeLimit',
11
                'runningPeriods',
12
                'maxCommitWindow',
13
                'over',
14
                'emailDomain',
15
                'metrics',
16
                'analyses'
17
        ],
18
        #category : #'GitLabHealth-Model-Analysis'
19
}
20

21
{ #category : #'as yet unclassified' }
22
GitMetricExporter class >> demoPeriod [
×
23

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

30
{ #category : #adding }
31
GitMetricExporter >> addAPeriodFrom: since to: until [
×
32

×
33
        runningPeriods add: {
×
34
                        (#since -> since asDate).
×
35
                        (#until -> until asDate) } asDictionary.
×
36
        
×
37
        ^runningPeriods 
×
38
]
×
39

40
{ #category : #adding }
41
GitMetricExporter >> addEntitiesFromUserNames: userNames [
×
42
        "import all the project since a certain time"
×
43
        
×
44
        self
×
45
                deprecated: 'Use #setupAnalysesForUsersWithNames instead'
×
46
                on: '03 Sept 2024'
×
47
                in:
×
48
                'Pharo-11.0.0+build.726.sha.aece1b5473acf3830a0e082c1bc3a15d4ff3522b (64 Bit)'.
×
49

×
50
        'Import all projects from the Git repository' recordInfo.
×
51
        projectCache := projectCache ifNil: [
×
52
                                glhImporter importProjectsSince: sinceTimeLimit ].
×
53

×
54
        "then collect the project in which the user has be seen commited"
×
55
        entities addAll: (userNames collect: [ :username |
×
56
                         | projects  i size |
×
57
                         projects := self
×
58
                                             findParticipationOfCommitAuthorNamed: username
×
59
                                             amongProjects: projectCache.
×
60

×
61
                        "metrics := GitMetric4User new.
×
62
                         metrics
×
63
                                 glhImporter: glhImporter;
×
64
                                 jiraImporter: jiraImporter;
×
65
                                 findUserNamed: username."
×
66

×
67

×
68

×
69
                         i := 0.
×
70
                         size := projects size.
×
71
                         metrics itsProjects: (projects collect: [ :p |
×
72
                                          (' ' join: {
×
73
                                                           'complete import of project:'.
×
74
                                                           p name printString.
×
75
                                                           '['.
×
76
                                                           (i := i + 1) printString.
×
77
                                                           '/'.
×
78
                                                           size.
×
79
                                                           ']' }) recordInfo.
×
80

×
81
                                          p id -> (glhImporter completeImportProject: p) ]) asDictionary.
×
82

×
83
                         metrics ]).
×
84

×
85
        ^ self
×
86
]
×
87

88
{ #category : #adding }
89
GitMetricExporter >> addEntitiesFromUserNamesAndProjects: usersWithProjects [
×
90

×
91
        self
×
92
                deprecated: 'Use #setupAnalysesForUsersWithNames instead'
×
93
                on: '03 Sept 2024'
×
94
                in:
×
95
                'Pharo-11.0.0+build.726.sha.aece1b5473acf3830a0e082c1bc3a15d4ff3522b (64 Bit)'.
×
96

×
97
        entities addAll: (usersWithProjects associations collect: [ :assoc |
×
98
                         | username projects  |
×
99
                         username := assoc key.
×
100
                         projects := assoc value.
×
101

×
102
                        " metrics := GitMetric4User new.
×
103
                         metrics
×
104
                                 glhImporter: glhImporter;
×
105
                                 jiraImporter: jiraImporter;
×
106
                                 findUserNamed: username.
×
107
                         metrics loadProjectsFromIds: projects."
×
108

×
109
                         username ]).
×
110

×
111
        ^ self 
×
112
]
×
113

114
{ #category : #utilities }
115
GitMetricExporter >> constructFilePath: runningOver [
×
116

×
117
        | file |
×
118
        file := (FileLocator home
×
119
                 /
×
120
                         ('GitlabHealth-' , label printString , '-' , runningOver printString
×
121
                          , '-'
×
122
                          , (DateAndTime now printString replaceAll: $: with: $-)
×
123
                          , '.csv')) asFileReference.
×
124
        ^ file
×
125
]
×
126

127
{ #category : #exporting }
128
GitMetricExporter >> csvMetricsFor: metricCollection at: date [
×
129

×
130
        | csvMetrics |
×
131
        csvMetrics := metricCollection collect: [ :metric |
×
132
                              metric new description , ' - ' , date asString
×
133
                              -> [ :groupAnalyses |
×
134
                                      | analysis |
×
135
                                      analysis := self
×
136
                                                          getAnalysisWithDate: date
×
137
                                                          from: groupAnalyses.
×
138
                                      analysis
×
139
                                              ifNil: [ nil ]
×
140
                                              ifNotNil: [ analysis metrics at: metric new name ] ] ].
×
141

×
142
        ^ csvMetrics asOrderedDictionary
×
143
]
×
144

145
{ #category : #accessing }
146
GitMetricExporter >> entities: aCollection [ 
×
147
        entities := aCollection
×
148
]
×
149

150
{ #category : #exporting }
151
GitMetricExporter >> exportFor: usersWithProjects [
×
152

×
153
        self
×
154
                deprecated: 'Use #exportInCSV instead'
×
155
                on: '03 Sept 2024'
×
156
                in:
×
157
                'Pharo-11.0.0+build.726.sha.aece1b5473acf3830a0e082c1bc3a15d4ff3522b (64 Bit)'.
×
158

×
159
        self exportFor: usersWithProjects over: {
×
160
                        Date.
×
161
                        Week.
×
162
                        Month.
×
163
                        Year }
×
164
]
×
165

166
{ #category : #exporting }
167
GitMetricExporter >> exportFor: usersWithProjects over: aCollectionOfDateWeekMonthOrYear [
×
168

×
169
        self
×
170
                deprecated: 'Use #exportInCSV instead'
×
171
                on: '03 Sept 2024'
×
172
                in:
×
173
                'Pharo-11.0.0+build.726.sha.aece1b5473acf3830a0e082c1bc3a15d4ff3522b (64 Bit)'.
×
174

×
175
        entities ifNil: [
×
176
                self addEntitiesFromUserNamesAndProjects: usersWithProjects ].
×
177

×
178
        self exportFor: aCollectionOfDateWeekMonthOrYear
×
179
]
×
180

181
{ #category : #exporting }
182
GitMetricExporter >> exportInCSV [
×
183

×
184
        self exportUserAnalysesInCSV.
×
185
        self exportProjectAnalysesInCSV.
×
186
]
×
187

188
{ #category : #exporting }
189
GitMetricExporter >> exportInDB: repository [
×
190

×
191
        repository enableSingleton.
×
192
        analyses do: [ :analysis | analysis save ]
×
193
]
×
194

195
{ #category : #exporting }
196
GitMetricExporter >> exportInS3: bucketName accessKey: accessKey secretKey: secretKey region: region [
×
197

×
198
        | s3 bucket ston date fileName |
×
199
        AWSS3Config default
×
200
                accessKeyId: accessKey;
×
201
                secretKey: secretKey;
×
202
                regionName: region.
×
203

×
204
        s3 := AWSS3 new.
×
205
        bucket := s3 bucketNamed: bucketName.
×
206

×
207
        ston := STON toString: analyses.
×
208

×
209
        date := Date today asString copyReplaceAll: ' ' asString with: '-'.
×
210
        fileName := ('-' join: {
×
211
                                     'analyse'.
×
212
                                     label.
×
213
                                     over asString.
×
214
                                     date }) , '.ston'.
×
215

×
216
        bucket atKey: fileName putObject: ston
×
217
]
×
218

219
{ #category : #exporting }
220
GitMetricExporter >> exportProjectAnalysesInCSV [
×
221

×
222
        | exportBrowserModel groupedByOver group groupOver groupByName periods csvMetrics file |
×
223
        exportBrowserModel := MiExportModel new.
×
224

×
225
        groupedByOver := self projectAnalyses groupedBy: #over.
×
226

×
227
        groupedByOver associations do: [ :groupAssociation |
×
228
                group := groupAssociation value.
×
229
                groupOver := groupAssociation key.
×
230

×
231

×
232
                groupByName := group groupedBy: #projectName.
×
233
                exportBrowserModel entitiesList: groupByName.
×
234

×
235
                exportBrowserModel removeColumnForQueryNamed: #Type.
×
236
                exportBrowserModel removeColumnForQueryNamed: #Name.
×
237

×
238
                exportBrowserModel
×
239
                        addColumnForQuery: [ :groupAnalyses |
×
240
                        (groupAnalyses at: 1) projectName ]
×
241
                        withName: #'Project name'.
×
242

×
243
                periods := (group groupedBy: #period) keys.
×
244

×
245
                periods do: [ :period |
×
246
                        csvMetrics := self
×
247
                                              csvMetricsFor: self projectMetrics
×
248
                                              at: (period at: #since).
×
249

×
250

×
251
                        csvMetrics associations do: [ :association |
×
252
                                exportBrowserModel
×
253
                                        addColumnForQuery: association value
×
254
                                        withName: association key ] ].
×
255

×
256
                file := self constructFilePath: groupOver.
×
257
                file writeStreamDo: [ :aStream |
×
258
                        exportBrowserModel writeCSVOn: aStream ] ]
×
259
]
×
260

261
{ #category : #exporting }
262
GitMetricExporter >> exportUserAnalysesInCSV [
×
263

×
264
        | exportBrowserModel groupedByOver group groupOver groupByName periods csvMetrics file |
×
265
        exportBrowserModel := MiExportModel new.
×
266
        groupedByOver := self userAnalyses groupedBy: #over.
×
267
        
×
268
        groupedByOver associations do: [ :groupAssociation |
×
269
                group := groupAssociation value.
×
270
                groupOver := groupAssociation key.
×
271
                
×
272
                groupByName := group groupedBy: #username.
×
273
                exportBrowserModel entitiesList: groupByName.
×
274
                exportBrowserModel removeColumnForQueryNamed: #Type.
×
275
                exportBrowserModel removeColumnForQueryNamed: #Name.
×
276
                
×
277
                exportBrowserModel
×
278
                        addColumnForQuery: [ :groupAnalyses |
×
279
                        (groupAnalyses at: 1) username ]
×
280
                        withName: #'User name'.
×
281
                        
×
282
                periods := (group groupedBy: #period) keys.
×
283
                periods do: [ :period |
×
284
                        csvMetrics := self
×
285
                                              csvMetricsFor: self userMetrics
×
286
                                              at: (period at: #since).
×
287
                        csvMetrics associations do: [ :association |
×
288
                                exportBrowserModel
×
289
                                        addColumnForQuery: association value
×
290
                                        withName: association key ] ].
×
291
                        
×
292
                        
×
293
                file := self constructFilePath: groupOver.
×
294
                
×
295
                file writeStreamDo: [ :aStream |
×
296
                        exportBrowserModel writeCSVOn: aStream ] ]
×
297
]
×
298

299
{ #category : #projects }
300
GitMetricExporter >> findParticipationOfCommitAuthorNamed: username amongProjects: aCollectionOfProjects [
×
301

×
302
        | response itsProjects i size |
×
303
        i := 1.
×
304
        size := aCollectionOfProjects size.
×
305
        itsProjects := aCollectionOfProjects select: [ :project |
×
306
                               (' ' join: {
×
307
                                                'search'.
×
308
                                                username printString.
×
309
                                                'in Project:'.
×
310
                                                project name printString.
×
311
                                                '['.
×
312
                                                (i := i + 1) printString.
×
313
                                                '/'.
×
314
                                                size.
×
315
                                                ']' }) recordInfo.
×
316

×
317
                               response := glhImporter glhApi
×
318
                                                   commitsOfUser: username
×
319
                                                   inProject: project id
×
320
                                                   since: '01 january 2023' asDateAndTime
×
321
                                                   until: Date today asDateAndTime.
×
322
                               response := glhImporter parseCommitsResult: response.
×
323
                               response isNotEmpty
×
324
                 ].
×
325

×
326
        ^ itsProjects
×
327
]
×
328

329
{ #category : #projects }
330
GitMetricExporter >> findProjectsOfUser: aCollection [ 
×
331
        self shouldBeImplemented.
×
332
]
×
333

334
{ #category : #analysis }
335
GitMetricExporter >> generateAnalysesOver: aDateWeekMonthOrYear [
×
336

×
337
        analyses := OrderedCollection new.
×
338
        runningPeriods do: [ :period |
×
339
                analyses addAll: (self
×
340
                                 generateUsersAnalysesDuringPeriod: period
×
341
                                 over: aDateWeekMonthOrYear).
×
342

×
343
                analyses addAll: (self
×
344
                                 generateProjectsAnalysesDuringPeriod: period
×
345
                                 over: aDateWeekMonthOrYear) ].
×
346

×
347
        ^ analyses
×
348
]
×
349

350
{ #category : #analysis }
351
GitMetricExporter >> generateProjectsAnalysesDuringPeriod: period over: aDateWeekMonthOrYear [
×
352

×
353
        ^self projectEntities collect: [ :project |
×
354
                ProjectAnalysisReport new
×
355
                        projectName: project name;
×
356
                        period: period;
×
357
                        over: aDateWeekMonthOrYear ]
×
358
]
×
359

360
{ #category : #analysis }
361
GitMetricExporter >> generateUsersAnalysesDuringPeriod: period over: aDateWeekMonthOrYear [
×
362

×
363
        | userAnalysisReport newMetric result |
×
364
        ^ self userEntities collect: [ :user |
×
365
                  userAnalysisReport := UserAnalysisReport new
×
366
                                                username: user name;
×
367
                                                period: period;
×
368
                                                over: aDateWeekMonthOrYear.
×
369

×
370
                  metrics do: [ :metric |
×
371
                          newMetric := metric new
×
372
                                               glhImporter: glhImporter;
×
373
                                               jiraImporter: jiraImporter;
×
374
                                               setPeriodSince: (period at: #since)
×
375
                                               until: (period at: #until);
×
376
                                               over: aDateWeekMonthOrYear;
×
377
                                               user: user;
×
378
                                               emailDomain: emailDomain.
×
379

×
380

×
381
                          result := newMetric calculate.
×
382
                          userAnalysisReport metrics at: newMetric name put: result ].
×
383

×
384
                  userAnalysisReport ]
×
385
]
×
386

387
{ #category : #utilities }
388
GitMetricExporter >> getAnalysisWithDate: date from: analysisCollection [
×
389

×
390
        ^analysisCollection
×
391
                detect: [ :groupAnalysis | (groupAnalysis period at: #since) = date ]
×
392
                ifNone: [ nil ]
×
393
]
×
394

395
{ #category : #accessing }
396
GitMetricExporter >> glhImporter: anImporter [
×
397

×
398
        glhImporter := anImporter withInitialCommits: false; yourself. 
×
399
]
×
400

401
{ #category : #adding }
402
GitMetricExporter >> importAnalysesFromS3: bucketName accessKey: accessKey secretKey: secretKey region: region [
×
403

×
404
        | s3 bucket xmlObjects contentElements filesContent |
×
405
        AWSS3Config default
×
406
                accessKeyId: accessKey;
×
407
                secretKey: secretKey;
×
408
                regionName: region.
×
409

×
410
        s3 := AWSS3 new.
×
411
        bucket := s3 bucketNamed: bucketName.
×
412
        xmlObjects := bucket listObjects.
×
413
        contentElements := xmlObjects root elementsSelect: [ :element |
×
414
                                   element isNamed: 'Contents' ].
×
415

×
416
        filesContent := contentElements collect: [ :contentElement |
×
417
                                | keyValue |
×
418
                                keyValue := contentElement contentStringAt: 'Key'.
×
419
                                bucket getObject: keyValue ].
×
420

×
421
        ^ analyses := (filesContent collect: [ :file | STON fromString: file ])
×
422
                              flattened
×
423
]
×
424

425
{ #category : #initialization }
426
GitMetricExporter >> initialize [
×
427

×
428
        entities := OrderedCollection new.
×
429
        "set up the minimal date from which we are looking for the commits a particular user in projects"
×
430
        sinceTimeLimit := '2024-01-01' asDateAndTime.
×
431
        runningPeriods := OrderedCollection new.
×
432
        maxCommitWindow := 3.
×
433
        over := Date.
×
434

×
435
        analyses := OrderedCollection new.
×
436

×
437
        metrics := {
×
438
                           CodeAdditionMetric.
×
439
                           CodeDeletionMetric.
×
440
                           CommentContributionMetric.
×
441
                           CommitFrequencyMetric.
×
442
                           CodeChurnMetric.
×
443
                           DelayUntilFirstChurnMetric.
×
444
                           TimeBetweenCommitMetric.
×
445
                           ContributedProjectMetric.
×
NEW
446
                CodeAdditionByMRMetric .
×
NEW
447
                CodeDeletionByMRMetric .
×
448
                           MergeRequestDurationMetric.
×
449
                           OpenedMergeRequestMetric.
×
450
                           ClosedMergeRequestMetric.
×
451
                           MergedMergeRequestMetric.
×
452
                           SelfMergedUnderAMinuteMergeRequestMetric.
×
453
                           ClosedTicketsMetric.
×
NEW
454
                           JiraTimeMRTimeDifferenceMetric.
×
NEW
455
                           CommitsNumberByJiraTicketsMetric }
×
UNCOV
456
]
×
457

458
{ #category : #accessing }
459
GitMetricExporter >> jiraImporter: anObject [
×
460

×
461
        jiraImporter := anObject
×
462
]
×
463

464
{ #category : #accessing }
465
GitMetricExporter >> label: aString [ 
×
466
        label := aString
×
467
]
×
468

469
{ #category : #accessing }
470
GitMetricExporter >> maxCommitWindow: anInteger [
×
471
        maxCommitWindow := anInteger abs
×
472
]
×
473

474
{ #category : #accessing }
475
GitMetricExporter >> metrics: anObject [
×
476

×
477
        metrics := anObject
×
478
]
×
479

480
{ #category : #adding }
481
GitMetricExporter >> onlyImportProjectsOfGroup: groupId [
×
482

×
483
        | group |
×
484
        group := glhImporter importGroup: groupId.
×
485
        projectCache := group toScope: GLHProject
×
486
]
×
487

488
{ #category : #accessing }
489
GitMetricExporter >> projectAnalyses [
×
490

×
491
        ^ analyses select: [ :analysis | analysis class = ProjectAnalysisReport ]
×
492
]
×
493

494
{ #category : #accessing }
495
GitMetricExporter >> projectEntities [
×
496

×
497
        ^ entities select: [ :entity | entity class = GLHProject ]
×
498
]
×
499

500
{ #category : #accessing }
501
GitMetricExporter >> projectMetrics [
×
502

×
503
        ^ metrics select: [ :metric | metric inheritsFrom: ProjectMetric ]
×
504
]
×
505

506
{ #category : #setup }
507
GitMetricExporter >> setupAnalysisForProjectsWithIds: projectIds [
×
508

×
509
        | projects |
×
510
        projects := glhImporter importProjects: projectIds.
×
511

×
512
        entities addAll: projects
×
513
]
×
514

515
{ #category : #setup }
516
GitMetricExporter >> setupAnalysisForUsersWithNames: userNames [
×
517
        "import all the project since a certain time"
×
518

×
519
        | users |
×
520
        users := userNames collect: [ :username |
×
521
                         glhImporter importUserByUsername: username ].
×
522

×
523
        glhImporter userCatalogue ifNotNil: [
×
524
                glhImporter userCatalogue scrapeAuthorNamesForUsers: users ].
×
525

×
526
        users do: [ :user |
×
527
                | projects |
×
528
                projects := glhImporter importContributedProjectsOfUser: user.
×
529

×
530
                projects do: [ :project |
×
531
                        glhImporter completeImportProject: project ] ].
×
532

×
533
        entities addAll: users.
×
534

×
535
        ^ self
×
536
]
×
537

538
{ #category : #accessing }
539
GitMetricExporter >> userAnalyses [
×
540

×
541
        ^ analyses select: [ :analysis | analysis class = UserAnalysisReport ]
×
542
]
×
543

544
{ #category : #accessing }
545
GitMetricExporter >> userEntities [
×
546

×
547
        ^ entities select: [ :entity | entity class = GLHUser ]
×
548
]
×
549

550
{ #category : #accessing }
551
GitMetricExporter >> userMetrics [
×
552

×
553
        ^ metrics select: [ :metric | metric inheritsFrom: UserMetric ]
×
554
]
×
555

556
{ #category : #setup }
557
GitMetricExporter >> withEmailDomain: anEmailDomain [
×
558

×
559
        "define the email domain of your Git user. Usefull to link them between service (i.e. Jira)"
×
560
        emailDomain := anEmailDomain
×
561
]
×
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