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

moosetechnology / GitProjectHealth / 10391985295

14 Aug 2024 05:12PM UTC coverage: 18.57%. First build
10391985295

Pull #28

github

web-flow
Merge c2427b6be into 7ae7aaeb7
Pull Request #28: New import for git metric

7 of 307 new or added lines in 5 files covered. (2.28%)

1587 of 8546 relevant lines covered (18.57%)

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 }
96
GitMetricExporter >> analyses [
×
97

×
98
        ^ analyses
×
99
]
×
100

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

×
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 : #exporting }
121
GitMetricExporter >> debugExportOver: aCollectionOfDateWeekMonthOrYear [
×
122

×
123
        | period |
×
124
        over := Date.
×
125

×
126
        period := runningPeriods first.
×
127

×
128

×
129
        1 halt.
×
130
        "Code Contribution "
×
131

×
132
        (entities collect: (self blockCodeAdditionSince: period)) recordInfo.
×
133
        (entities collect: (self blockCodeDeletionSince: period)) recordInfo.
×
134

×
135
        "Commit frequencies "
×
136
        (entities collect: (self blockCommitFrequencySince: period))
×
137
                recordInfo.
×
138

×
139
        "comment contribution "
×
140
        (entities collect: (self blockCommentsContributionSince: period))
×
141
                recordInfo.
×
142

×
143
        "merge Request Duration "
×
144
        (entities collect: (self blockMergeRequestDurationSince: period))
×
145
                recordInfo.
×
146

×
147
        "code churn"
×
148
        (entities collect: (self blockCodeChurnSince: period)) recordInfo.
×
149

×
150
        "delay Until First Churn"
×
151
        (entities collect: (self blockDelayUntilFirstChurnSince: period))
×
152
                recordInfo.
×
153

×
154

×
155
        'Done computing debug' recordInfo
×
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 >> exportInCSVOver: aCollectionOfDateWeekMonthOrYear [
×
180

×
181
        | exportBrowserModel file |
×
182
        exportBrowserModel := MiExportModel new.
×
183

×
184
        self analyses ifNil: [ self generateAnalyses ].
×
185
        exportBrowserModel entitiesList: self analyses.
×
186

×
187
        exportBrowserModel removeColumnForQueryNamed: #Type.
×
188
        exportBrowserModel removeColumnForQueryNamed: #Name.
×
189

×
190
        exportBrowserModel
×
191
                addColumnForQuery: [ :analysis | analysis username ]
×
192
                withName: #'User name'.
×
193

×
194
        exportBrowserModel
×
195
                addColumnForQuery: [ :analysis | analysis period ]
×
196
                withName: #Period.
×
197

×
198
        "Code Contribution "
×
199
        exportBrowserModel
×
200
                addColumnForQuery: [ :analysis | analysis codeAddition ]
×
201
                withName: 'code addition (avg)' asSymbol.
×
202

×
203
        exportBrowserModel
×
204
                addColumnForQuery: [ :analysis | analysis codeDeletion ]
×
205
                withName: 'code deletion (avg)' asSymbol.
×
206

×
207
        "Commit frequencies "
×
208
        exportBrowserModel
×
209
                addColumnForQuery: [ :analysis | analysis commitFrequency ]
×
210
                withName: 'commits frequency (avg) ' asSymbol.
×
211

×
212
        "comment contribution "
×
213
        exportBrowserModel
×
214
                addColumnForQuery: [ :analysis | analysis commentContribution ]
×
215
                withName: 'comment contribution (avg)' asSymbol.
×
216

×
217
        "merge Request Duration "
×
218
        exportBrowserModel
×
219
                addColumnForQuery: [ :analysis | analysis mergeRequestDuration ]
×
220
                withName: 'merge Request Duration ' asSymbol.
×
221

×
222
        "code churn"
×
223
        exportBrowserModel
×
224
                addColumnForQuery: [ :analysis | analysis codeChurn ]
×
225
                withName:
×
226
                'churn % (W=' , maxCommitWindow printString , ') ' asSymbol.
×
227

×
228
        "delay Until First Churn"
×
229
        exportBrowserModel
×
230
                addColumnForQuery: [ :analysis | analysis delayUntilFirstChurn ]
×
231
                withName:
×
232
                        'delay Until First Churn (W=' , maxCommitWindow printString
×
233
                        , ') ' asSymbol.
×
234

×
235
        aCollectionOfDateWeekMonthOrYear do: [ :aDateWeekMonthOrYear |
×
236
                over := aDateWeekMonthOrYear.
×
237
                file := self constructFilePath: over.
×
238

×
239
                file writeStreamDo: [ :aStream |
×
240
                        aStream
×
241
                                << 'sep=,';
×
242
                                << OSPlatform current lineEnding.
×
243
                        exportBrowserModel writeCSVOn: aStream ] ].
×
244

×
245
        'Done computing' recordInfo
×
246
]
×
247

248
{ #category : #exporting }
249
GitMetricExporter >> exportInDB: repository [
×
250

×
251
        repository enableSingleton.
×
252

×
253
        self analyses ifNil: [ self generateAnalyses ].
×
254
        self analyses do: [ :analysis | analysis save ]
×
255
]
×
256

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

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

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

×
284
        ^ itsProjects
×
285
]
×
286

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

292
{ #category : #analysis }
293
GitMetricExporter >> generateAnalyses [
×
294

×
295
        | newAnalyses |
×
296
        newAnalyses := OrderedCollection new.
×
297

×
298
        runningPeriods do: [ :period |
×
299
                newAnalyses addAll: (entities collect: [ :entity |
×
300
                        entity
×
301
                                generateAnalysisForPeriod: period
×
302
                                over: over
×
303
                                withMaxCommitWindows: maxCommitWindow ]) ].
×
304

×
305
        self analyses: newAnalyses.
×
306

×
307
        ^ newAnalyses
×
308
]
×
309

310
{ #category : #accessing }
311
GitMetricExporter >> glhImporter: anImporter [
×
312

×
313
        glhImporter := anImporter withInitialCommits: false; yourself. 
×
314
]
×
315

316
{ #category : #initialization }
317
GitMetricExporter >> initialize [
×
318

×
319
        entities := OrderedCollection new.
×
320
        "set up the minimal date from which we are looking for the commits a particular user in projects"
×
321
        sinceTimeLimit := '2024-01-01' asDateAndTime..
×
322
        runningPeriods := OrderedCollection new.
×
323
        maxCommitWindow := 3.
×
324
        over := Date
×
325
]
×
326

327
{ #category : #accessing }
328
GitMetricExporter >> label: aString [ 
×
329
        label := aString
×
330
]
×
331

332
{ #category : #accessing }
333
GitMetricExporter >> maxCommitWindow: anInteger [
×
334
        maxCommitWindow := anInteger abs
×
335
]
×
336

337
{ #category : #adding }
338
GitMetricExporter >> onlyImportProjectsOfGroup: groupId [
×
339

×
340
        | group |
×
341
        group := glhImporter importGroup: groupId.
×
342
        projectCache := group toScope: GLHProject
×
343
]
×
344

345
{ #category : #adding }
NEW
346
GitMetricExporter >> setupAnalysisForUsersWithNames: userNames [
×
NEW
347
        "import all the project since a certain time"
×
NEW
348

×
NEW
349
        | users |
×
NEW
350
        users := userNames collect: [ :username |
×
NEW
351
                         glhImporter importUserByUsername: username ].
×
NEW
352

×
NEW
353
        glhImporter userCatalogue scrapeAuthorNamesForUsers: users.
×
NEW
354

×
NEW
355
        entities addAll: (users collect: [ :user |
×
NEW
356
                         | itsProjects metrics i size |
×
NEW
357
                         itsProjects := glhImporter importContributedProjectsOfUser: user.
×
NEW
358

×
NEW
359
                         metrics := GitMetric4User new.
×
NEW
360
                         metrics
×
NEW
361
                                 glhImporter: glhImporter;
×
NEW
362
                                 user: user.
×
NEW
363

×
NEW
364
                         i := 0.
×
NEW
365
                         size := itsProjects size.
×
NEW
366
                         metrics itsProjects: (itsProjects collect: [ :p |
×
NEW
367
                                          (' ' join: {
×
NEW
368
                                                           'complete import of project:'.
×
NEW
369
                                                           p name printString.
×
NEW
370
                                                           '['.
×
NEW
371
                                                           (i := i + 1) printString.
×
NEW
372
                                                           '/'.
×
NEW
373
                                                           size.
×
NEW
374
                                                           ']' }) recordInfo.
×
NEW
375

×
NEW
376
                                          p id -> (glhImporter completeImportProject: p) ]) asDictionary ]).
×
NEW
377

×
NEW
378
        ^ self
×
NEW
379
]
×
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