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

moosetechnology / GitProjectHealth / 10682053149

03 Sep 2024 11:29AM UTC coverage: 18.493%. First build
10682053149

Pull #47

github

web-flow
Merge bae5d1107 into 049515451
Pull Request #47: refactor: remove GitMetric class and subclasses

0 of 176 new or added lines in 10 files covered. (0.0%)

1590 of 8598 relevant lines covered (18.49%)

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
                'analyses',
15
                'emailDomain',
16
                'metrics'
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"
×
NEW
43
        
×
NEW
44
        self
×
NEW
45
                deprecated: 'Use #setupAnalysesForUsersWithNames instead'
×
NEW
46
                on: '03 Sept 2024'
×
NEW
47
                in:
×
NEW
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 |
×
NEW
56
                         | projects  i size |
×
57
                         projects := self
×
58
                                             findParticipationOfCommitAuthorNamed: username
×
59
                                             amongProjects: projectCache.
×
60

×
NEW
61
                        "metrics := GitMetric4User new.
×
62
                         metrics
×
63
                                 glhImporter: glhImporter;
×
NEW
64
                                 jiraImporter: jiraImporter;
×
NEW
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

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

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

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

×
NEW
109
                         username ]).
×
110

×
NEW
111
        ^ self 
×
112
]
×
113

