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

moosetechnology / GitProjectHealth / 10849965510

13 Sep 2024 01:03PM UTC coverage: 17.669%. First build
10849965510

Pull #54

github

web-flow
Merge 9d4695b3c into 6bbc9cee6
Pull Request #54: Metrics fixing

0 of 156 new or added lines in 17 files covered. (0.0%)

1589 of 8993 relevant lines covered (17.67%)

0.18 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

×
267
        groupedByOver := self userAnalyses groupedBy: #over.
×
268
        
×
269

×
270
        groupedByOver associations do: [ :groupAssociation |
×
271
                group := groupAssociation value.
×
272
                groupOver := groupAssociation key.
×
273

×
274

×
275
                groupByName := group groupedBy: #username.
×
276
                exportBrowserModel entitiesList: groupByName.
×
277

×
278
                exportBrowserModel removeColumnForQueryNamed: #Type.
×
279
                exportBrowserModel removeColumnForQueryNamed: #Name.
×
280

×
281
                exportBrowserModel
×
282
                        addColumnForQuery: [ :groupAnalyses |
×
283
                        (groupAnalyses at: 1) username ]
×
284
                        withName: #'User name'.
×
285

×
286
                periods := (group groupedBy: #period) keys.
×
287

×
288
                periods do: [ :period |
×
289
                        csvMetrics := self
×
290
                                              csvMetricsFor: self userMetrics
×
291
                                              at: (period at: #since).
×
292

×
293

×
294
                        csvMetrics associations do: [ :association |
×
295
                                exportBrowserModel
×
296
                                        addColumnForQuery: association value
×
297
                                        withName: association key ] ].
×
298

×
299
                file := self constructFilePath: groupOver.
×
300
                file writeStreamDo: [ :aStream |
×
301
                        exportBrowserModel writeCSVOn: aStream ] ]
×
302
]
×
303

304
{ #category : #projects }
305
GitMetricExporter >> findParticipationOfCommitAuthorNamed: username amongProjects: aCollectionOfProjects [
×
306

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

×
322
                               response := glhImporter glhApi
×
323
                                                   commitsOfUser: username
×
324
                                                   inProject: project id
×
325
                                                   since: '01 january 2023' asDateAndTime
×
326
                                                   until: Date today asDateAndTime.
×
327
                               response := glhImporter parseCommitsResult: response.
×
328
                               response isNotEmpty
×
329
                 ].
×
330

×
331
        ^ itsProjects
×
332
]
×
333

334
{ #category : #projects }
335
GitMetricExporter >> findProjectsOfUser: aCollection [ 
×
336
        self shouldBeImplemented.
×
337
]
×
338

339
{ #category : #analysis }
340
GitMetricExporter >> generateAnalysesOver: aDateWeekMonthOrYear [
×
341

×
342
        | userAnalyses projectAnalyses |
×
343
        runningPeriods do: [ :period |
×
344
                userAnalyses := self
×
345
                                        generateUsersAnalysesDuringPeriod: period
×
346
                                        over: aDateWeekMonthOrYear.
×
347
                projectAnalyses := self
×
348
                                           generateProjectsAnalysesDuringPeriod: period
×
349
                                           over: aDateWeekMonthOrYear ].
×
350

×
351
        ^ analyses := userAnalyses, projectAnalyses.
×
352
]
×
353

354
{ #category : #analysis }
355
GitMetricExporter >> generateProjectsAnalysesDuringPeriod: period over: aDateWeekMonthOrYear [
×
356

×
357
        ^self projectEntities collect: [ :project |
×
358
                ProjectAnalysisReport new
×
359
                        projectName: project name;
×
360
                        period: period;
×
361
                        over: aDateWeekMonthOrYear ]
×
362
]
×
363

364
{ #category : #analysis }
365
GitMetricExporter >> generateUsersAnalysesDuringPeriod: period over: aDateWeekMonthOrYear [
×
366

×
367
        | userAnalysisReport newMetric result |
×
368
        ^ self userEntities collect: [ :user |
×
369
                  userAnalysisReport := UserAnalysisReport new
×
370
                                                username: user name;
×
371
                                                period: period;
×
372
                                                over: aDateWeekMonthOrYear.
×
373

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

×
384

×
385
                          result := newMetric calculate.
×
386
                          userAnalysisReport metrics at: newMetric name put: result ].
×
387

×
388
                  userAnalysisReport ]
×
389
]
×
390

391
{ #category : #utilities }
392
GitMetricExporter >> getAnalysisWithDate: date from: analysisCollection [
×
393

×
394
        ^analysisCollection
×
395
                detect: [ :groupAnalysis | (groupAnalysis period at: #since) = date ]
×
396
                ifNone: [ nil ]
×
397
]
×
398

399
{ #category : #accessing }
400
GitMetricExporter >> glhImporter: anImporter [
×
401

×
402
        glhImporter := anImporter withInitialCommits: false; yourself. 
×
403
]
×
404

405
{ #category : #adding }
406
GitMetricExporter >> importAnalysesFromS3: bucketName accessKey: accessKey secretKey: secretKey region: region [
×
407

×
408
        | s3 bucket xmlObjects contentElements filesContent |
×
409
        AWSS3Config default
×
410
                accessKeyId: accessKey;
×
411
                secretKey: secretKey;
×
412
                regionName: region.
×
413

×
414
        s3 := AWSS3 new.
×
415
        bucket := s3 bucketNamed: bucketName.
×
416
        xmlObjects := bucket listObjects.
×
417
        contentElements := xmlObjects root elementsSelect: [ :element |
×
418
                                   element isNamed: 'Contents' ].
×
419

×
420
        filesContent := contentElements collect: [ :contentElement |
×
421
                                | keyValue |
×
422
                                keyValue := contentElement contentStringAt: 'Key'.
×
423
                                bucket getObject: keyValue ].
×
424

×
425
        ^ analyses := (filesContent collect: [ :file | STON fromString: file ])
×
426
                              flattened
×
427
]
×
428

429
{ #category : #initialization }
430
GitMetricExporter >> initialize [
×
431

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

×
439
        analyses := OrderedCollection new.
×
440

×
441
        metrics := {
×
442
                           CodeAdditionMetric.
×
443
                           CodeDeletionMetric.
×
444
                           CommentContributionMetric.
×
445
                           CommitFrequencyMetric.
×
446
                           CodeChurnMetric.
×
447
                           DelayUntilFirstChurnMetric.
×
448
                           TimeBetweenCommitMetric.
×
449
                           ContributedProjectMetric.
×
450
                           MergeRequestDurationMetric.
×
451
                           OpenedMergeRequestMetric.
×
452
                           ClosedMergeRequestMetric.
×
453
                           MergedMergeRequestMetric.
×
NEW
454
                           SelfMergedUnderAMinuteMergeRequestMetric.
×
455
                           ClosedTicketsMetric}
×
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 : #adding }
475
GitMetricExporter >> onlyImportProjectsOfGroup: groupId [
×
476

×
477
        | group |
×
478
        group := glhImporter importGroup: groupId.
×
479
        projectCache := group toScope: GLHProject
×
480
]
×
481

482
{ #category : #accessing }
483
GitMetricExporter >> projectAnalyses [
×
484

×
485
        ^ analyses select: [ :analysis | analysis class = ProjectAnalysisReport ]
×
486
]
×
487

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

×
491
        ^ entities select: [ :entity | entity class = GLHProject ]
×
492
]
×
493

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

×
497
        ^ metrics select: [ :metric | metric inheritsFrom: ProjectMetric ]
×
498
]
×
499

500
{ #category : #setup }
501
GitMetricExporter >> setupAnalysisForProjectsWithIds: projectIds [
×
502

×
503
        | projects |
×
504
        projects := glhImporter importProjects: projectIds.
×
505

×
506
        entities addAll: projects
×
507
]
×
508

509
{ #category : #setup }
510
GitMetricExporter >> setupAnalysisForUsersWithNames: userNames [
×
511
        "import all the project since a certain time"
×
512

×
513
        | users |
×
514
        users := userNames collect: [ :username |
×
515
                         glhImporter importUserByUsername: username ].
×
516

×
517
        glhImporter userCatalogue scrapeAuthorNamesForUsers: users.
×
518
        
×
519
        users do: [ :user |
×
520
                |projects |
×
521
                projects := glhImporter importContributedProjectsOfUser: user.
×
522
                                projects do: [ :project |
×
523
                                glhImporter completeImportProject: project ].         
×
524
                
×
525
        ].
×
526

×
527
        entities addAll: users.
×
528

×
529
        ^ self
×
530
]
×
531

532
{ #category : #accessing }
533
GitMetricExporter >> userAnalyses [
×
534

×
535
        ^ analyses select: [ :analysis | analysis class = UserAnalysisReport ]
×
536
]
×
537

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

×
541
        ^ entities select: [ :entity | entity class = GLHUser ]
×
542
]
×
543

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

×
547
        ^ metrics select: [ :metric | metric inheritsFrom: UserMetric ]
×
548
]
×
549

550
{ #category : #setup }
551
GitMetricExporter >> withEmailDomain: anEmailDomain [
×
552

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