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

moosetechnology / GitProjectHealth / 11667512120

04 Nov 2024 03:36PM UTC coverage: 59.207% (+0.2%) from 59.01%
11667512120

Pull #105

github

web-flow
Merge 0462ff346 into 3c4574e31
Pull Request #105: fix/add email user to the importer + tests

71 of 82 new or added lines in 3 files covered. (86.59%)

149 existing lines in 35 files now uncovered.

9582 of 16184 relevant lines covered (59.21%)

0.59 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' }
UNCOV
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 }
UNCOV
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 }
UNCOV
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 }
UNCOV
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 }
UNCOV
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 }
UNCOV
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 }
UNCOV
146
GitMetricExporter >> entities: aCollection [ 
×
147
        entities := aCollection
×
148
]
×
149

150
{ #category : #exporting }
UNCOV
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 }
UNCOV
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 }
UNCOV
182
GitMetricExporter >> exportInCSV [
×
183

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

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

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

195
{ #category : #exporting }
UNCOV
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 }
UNCOV
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 }
UNCOV
262
GitMetricExporter >> exportUserAnalysesInCSV [
×
263

×
264
        | exportBrowserModel groupedByOver group groupOver groupByName periods csvMetrics file |
×
265
        exportBrowserModel := MiExportModel new.
×
266
        groupedByOver := self userAnalyses groupedBy: #over.
×
NEW
267

×
268
        groupedByOver associations do: [ :groupAssociation |
×
269
                group := groupAssociation value.
×
270
                groupOver := groupAssociation key.
×
NEW
271

×
272
                groupByName := group groupedBy: #username.
×
273
                exportBrowserModel entitiesList: groupByName.
×
274
                exportBrowserModel removeColumnForQueryNamed: #Type.
×
275
                exportBrowserModel removeColumnForQueryNamed: #Name.
×
NEW
276

×
277
                exportBrowserModel
×
278
                        addColumnForQuery: [ :groupAnalyses |
×
279
                        (groupAnalyses at: 1) username ]
×
280
                        withName: #'User name'.
×
281
                        
×
NEW
282
                exportBrowserModel
×
NEW
283
                        addColumnForQuery: [ :groupAnalyses |
×
NEW
284
                        (groupAnalyses at: 1) email ifNil: #public_email ]
×
NEW
285
                        withName: #'User email'.
×
NEW
286

×
287
                periods := (group groupedBy: #period) keys.
×
288
                periods do: [ :period |
×
289
                        csvMetrics := self
×
290
                                              csvMetricsFor: self userMetrics
×
291
                                              at: (period at: #since).
×
292
                        csvMetrics associations do: [ :association |
×
293
                                exportBrowserModel
×
294
                                        addColumnForQuery: association value
×
295
                                        withName: association key ] ].
×
NEW
296

×
NEW
297

×
298
                file := self constructFilePath: groupOver.
×
NEW
299

×
300
                file writeStreamDo: [ :aStream |
×
301
                        exportBrowserModel writeCSVOn: aStream ] ]
×
302
]
×
303

304
{ #category : #projects }
UNCOV
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 repoApi
×
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 }
UNCOV
335
GitMetricExporter >> findProjectsOfUser: aCollection [ 
×
336
        self shouldBeImplemented.
×
337
]
×
338

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

×
342
        analyses := OrderedCollection new.
×
343
        runningPeriods do: [ :period |
×
344
                analyses addAll: (self
×
345
                                 generateUsersAnalysesDuringPeriod: period
×
346
                                 over: aDateWeekMonthOrYear).
×
347

×
348
                analyses addAll: (self
×
349
                                 generateProjectsAnalysesDuringPeriod: period
×
350
                                 over: aDateWeekMonthOrYear) ].
×
351

×
352
        ^ analyses
×
353
]
×
354

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

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

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

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

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

×
385

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

×
389
                  userAnalysisReport ]
×
390
]
×
391

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

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

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

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

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

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

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

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

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

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

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

×
440
        analyses := OrderedCollection new.
×
441

