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

moosetechnology / GitProjectHealth / 10452237749

19 Aug 2024 11:10AM UTC coverage: 18.86% (-14.8%) from 33.667%
10452237749

Pull #31

github

web-flow
Merge 2cf167214 into 48c9c9c78
Pull Request #31: fix: error if there are no commits in averageTimeBetweenCommits method

163 of 1071 new or added lines in 15 files covered. (15.22%)

856 existing lines in 12 files now uncovered.

1585 of 8404 relevant lines covered (18.86%)

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

18
{ #category : #'as yet unclassified' }
19
GitMetricExporter class >> demoPeriod [
×
20

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

27
{ #category : #adding }
28
GitMetricExporter >> addAPeriodFrom: since to: until [
×
29

×
30
        runningPeriods add: {
×
31
                        (#since -> since asDate).
×
32
                        (#until -> until asDate) } asDictionary.
×
33
        
×
34
        ^runningPeriods 
×
35
]
×
36

37
{ #category : #adding }
38
GitMetricExporter >> addEntitiesFromUserNames: userNames [
×
39
        "import all the project since a certain time"
×
40

×
41
        'Import all projects from the Git repository' recordInfo.
×
42
        projectCache := projectCache ifNil: [
×
43
                                glhImporter importProjectsSince: sinceTimeLimit ].
×
44

×
45
        "then collect the project in which the user has be seen commited"
×
46
        entities addAll: (userNames collect: [ :username |
×
47
                         | projects metrics i size |
×
48
                         projects := self findParticipationOfCommitAuthorNamed: username amongProjects: projectCache.
×
49

×
50
                         metrics := GitMetric4User new.
×
51
                         metrics
×
52
                                 glhImporter: glhImporter;
×
53
                                 findUserNamed: username.
×
54

×
55

×
56

×
57
                         i := 0.
×
58
                         size := projects size.
×
59
                         metrics itsProjects: (projects collect: [ :p |
×
60
                                          (' ' join: {
×
61
                                                           'complete import of project:'.
×
62
                                                           p name printString.
×
63
                                                           '['.
×
64
                                                           (i := i + 1) printString.
×
65
                                                           '/'.
×
66
                                                           size.
×
67
                                                           ']' }) recordInfo.
×
68

×
69
                                          p id -> (glhImporter completeImportProject: p) ]) asDictionary.
×
70

×
71
                         metrics ]).
×
72

×
73
        ^ self
×
74
]
×
75

76
{ #category : #adding }
77
GitMetricExporter >> addEntitiesFromUserNamesAndProjects: usersWithProjects [
×
78

×
79
        entities addAll: (usersWithProjects associations collect: [ :assoc |
×
80
                            | username projects metrics |
×
81
                            username := assoc key.
×
82
                            projects := assoc value.
×
83

×
84
                            metrics := GitMetric4User new.
×
85
                            metrics
×
86
                                    glhImporter: glhImporter;
×
87
                                    findUserNamed: username.
×
88
                            metrics loadProjectsFromIds: projects.
×
89

×
90
                            metrics ]).
×
91

×
92
        ^ self
×
93
]
×
94

95
{ #category : #accessing }
NEW
96
GitMetricExporter >> analyses [
×
97

×
NEW
98
        ^ analyses
×
99
]
×
100

101
{ #category : #accessing }
NEW
102
GitMetricExporter >> analyses: anObject [
×
UNCOV
103

×
NEW
104
        analyses := anObject
×
105
]
×
106

107
{ #category : #utilities }
108
GitMetricExporter >> constructFilePath: runningOver [
×
109

×
110
        | file |
×
111
        file := (FileLocator home
×
112
                 /
×
113
                         ('GitlabHealth-' , label printString , '-' , runningOver printString
×
114
                          , '-'
×
115
                          , (DateAndTime now printString replaceAll: $: with: $-)
×
116
                          , '.csv')) asFileReference.
×
117
        ^ file
×
118
]
×
119

120
{ #category : #accessing }
NEW
121
GitMetricExporter >> entities: aCollection [ 
×
NEW
122
        entities := aCollection
×
NEW
123
]
×
124

125
{ #category : #exporting }
NEW
126
GitMetricExporter >> exportFor: usersWithProjects [
×
127

×
NEW
128
        self exportFor: usersWithProjects over: { Date. Week . Month . Year }.
×
NEW
129
]
×
130

131
{ #category : #exporting }
NEW
132
GitMetricExporter >> exportFor: usersWithProjects over: aCollectionOfDateWeekMonthOrYear [
×
133

×
NEW
134
        entities ifNil: [
×
NEW
135
                self addEntitiesFromUserNamesAndProjects: usersWithProjects ].
×
UNCOV
136

×
NEW
137
        self exportFor: aCollectionOfDateWeekMonthOrYear. 
×
138
]
×
139

140
{ #category : #exporting }
NEW
141
GitMetricExporter >> exportInCSV [
×
142

×
NEW
143
        | exportBrowserModel file |
×
144
        exportBrowserModel := MiExportModel new.
×
NEW
145

×
NEW
146
        self analyses ifNil: [ self generateAnalyses ].
×
NEW
147
        exportBrowserModel entitiesList: self analyses.
×
NEW
148

×
149
        exportBrowserModel removeColumnForQueryNamed: #Type.
×
150
        exportBrowserModel removeColumnForQueryNamed: #Name.
×
151

×
152
        exportBrowserModel
×
NEW
153
                addColumnForQuery: [ :analysis | analysis username ]
×
154
                withName: #'User name'.
×
155

×
NEW
156
        exportBrowserModel
×
NEW
157
                addColumnForQuery: [ :analysis | analysis period at: #since ]
×
NEW
158
                withName: #Since.
×
NEW
159

×
NEW
160
        exportBrowserModel
×
NEW
161
                addColumnForQuery: [ :analysis | analysis period at: #until ]
×
NEW
162
                withName: #Until.
×
NEW
163

×
NEW
164
        exportBrowserModel
×
NEW
165
                addColumnForQuery: [ :analysis | analysis over ]
×
NEW
166
                withName: #Over.
×
NEW
167

×
168
        "Code Contribution "
×
NEW
169
        exportBrowserModel
×
NEW
170
                addColumnForQuery: [ :analysis | analysis codeAddition ]
×
NEW
171
                withName: 'code addition (avg)' asSymbol.
×
NEW
172

×
NEW
173
        exportBrowserModel
×
NEW
174
                addColumnForQuery: [ :analysis | analysis codeDeletion ]
×
NEW
175
                withName: 'code deletion (avg)' asSymbol.
×
176

×
177
        "Commit frequencies "
×
NEW
178
        exportBrowserModel
×
NEW
179
                addColumnForQuery: [ :analysis | analysis commitFrequency ]
×
NEW
180
                withName: 'commits frequency (avg) ' asSymbol.
×
181

×
182
        "comment contribution "
×
NEW
183
        exportBrowserModel
×
NEW
184
                addColumnForQuery: [ :analysis | analysis commentContribution ]
×
NEW
185
                withName: 'comment contribution (avg)' asSymbol.
×
186

×
187
        "merge Request Duration "
×
NEW
188
        exportBrowserModel
×
NEW
189
                addColumnForQuery: [ :analysis | analysis mergeRequestDuration ]
×
NEW
190
                withName: 'merge Request Duration ' asSymbol.
×
191

×
192
        "code churn"
×
NEW
193
        exportBrowserModel
×
NEW
194
                addColumnForQuery: [ :analysis | analysis codeChurn ]
×
NEW
195
                withName:
×
NEW
196
                'churn % (W=' , maxCommitWindow printString , ') ' asSymbol.
×
197

×
198
        "delay Until First Churn"
×
NEW
199
        exportBrowserModel
×
NEW
200
                addColumnForQuery: [ :analysis | analysis delayUntilFirstChurn ]
×
NEW
201
                withName:
×
NEW
202
                        'delay Until First Churn (W=' , maxCommitWindow printString
×
NEW
203
                        , ') ' asSymbol.
×
NEW
204
                        
×
NEW
205
        "number of project with minimum one commit of user"
×
NEW
206
        exportBrowserModel
×
NEW
207
                addColumnForQuery: [ :analysis | analysis numberOfProjectWithCommit ]
×
NEW
208
                withName:
×
NEW
209
                        'number of project with min 1 commit of user' asSymbol.
×
NEW
210
      
×
NEW
211
        "average time between commits"
×
NEW
212
        exportBrowserModel
×
NEW
213
                addColumnForQuery: [ :analysis | analysis averageTimeBetweenCommits  ]
×
NEW
214
                withName:
×
NEW
215
                        'average time between commits' asSymbol.
×
216

×
NEW
217
        file := self constructFilePath: over.
×
NEW
218
        file writeStreamDo: [ :aStream |
×
NEW
219
                aStream
×
NEW
220
                        << 'sep=,';
×
NEW
221
                        << OSPlatform current lineEnding.
×
NEW
222
                exportBrowserModel writeCSVOn: aStream ].
×
223

×
224
        'Done computing' recordInfo
×
225
]
×
226

227
{ #category : #exporting }
NEW
228
GitMetricExporter >> exportInDB: repository [
×
229

×
NEW
230
        repository enableSingleton.
×
NEW
231

×
NEW
232
        self analyses ifNil: [ self generateAnalyses ].
×
NEW
233
        self analyses do: [ :analysis | analysis save ]
×
UNCOV
234
]
×
235

236
{ #category : #exporting }
NEW
237
GitMetricExporter >> exportInS3: bucketName accessKey: accessKey secretKey: secretKey region: region [
×
NEW
238
  | s3 bucket ston date |
×
NEW
239
AWSS3Config default 
×
NEW
240
  accessKeyId: accessKey;
×
NEW
241
  secretKey: secretKey;
×
NEW
242
  regionName: region.
×
243

×
NEW
244
        s3 := AWSS3 new.
×
NEW
245
        bucket:= s3 bucketNamed: bucketName.
×
NEW
246
        
×
NEW
247
        ston := STON toString: analyses.
×
NEW
248
        
×
NEW
249
        date := (Date today asString) copyReplaceAll: ' 'asString with: '-'.
×
NEW
250
        
×
NEW
251
        bucket atKey:'analyses-', date, '.ston' putObject: ston.
×
UNCOV
252
]
×
253

254
{ #category : #projects }
255
GitMetricExporter >> findParticipationOfCommitAuthorNamed: username amongProjects: aCollectionOfProjects [
×
256

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

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

×
281
        ^ itsProjects
×
282
]
×
283

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

289
{ #category : #analysis }
NEW
290
GitMetricExporter >> generateAnalyses [
×
NEW
291

×
NEW
292
        | newAnalyses |
×
NEW
293
        newAnalyses := OrderedCollection new.
×
NEW
294

×
NEW
295
        runningPeriods do: [ :period |
×
NEW
296
                newAnalyses addAll: (entities collect: [ :entity |
×
NEW
297
                        entity
×
NEW
298
                                generateAnalysisForPeriod: period
×
NEW
299
                                over: over
×
NEW
300
                                withMaxCommitWindows: maxCommitWindow ]) ].
×
NEW
301

×
NEW
302
        self analyses: newAnalyses.
×
NEW
303

×
NEW
304
        ^ newAnalyses
×
NEW
305
]
×
306

307
{ #category : #analysis }
NEW
308
GitMetricExporter >> generateAnalysesOver: aDateWeekMonthOrYear [
×
NEW
309

×
NEW
310
        | newAnalyses |
×
NEW
311
        over := aDateWeekMonthOrYear.
×
NEW
312
        newAnalyses := OrderedCollection new.
×
NEW
313

×
NEW
314
        runningPeriods do: [ :period |
×
NEW
315
                newAnalyses addAll: (entities collect: [ :entity |
×
NEW
316
                        entity
×
NEW
317
                                generateAnalysisForPeriod: period
×
NEW
318
                                over: over
×
NEW
319
                                withMaxCommitWindows: maxCommitWindow ]) ].
×
NEW
320

×
NEW
321
        self analyses: newAnalyses.
×
NEW
322

×
NEW
323
        ^ newAnalyses
×
NEW
324
]
×
325

326
{ #category : #accessing }
327
GitMetricExporter >> glhImporter: anImporter [
×
328

×
329
        glhImporter := anImporter withInitialCommits: false; yourself. 
×
330
]
×
331

332
{ #category : #initialization }
333
GitMetricExporter >> initialize [
×
334

×
335
        entities := OrderedCollection new.
×
336
        "set up the minimal date from which we are looking for the commits a particular user in projects"
×
337
        sinceTimeLimit := '2024-01-01' asDateAndTime..
×
338
        runningPeriods := OrderedCollection new.
×
339
        maxCommitWindow := 3.
×
340
        over := Date
×
341
]
×
342

343
{ #category : #accessing }
344
GitMetricExporter >> label: aString [ 
×
345
        label := aString
×
346
]
×
347

348
{ #category : #accessing }
349
GitMetricExporter >> maxCommitWindow: anInteger [
×
350
        maxCommitWindow := anInteger abs
×
351
]
×
352

353
{ #category : #adding }
354
GitMetricExporter >> onlyImportProjectsOfGroup: groupId [
×
355

×
356
        | group |
×
NEW
357
        group := glhImporter importGroup: groupId.
×
NEW
358
        projectCache := group toScope: GLHProject
×
UNCOV
359
]
×
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