114
{ #category : #accessing }
115
GitMetricExporter >> analyses [
×
116

×
117
        ^ analyses
×
118
]
×
119

120
{ #category : #accessing }
121
GitMetricExporter >> analyses: anObject [
×
122

×
123
        analyses := anObject
×
124
]
×
125

126
{ #category : #utilities }
127
GitMetricExporter >> constructFilePath: runningOver [
×
128

×
129
        | file |
×
130
        file := (FileLocator home
×
131
                 /
×
132
                         ('GitlabHealth-' , label printString , '-' , runningOver printString
×
133
                          , '-'
×
134
                          , (DateAndTime now printString replaceAll: $: with: $-)
×
135
                          , '.csv')) asFileReference.
×
136
        ^ file
×
137
]
×
138

139
{ #category : #exporting }
140
GitMetricExporter >> csvMetricsFor: date [
×
141

×
142
        | csvMetrics |
×
143
        csvMetrics := metrics collect: [ :metric |
×
144
                              metric new description , ' - ' , date asString
×
145
                              -> [ :groupAnalyses |
×
146
                                      | analysis |
×
147
                                      analysis := self
×
148
                                                          getAnalysisWithDate: date
×
149
                                                          from: groupAnalyses.
×
150
                                      analysis
×
151
                                              ifNil: [ nil ]
×
152
                                              ifNotNil: [
×
153
                                              analysis metrics at: metric new name ] ] ].
×
154

×
155
        ^ csvMetrics asOrderedDictionary
×
156
]
×
157

158
{ #category : #accessing }
159
GitMetricExporter >> entities: aCollection [ 
×
160
        entities := aCollection
×
161
]
×
162

163
{ #category : #exporting }
164
GitMetricExporter >> exportFor: usersWithProjects [
×
165

×
166
        self exportFor: usersWithProjects over: { Date. Week . Month . Year }.
×
167
]
×
168

169
{ #category : #exporting }
170
GitMetricExporter >> exportFor: usersWithProjects over: aCollectionOfDateWeekMonthOrYear [
×
171

×
172
        entities ifNil: [
×
173
                self addEntitiesFromUserNamesAndProjects: usersWithProjects ].
×
174

×
175
        self exportFor: aCollectionOfDateWeekMonthOrYear. 
×
176
]
×
177

178
{ #category : #exporting }
179
GitMetricExporter >> exportInCSV [
×
180

×
181
        | exportBrowserModel file groupedByOver groupByName periods group groupOver csvMetrics |
×
182
        exportBrowserModel := MiExportModel new.
×
183

×
184
        groupedByOver := self analyses groupedBy: #over.
×
185

×
186
        groupedByOver associations do: [ :groupAssociation |
×
187
                group := groupAssociation value.
×
188
                groupOver := groupAssociation key.
×
189

×
190

×
191
                groupByName := group groupedBy: #username.
×
192
                exportBrowserModel entitiesList: groupByName.
×
193

×
194
                exportBrowserModel removeColumnForQueryNamed: #Type.
×
195
                exportBrowserModel removeColumnForQueryNamed: #Name.
×
196

×
197
                exportBrowserModel
×
198
                        addColumnForQuery: [ :groupAnalyses |
×
199
                        (groupAnalyses at: 1) username ]
×
200
                        withName: #'User name'.
×
201

×
202
                periods := (group groupedBy: #period) keys.
×
203

×
204
                periods do: [ :period |
×
205
                        csvMetrics := self csvMetricsFor: (period at: #since).
×
206

×
207

×
208
                        csvMetrics associations do: [ :association |
×
209
                                exportBrowserModel
×
210
                                        addColumnForQuery: association value
×
211
                                        withName: association key ] ].
×
212

×
213
                file := self constructFilePath: groupOver.
×
214
                file writeStreamDo: [ :aStream |
×
215
                        aStream
×
216
                                << 'sep=,';
×
217
                                << OSPlatform current lineEnding.
×
218
                        exportBrowserModel writeCSVOn: aStream ] ].
×
219

×
220
        'Done computing' recordInfo
×
221
]
×
222

223
{ #category : #exporting }
224
GitMetricExporter >> exportInDB: repository [
×
225

×
226
        repository enableSingleton.
×
227

×
228
        self analyses ifNil: [ self generateAnalyses ].
×
229
        self analyses do: [ :analysis | analysis save ]
×
230
]
×
231

232
{ #category : #exporting }
233
GitMetricExporter >> exportInS3: bucketName accessKey: accessKey secretKey: secretKey region: region [
×
234

×
235
        | s3 bucket ston date fileName |
×
236
        AWSS3Config default
×
237
                accessKeyId: accessKey;
×
238
                secretKey: secretKey;
×
239
                regionName: region.
×
240

×
241
        s3 := AWSS3 new.
×
242
        bucket := s3 bucketNamed: bucketName.
×
243

×
244
        ston := STON toString: analyses.
×
245

×
246
        date := Date today asString copyReplaceAll: ' ' asString with: '-'.
×
247
        fileName := ('-' join: {
×
248
                                     'analyse'.
×
249
                                     label.
×
250
                                     over asString.
×
251
                                     date }) , '.ston'.
×
252

×
253
        bucket atKey: fileName putObject: ston
×
254
]
×
255

256
{ #category : #projects }
257
GitMetricExporter >> findParticipationOfCommitAuthorNamed: username amongProjects: aCollectionOfProjects [
×
258

×
259
        | response itsProjects i size |
×
260
        i := 1.
×
261
        size := aCollectionOfProjects size.
×
262
        itsProjects := aCollectionOfProjects select: [ :project |
×
263
                               (' ' join: {
×
264
                                                'search'.
×
265
                                                username printString.
×
266
                                                'in Project:'.
×
267
                                                project name printString.
×
268
                                                '['.
×
269
                                                (i := i + 1) printString.
×
270
                                                '/'.
×
271
                                                size.
×
272
                                                ']' }) recordInfo.
×
273

×
274
                               response := glhImporter glhApi
×
275
                                                   commitsOfUser: username
×
276
                                                   inProject: project id
×
277
                                                   since: '01 january 2023' asDateAndTime
×
278
                                                   until: Date today asDateAndTime.
×
279
                               response := glhImporter parseCommitsResult: response.
×
280
                               response isNotEmpty
×
281
                 ].
×
282

×
283
        ^ itsProjects
×
284
]
×
285

286
{ #category : #projects }
287
GitMetricExporter >> findProjectsOfUser: aCollection [ 
×
288
        self shouldBeImplemented.
×
289
]
×
290

291
{ #category : #analysis }
292
GitMetricExporter >> generateAnalysesOver: aDateWeekMonthOrYear [
×
293

×
294
        | userAnalysisReport result analysesReport newMetric |
×
295
        runningPeriods do: [ :period |
×
296
                analysesReport := entities collect: [ :entity |
×
297
                                          userAnalysisReport := UserAnalysisReport new
×
NEW
298
                                                                        username: entity name;
×
299
                                                                        period: period;
×
300
                                                                        over: aDateWeekMonthOrYear.
×
301

×
302
                                          metrics do: [ :metric |
×
303
                                                  newMetric := metric new
×
304
                                                                       setPeriodSince:
×
305
                                                                               (period at: #since)
×
306
                                                                       until: (period at: #until);
×
307
                                                                       over: aDateWeekMonthOrYear;
×
NEW
308
                                                                       user: entity;
×
NEW
309
                                                                       glhImporter: glhImporter;
×
NEW
310
                                                                       jiraImporter: jiraImporter;
×
NEW
311
                                                                       emailDomain: emailDomain.
×
312

×
313

×
314
                                                  result := newMetric calculate.
×
315
                                                  userAnalysisReport metrics
×
316
                                                          at: newMetric name
×
317
                                                          put: result ].
×
318

×
319
                                          userAnalysisReport ].
×
320
                self analyses addAll: analysesReport ].
×
321

×
322
        ^ analyses
×
323
]
×
324

325
{ #category : #utilities }
326
GitMetricExporter >> getAnalysisWithDate: date from: analysisCollection [
×
327

×
328
        ^analysisCollection
×
329
                detect: [ :groupAnalysis | (groupAnalysis period at: #since) = date ]
×
330
                ifNone: [ nil ]
×
331
]
×
332

333
{ #category : #accessing }
334
GitMetricExporter >> glhImporter: anImporter [
×
335

×
336
        glhImporter := anImporter withInitialCommits: false; yourself. 
×
337
]
×
338

339
{ #category : #adding }
340
GitMetricExporter >> importAnalysesFromS3: bucketName accessKey: accessKey secretKey: secretKey region: region [
×
341

×
342
        | s3 bucket xmlObjects contentElements filesContent |
×
343
        AWSS3Config default
×
344
                accessKeyId: accessKey;
×
345
                secretKey: secretKey;
×
346
                regionName: region.
×
347

×
348
        s3 := AWSS3 new.
×
349
        bucket := s3 bucketNamed: bucketName.
×
350
        xmlObjects := bucket listObjects.
×
351
        contentElements := xmlObjects root elementsSelect: [ :element |
×
352
                                   element isNamed: 'Contents' ].
×
353

×
354
        filesContent := contentElements collect: [ :contentElement |
×
355
                                | keyValue |
×
356
                                keyValue := contentElement contentStringAt: 'Key'.
×
357
                                bucket getObject: keyValue ].
×
358

×
359
        ^ analyses := (filesContent collect: [ :file | STON fromString: file ])
×
360
                              flattened
×
361
]
×
362

363
{ #category : #initialization }
364
GitMetricExporter >> initialize [
×
365

×
366
        entities := OrderedCollection new.
×
367
        "set up the minimal date from which we are looking for the commits a particular user in projects"
×
368
        sinceTimeLimit := '2024-01-01' asDateAndTime.
×
369
        runningPeriods := OrderedCollection new.
×
370
        maxCommitWindow := 3.
×
371
        over := Date.
×
372

×
373
        analyses := OrderedCollection new.
×
374

×
375
        metrics := {
×
376
                           CodeAdditionMetric.
×
377
                           CodeDeletionMetric.
×
378
                           CommentContributionMetric.
×
379
                           CommitFrequencyMetric.
×
380
                           CodeChurnMetric.
×
381
                           DelayUntilFirstChurnMetric.
×
382
                           TimeBetweenCommitMetric.
×
383
                           ContributedProjectMetric.
×
384
                           MergeRequestDurationMetric.
×
385
                           OpenedMergeRequestMetric.
×
386
                           ClosedMergeRequestMetric.
×
387
                           MergedMergeRequestMetric.
×
388
                           MergedMergeRequestWithoutReviewMetric.
×
389
                           ClosedTicketsMetric}
×
390
]
×
391

392
{ #category : #accessing }
393
GitMetricExporter >> jiraImporter: anObject [
×
394

×
395
        jiraImporter := anObject
×
396
]
×
397

398
{ #category : #accessing }
399
GitMetricExporter >> label: aString [ 
×
400
        label := aString
×
401
]
×
402

403
{ #category : #accessing }
404
GitMetricExporter >> maxCommitWindow: anInteger [
×
405
        maxCommitWindow := anInteger abs
×
406
]
×
407

408
{ #category : #adding }
409
GitMetricExporter >> onlyImportProjectsOfGroup: groupId [
×
410

×
411
        | group |
×
412
        group := glhImporter importGroup: groupId.
×
413
        projectCache := group toScope: GLHProject
×
414
]
×
415

416
{ #category : #setup }
417
GitMetricExporter >> setupAnalysisForUsersWithNames: userNames [
×
418
        "import all the project since a certain time"
×
419

×
420
        | users |
×
421
        users := userNames collect: [ :username |
×
422
                         glhImporter importUserByUsername: username ].
×
423

×
424
        glhImporter userCatalogue scrapeAuthorNamesForUsers: users.
×
NEW
425
        
×
NEW
426
        users do: [ :user |
×
NEW
427
                |projects |
×
NEW
428
                projects := glhImporter importContributedProjectsOfUser: user.
×
NEW
429
                                projects do: [ :project |
×
NEW
430
                                glhImporter completeImportProject: project ].         
×
NEW
431
                
×
NEW
432
        ].
×
NEW
433

×
NEW
434
        entities addAll: users.
×
435

×
436
        ^ self
×
437
]
×
438

439
{ #category : #setup }
440
GitMetricExporter >> withEmailDomain: anEmailDomain [
×
441

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