×
442
        metrics := {
×
443
                           CodeAdditionMetric.
×
444
                           CodeDeletionMetric.
×
445
                           CommentContributionMetric.
×
446
                           CommitFrequencyMetric.
×
447
                           CodeChurnMetric.
×
448
                           DelayUntilFirstChurnMetric.
×
449
                           TimeBetweenCommitMetric.
×
450
                           ContributedProjectMetric.
×
451
                CodeAdditionByMRMetric .
×
452
                CodeDeletionByMRMetric .
×
453
                           MergeRequestDurationMetric.
×
454
                           OpenedMergeRequestMetric.
×
455
                           ClosedMergeRequestMetric.
×
456
                           MergedMergeRequestMetric.
×
457
                           SelfMergedUnderAMinuteMergeRequestMetric.
×
458
                           ClosedTicketsMetric.
×
459
                           JiraTimeMRTimeDifferenceMetric.
×
460
                           CommitsNumberByJiraTicketsMetric }
×
461
]
×
462

463
{ #category : #accessing }
UNCOV
464
GitMetricExporter >> jiraImporter: anObject [
×
UNCOV
465

×
466
        jiraImporter := anObject
×
467
]
×
468

469
{ #category : #accessing }
UNCOV
470
GitMetricExporter >> label: aString [ 
×
UNCOV
471
        label := aString
×
472
]
×
473

474
{ #category : #accessing }
UNCOV
475
GitMetricExporter >> maxCommitWindow: anInteger [
×
UNCOV
476
        maxCommitWindow := anInteger abs
×
477
]
×
478

479
{ #category : #accessing }
UNCOV
480
GitMetricExporter >> metrics: anObject [
×
UNCOV
481

×
482
        metrics := anObject
×
483
]
×
484

485
{ #category : #adding }
UNCOV
486
GitMetricExporter >> onlyImportProjectsOfGroup: groupId [
×
UNCOV
487

×
488
        | group |
×
489
        group := glhImporter importGroup: groupId.
×
490
        projectCache := group toScope: GLHProject
×
491
]
×
492

493
{ #category : #accessing }
UNCOV
494
GitMetricExporter >> projectAnalyses [
×
UNCOV
495

×
496
        ^ analyses select: [ :analysis | analysis class = ProjectAnalysisReport ]
×
497
]
×
498

499
{ #category : #accessing }
UNCOV
500
GitMetricExporter >> projectEntities [
×
UNCOV
501

×
502
        ^ entities select: [ :entity | entity class = GLHProject ]
×
503
]
×
504

505
{ #category : #accessing }
UNCOV
506
GitMetricExporter >> projectMetrics [
×
UNCOV
507

×
508
        ^ metrics select: [ :metric | metric inheritsFrom: ProjectMetric ]
×
509
]
×
510

511
{ #category : #setup }
UNCOV
512
GitMetricExporter >> setupAnalysisForProjectsWithIds: projectIds [
×
UNCOV
513

×
514
        | projects |
×
515
        projects := glhImporter importProjects: projectIds.
×
516

×
517
        entities addAll: projects
×
518
]
×
519

520
{ #category : #setup }
UNCOV
521
GitMetricExporter >> setupAnalysisForUsersWithNames: userNames [
×
UNCOV
522
        "import all the project since a certain time"
×
523

×
524
        | users |
×
525
        users := userNames collect: [ :username |
×
526
                         glhImporter importUserByUsername: username ].
×
527

×
528
        glhImporter userCatalogue ifNotNil: [
×
529
                glhImporter userCatalogue scrapeAuthorNamesForUsers: users ].
×
530

×
531
        users do: [ :user |
×
532
                | projects |
×
533
                projects := glhImporter importContributedProjectsOfUser: user.
×
534

×
535
                projects do: [ :project |
×
536
                        glhImporter completeImportProject: project ] ].
×
537

×
538
        entities addAll: users.
×
539

×
540
        ^ self
×
541
]
×
542

543
{ #category : #accessing }
UNCOV
544
GitMetricExporter >> userAnalyses [
×
UNCOV
545

×
546
        ^ analyses select: [ :analysis | analysis class = UserAnalysisReport ]
×
547
]
×
548

549
{ #category : #accessing }
UNCOV
550
GitMetricExporter >> userEntities [
×
UNCOV
551

×
552
        ^ entities select: [ :entity | entity class = GLHUser ]
×
553
]
×
554

555
{ #category : #accessing }
UNCOV
556
GitMetricExporter >> userMetrics [
×
UNCOV
557

×
558
        ^ metrics select: [ :metric | metric inheritsFrom: UserMetric ]
×
559
]
×
560

561
{ #category : #setup }
UNCOV
562
GitMetricExporter >> withEmailDomain: anEmailDomain [
×
UNCOV
563

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