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

moosetechnology / GitProjectHealth / 9757524395

02 Jul 2024 08:25AM UTC coverage: 31.568% (+1.7%) from 29.879%
9757524395

Pull #8

github

web-flow
Merge 25e91c6b4 into 9a1cf1131
Pull Request #8: Fill merge request

160 of 164 new or added lines in 4 files covered. (97.56%)

9 existing lines in 1 file now uncovered.

2432 of 7704 relevant lines covered (31.57%)

0.32 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

71.12
/src/GitLabProjectHealth-Model-Importer/GLPHModelImporter.class.st
1
Class {
2
        #name : #GLPHModelImporter,
3
        #superclass : #GLHModelImporter,
4
        #category : #'GitLabProjectHealth-Model-Importer'
5
}
6

7
{ #category : #'as yet unclassified' }
8
GLPHModelImporter >> blockForDiffRangeEquality [
1✔
9

1✔
10
        ^ [ :existing :new |
1✔
11
          existing diff mooseID = new diff mooseID and: [
1✔
12
                  existing originalLineRange = new originalLineRange and: [
1✔
13
                          existing newLineRange = new newLineRange ] ] ]
1✔
14
]
1✔
15

16
{ #category : #commit }
17
GLPHModelImporter >> chainsCommitsFrom: commitsCollection [
1✔
18

1✔
19
        | dic |
1✔
20
        
1✔
21
        ('Chains ', commitsCollection size printString , ' commits') recordInfo.
1✔
22
        
1✔
23
        dic := ((self glhModel allWithType: GLHCommit) collect: [ :commit |
1✔
24
                        commit id -> commit ]) asSet asDictionary.
1✔
25

1✔
26
        commitsCollection do: [ :commit |
1✔
27
                commit parent_ids do: [ :parentId | 
1✔
28
                        dic
1✔
29
                                at: parentId
1✔
30
                                ifPresent: [ :parentCommit |
1✔
31
                                        parentCommit childCommits
1✔
32
                                                add: commit
1✔
33
                                                unless: self blockOnIdEquality ]
1✔
34
                                ifAbsent: [  ] ] ].
1✔
35
        ^ commitsCollection
1✔
36
]
1✔
37

38
{ #category : #commit }
39
GLPHModelImporter >> commitsOfProject: aGLHProject forRefName: refName until: toDate [
×
40

×
41
        | newlyFoundCommit page |
×
42
        page := 0.
×
43
        newlyFoundCommit := { true }.
×
44
        [ newlyFoundCommit isNotEmpty ] whileTrue: [
×
45
                | results parsedResults existingCommits |
×
46
                page := page + 1.
×
47
                ('import commit page ' , page printString) recordInfo.
×
48
                results := self glhApi
×
49
                                   commitsOfProject: aGLHProject id
×
50
                                   forRefName: refName
×
51
                                   since: nil
×
52
                                   until: nil
×
53
                                   path: nil
×
54
                                   author: nil
×
55
                                   all: nil
×
56
                                   with_stats: nil
×
57
                                   firstParent: nil
×
58
                                   order: nil
×
59
                                   trailers: nil
×
60
                                   perPage: 100
×
61
                                   page: page.
×
62
                parsedResults := self parseCommitsResult: results.
×
63
                existingCommits := aGLHProject mooseModel allWithType: GLHCommit.
×
64

×
65
                newlyFoundCommit := parsedResults reject: [ :commitParsed |
×
66
                                            (toDate isNil or: [
×
67
                                                     commitParsed committed_date
×
68
                                                     < toDate asDateAndTime ]) or: [
×
69
                                                    existingCommits anySatisfy: [ :existingCommit |
×
70
                                                            existingCommit id = commitParsed id ] ] ].
×
71
                self glhModel addAll: newlyFoundCommit unless: self blockOnIdEquality.
×
72
                aGLHProject repository commits addAll: newlyFoundCommit unless: self blockOnIdEquality  ].
×
73
        self withCommitDiffs ifTrue: [
×
74
                aGLHProject repository commits do: [ :commit |
×
75
                        self importDiffOfCommit: commit ] ]
×
76
]
×
77

78
{ #category : #'private - api' }
79
GLPHModelImporter >> completeImportProject: aGLHProject [
1✔
80

1✔
81
        super completeImportProject: aGLHProject.
1✔
82

1✔
83
        "for this initial import, with only look at some but not all MR"
1✔
84
        withInitialMergeRequest ifTrue: [ self
1✔
85
                importMergeRequests: aGLHProject
1✔
86
                since: DateAndTime today
1✔
87
                until: DateAndTime now. ].
1✔
88

1✔
89
        ^ aGLHProject
1✔
90
]
1✔
91

92
{ #category : #'private - configure reader' }
93
GLPHModelImporter >> configureReaderForMergeRequest: reader [
1✔
94
        "declare quil y a un array a mapper"
1✔
95

1✔
96
        reader for: #ArrayOfMergeRequest customDo: [ :customMappting |
1✔
97
                customMappting listOfElementSchema: GLPHEMergeRequest ].
1✔
98

1✔
99
        "declare la liste des properties"
1✔
100
        reader for: GLPHEMergeRequest do: [ :mapping |
1✔
101
                mapping mapInstVars:
1✔
102
                        #( blocking_discussions_resolved changes_count description
1✔
103
                           detailed_merge_status discussion_locked downvotes draft first_deployed_to_production_at
1✔
104
                           force_remove_source_branch has_conflicts id iid labels latest_build_finished_at
1✔
105
                           latest_build_started_at merge_commit_sha merge_status
1✔
106
                           merge_when_pipeline_succeeds merged_at milestone project_id
1✔
107
                           reference references_full references_relative
1✔
108
                           references_short sha should_remove_source_branch
1✔
109
                           source_branch source_project_id squash squash_commit_sha
1✔
110
                           squash_on_merge state subscribed target_branch target_project_id
1✔
111
                           task_completion_status_completed_count
1✔
112
                           task_completion_status_count time_stats_human_time_estimate
1✔
113
                           time_stats_human_total_time_spent
1✔
114
                           time_stats_time_estimate time_stats_total_time_spent
1✔
115
                           title updated_at upvotes user_notes_count web_url work_in_progress ).
1✔
116
                (mapping mapInstVar: #created_at) valueSchema: DateAndTime.
1✔
117
                (mapping mapInstVar: #updated_at) valueSchema: DateAndTime.
1✔
118
                (mapping mapInstVar: #merged_at) valueSchema: DateAndTime.
1✔
119
                (mapping mapInstVar: #closed_at) valueSchema: DateAndTime.
1✔
120
                "(mapping mapInstVar: #assignee) valueSchema: GLHUser."
1✔
121
                (mapping
1✔
122
                         mapProperty: #author
1✔
123
                         getter: [  ]
1✔
124
                         setter: [ :object :value | object cacheAt: #authorID put: (value at: #id) ]).
1✔
125
                "(mapping mapInstVar: #closed_by) valueSchema: GLHUser.
1✔
126
                (mapping mapInstVar: #mergeCommit) valueSchema: GLHCommit." ].
1✔
127

1✔
128
        "indique ce que doit faire le reader lorsqu'il parse une DateAndTime object"
1✔
129
        reader for: DateAndTime customDo: [ :mapping |
1✔
130
                mapping decoder: [ :string |
1✔
131
                        string ifNil: [ nil ] ifNotNil: [ DateAndTime fromString: string ] ] ]
1✔
132
]
1✔
133

134
{ #category : #import }
135
GLPHModelImporter >> importCommitsOfBranch: aGLHBranch [
×
136

×
137
        | commits |
×
138
        "        result := self glhApi
×
139
                          commitsOfProject: aGLHBranch repository project id
×
UNCOV
140
                          forRefName: aGLHBranch name."
×
UNCOV
141
        commits := self
×
142
                           importCommitsOfBranch: aGLHBranch
×
143
                           forRefName: aGLHBranch name
×
144
                           since: withCommitsSince.
×
145

×
146
        self chainsCommitsFrom: commits.
×
147

×
148
        commits do: [ :aCommit |
×
149
                aCommit repository: aGLHBranch repository.
×
150
                self completeImportedCommit: aCommit. 
×
151
                 ]
×
152
]
×
153

154
{ #category : #import }
155
GLPHModelImporter >> importCommitsOfMergeResquest: aGLPHEMergeRequest [
1✔
156

1✔
157
        | foundCommits |
1✔
158
        foundCommits := OrderedCollection new.
1✔
159

1✔
160
        ('Import commit sha of MR:  ' , aGLPHEMergeRequest iid printString)
1✔
161
                recordInfo.
1✔
162
        "the founds commits are added to the model during their respective import"
1✔
163
        aGLPHEMergeRequest mergeRequestCommit: ((self
1✔
164
                          importCommitOfProject: aGLPHEMergeRequest project
1✔
165
                          withId: aGLPHEMergeRequest sha) ifNotNil: [ :commit |
1✔
166
                         foundCommits add: commit ]).
1✔
167

1✔
168
        ('Import commit merge_commit_sha of MR:  '
1✔
169
         , aGLPHEMergeRequest iid printString) recordInfo.
1✔
170
        aGLPHEMergeRequest mergedCommit: ((self
1✔
171
                          importCommitOfProject: aGLPHEMergeRequest project
1✔
172
                          withId: aGLPHEMergeRequest merge_commit_sha) ifNotNil: [ :commit |
1✔
173
                         foundCommits add: commit ]).
1✔
174

1✔
175
        ('Import commit squash_commit_sha of MR:  '
1✔
176
         , aGLPHEMergeRequest iid printString) recordInfo.
1✔
177
        aGLPHEMergeRequest squashCommit: ((self
1✔
178
                          importCommitOfProject: aGLPHEMergeRequest project
1✔
179
                          withId: aGLPHEMergeRequest squash_commit_sha) ifNotNil: [ :commit |
1✔
180
                         foundCommits add: commit ]).
1✔
181

1✔
182

1✔
183
        self chainsCommitsFrom: foundCommits.
1✔
184
        ^ foundCommits
1✔
185
]
1✔
186

187
{ #category : #api }
188
GLPHModelImporter >> importDiffOfCommit: aCommit [
1✔
189

1✔
190
        super importDiffOfCommit: aCommit.
1✔
191
        
1✔
192
        "changes are added into the model during the import"
1✔
193
        aCommit diffs do: [ :diff | self importDiffRangesForDiff: diff ].
1✔
194

1✔
195
        ^ aCommit diffs
1✔
196
]
1✔
197

198
{ #category : #'as yet unclassified' }
199
GLPHModelImporter >> importDiffOfMergeRequest: aMergeRequest [
1✔
200

1✔
201
        | result diffsResult |
1✔
202
        aMergeRequest diffs ifNotEmpty: [
1✔
203
                'Diff of already importer: '
1✔
204
                , aMergeRequest iid printString recordInfo.
1✔
205
                ^ aMergeRequest diffs ].
1✔
206
        ('Import diff commits of MR ' , aMergeRequest iid printString)
1✔
207
                recordInfo.
1✔
208
        result := self glhApi
1✔
209
                          diffsMergeRequestOfProject: aMergeRequest project_id
1✔
210
                          withId: aMergeRequest iid.
1✔
211

1✔
212
        diffsResult := self parseDiffResult: result.
1✔
213

1✔
214

1✔
215
        aMergeRequest diffs
1✔
216
                addAll: diffsResult
1✔
217
                unless: self blockForDiffEquality.
1✔
218
        self glhModel
1✔
219
                addAll: aMergeRequest diffs
1✔
220
                unless: self blockForDiffEquality.
1✔
221

1✔
222
        aMergeRequest diffs do: [ :diff | self importDiffRangesForDiff: diff ].
1✔
223

1✔
224
        ^ aMergeRequest diffs
1✔
225
]
1✔
226

227
{ #category : #import }
228
GLPHModelImporter >> importDiffRangesForDiff: aGLHDiff [
1✔
229

1✔
230
        | diffRanges |
1✔
231
        aGLHDiff diffRanges ifNotEmpty: [
1✔
232
                ('Diffs already imported for ' , aGLHDiff printString) recordInfo.
1✔
233
                ^ aGLHDiff diffRanges ].
1✔
234

1✔
235
        ('Import changes of diff ' , aGLHDiff printString) recordInfo.
1✔
236
        "the import of 'diffRanges' entites is technically done inside the parseDiffString"
1✔
237

1✔
238
        diffRanges := self glhModel
1✔
239
                              addAll: (self parseDiffString: aGLHDiff)
1✔
240
                              unless: self blockForDiffRangeEquality.
1✔
241
        ^ aGLHDiff diffRanges
1✔
242
                  addAll: diffRanges
1✔
243
                  unless: self blockForDiffRangeEquality
1✔
244
]
1✔
245

246
{ #category : #'import - merge request' }
247
GLPHModelImporter >> importMergeRequests: aGLHProject [
1✔
248

1✔
249
        | results parsedResults |
1✔
250
        ('Import merge request of Project: ' , aGLHProject id printString)
1✔
251
                recordInfo.
1✔
252

1✔
253
        results := self glhApi mergeRequestOfProject: aGLHProject id.
1✔
254
        parsedResults := self parseMergeRequestResult: results.
1✔
255

1✔
256
        aGLHProject mergeRequests
1✔
257
                addAll: parsedResults
1✔
258
                unless: self blockOnIdEquality.
1✔
259

1✔
260
        self glhModel
1✔
261
                addAll: aGLHProject mergeRequests
1✔
262
                unless: self blockOnIdEquality.
1✔
263

1✔
264

1✔
265
        "gets it related commits"
1✔
266
        aGLHProject mergeRequests do: [ :mr |
1✔
267
                self importCommitsOfMergeResquest: mr ].
1✔
268

1✔
269

1✔
270
        self withCommitDiffs ifTrue: [
1✔
271
                aGLHProject mergeRequests do: [ :mr |
1✔
272
                        self importDiffOfMergeRequest: mr ] ]
1✔
273
]
1✔
274

275
{ #category : #'import - merge request' }
UNCOV
276
GLPHModelImporter >> importMergeRequests: aGLHProject since: fromDate until: toDate [
×
UNCOV
277

×
UNCOV
278
        | newlyFoundMR page foundMR |
×
UNCOV
279
        ('import MR of Project ' , aGLHProject name) recordInfo.
×
UNCOV
280

×
UNCOV
281
        page := 0.
×
282
        foundMR := OrderedCollection new.
×
283
        newlyFoundMR := { true }.
×
284
        [ newlyFoundMR isNotEmpty ] whileTrue: [
×
285
                | results |
×
286
                page := page + 1.
×
287
                ('import MR page ' , page printString) recordInfo.
×
288
                results := self glhApi
×
289
                                   mergeRequestsOfProject: aGLHProject id
×
290
                                   createdAfter:
×
291
                                   (fromDate ifNotNil: [ fromDate asDateAndTime asString ])
×
292
                                   createdBefore:
×
293
                                   (toDate ifNotNil: [ toDate asDateAndTime asString ])
×
294
                                   authorId: nil
×
295
                                   authorUsername: nil
×
296
                                   scope: 'all'
×
297
                                   orderBy: 'created_at'
×
298
                                   page: page.
×
299

×
300

×
301
                newlyFoundMR := aGLHProject mergeRequests
×
302
                                        addAll: (self parseMergeRequestResult: results)
×
303
                                        unless: self blockOnIdEquality.
×
304
                foundMR addAll: newlyFoundMR ].
×
305

×
306

×
307
        "gets it related commits"
×
308
        aGLHProject mergeRequests do: [ :mr |
×
309
                self importCommitsOfMergeResquest: mr ].
×
310

×
311
        self withCommitDiffs ifTrue: [
×
312
                aGLHProject mergeRequests do: [ :mr |
×
313
                        self importDiffOfMergeRequest: mr ] ].
×
314
        
×
315
        self glhModel addAll: foundMR unless: (self blockEqualityOn: #iid).
×
316

×
317
        ^ foundMR
×
318
]
×
319

320
{ #category : #'import - merge request' }
321
GLPHModelImporter >> importMergeResquestApprovals: aGLPHEMergeRequest [
×
322

×
323
        | results parsedResult |
×
324
        (String streamContents: [ :str |
×
325
                 str << 'Check approvals of '.
×
UNCOV
326
                 aGLPHEMergeRequest printOn: str ]) recordInfo.
×
327
        results := self glhApi
×
328
                           approvalsOfMergeQuest: aGLPHEMergeRequest iid
×
329
                           ofProject: aGLPHEMergeRequest project id.
×
330

×
331
        parsedResult := generalReader
×
332
                                on: results readStream;
×
333
                                next.
×
NEW
334

×
NEW
335
        (parsedResult at: #approved_by) do: [ :approvedUser |
×
NEW
336
                aGLPHEMergeRequest addApproved_by:
×
NEW
337
                        (self importUser: ((approvedUser at: #user) at: #id)) ].
×
338
        aGLPHEMergeRequest approved: (parsedResult at: #approved).
×
339
        ^ aGLPHEMergeRequest
×
340
]
×
341

342
{ #category : #'import - merge request' }
343
GLPHModelImporter >> importMergeResquestAuthor: aGLPHEMergeRequest [
1✔
344

1✔
345
        | authorID |
1✔
346
        aGLPHEMergeRequest author ifNotNil: [ ^ aGLPHEMergeRequest author ].
1✔
347
        authorID := aGLPHEMergeRequest cacheAt: #authorID ifAbsent: [
1✔
348
                            (generalReader
1✔
349
                                     on: (self glhApi
1✔
350
                                                      mergeRequestOfProject:
1✔
351
                                                              aGLPHEMergeRequest project_id
1✔
352
                                                      withId: aGLPHEMergeRequest iid) readStream;
1✔
353
                                     next) at: #author at: #id ].
1✔
354
        aGLPHEMergeRequest author: (self importUser: authorID)
1✔
355
]
1✔
356

357
{ #category : #'as yet unclassified' }
358
GLPHModelImporter >> importProject: aProjectID [
1✔
359

1✔
360
        | result projectResult |
1✔
361
        ('Import project with id:  ' , aProjectID printString) recordInfo.
1✔
362

1✔
363
        result := self glhApi project: aProjectID.
1✔
364
        projectResult := self parseProjectResult: result.
1✔
365

1✔
366
        ^ self completeImportProject: projectResult
1✔
367
]
1✔
368

369
{ #category : #'private - api' }
370
GLPHModelImporter >> importRepository: aGLHRepository [
1✔
371

1✔
372
        super importRepository: aGLHRepository.
1✔
373

1✔
374
        withInitialCommits ifTrue: [
1✔
375
                aGLHRepository branches do: [ :branch |
1✔
376
                        self importCommitsOfBranch: branch ] ]
1✔
377
]
1✔
378

379
{ #category : #initialization }
380
GLPHModelImporter >> initReader [
1✔
381

1✔
382
        super initReader.
1✔
383
        self configureReaderForMergeRequest: generalReader
1✔
384
]
1✔
385

386
{ #category : #initialization }
387
GLPHModelImporter >> initialize [
1✔
388

1✔
389
        super initialize.
1✔
390
        withCommitDiffs := true
1✔
391
]
1✔
392

393
{ #category : #parsing }
394
GLPHModelImporter >> parseDiffString: aDiff [
1✔
395
        "parse diff string to create entities for each lines"
1✔
396

1✔
397
        | lines range index firstChangeRange |
1✔
398
        lines := aDiff diffString lines.
1✔
399
        index := 0.
1✔
400
        range := nil.
1✔
401

1✔
402
        lines ifEmpty: [ ^ aDiff diffRanges ].
1✔
403
        lines := self filterCommitChanges: lines.
1✔
404
        (lines first beginsWith: '@@') ifFalse: [ ^ aDiff diffRanges ].
1✔
405

1✔
406
        lines do: [ :line |
1✔
407
                | aChange |
1✔
408
                firstChangeRange := false.
1✔
409
                (line trim beginsWith: #'@@') ifTrue: [
1✔
410
                        range := GLPHEDiffRange newFrom: line.
1✔
411
                        firstChangeRange := true.
1✔
412
                        range := aDiff diffRanges add: range unless: [ :existing :new |
1✔
413
                                         existing originalLineRange = new originalLineRange and: [
1✔
414
                                                 existing newLineRange = new newLineRange ] ] ].
1✔
415

1✔
416
                self withCommitDiffs ifTrue: [
1✔
417
                        firstChangeRange ifFalse: [
1✔
418
                                aChange := GLPHEChange newFrom: line.
1✔
419
                                aChange relativeIndex: index.
1✔
420
                                aChange := range changes add: aChange unless: [ :existing :new |
1✔
421
                                                   existing sourceCode = new sourceCode and: [
1✔
422
                                                           existing index = new index ] ].
1✔
423
                                index := index + 1 ] ] ].
1✔
424

1✔
425
        "add changes to the diff range"
1✔
426
        aDiff diffRanges do: [ :diffRange |
1✔
427
                self glhModel addAll: diffRange changes unless: [ :existing :new |
1✔
428
                        existing diffRange mooseID = new diffRange mooseID and: [
1✔
429
                                existing sourceCode = new sourceCode and: [
1✔
430
                                        existing index = new index ] ] ] ].
1✔
431

1✔
432
        ^ aDiff diffRanges
1✔
433
]
1✔
434

435
{ #category : #parsing }
436
GLPHModelImporter >> parseMergeRequestResult: result [
1✔
437

1✔
438
        generalReader on: result readStream.
1✔
439
        ^ generalReader nextAs: #ArrayOfMergeRequest
1✔
440
]
1✔
441

442
{ #category : #parsing }
443
GLPHModelImporter >> parseProjectResult: aResult [ 
1✔
444
                | reader |
1✔
445
        reader := NeoJSONReader on: aResult readStream.
1✔
446
        reader for: GLHProject do: [ :mapping |
1✔
447
                mapping mapInstVars. ].
1✔
448
"        reader mapInstVarsFor: GLHProject."
1✔
449

1✔
450
        ^ reader nextAs: GLHProject
1✔
451
]
1✔
452

1✔
453
{ #category : #accessing }
1✔
454
GLPHModelImporter >> withCommitsSince: someDays [
1✔
455
        "substract the current date with a given number of days. Use to retrieve the commits submit in the last giving days"
1✔
456
        "(GLPHModelImporter new withCommitsSince: 1 week ) >>> (Date today - 1 week) asDateAndTime"
1✔
457
        "(GLPHModelImporter new withCommitsSince: 30 day ) >>> (Date today - 30 day) asDateAndTime"
1✔
458
        withCommitsSince := (Date today - someDays) asDateAndTime
1✔
459
]
1✔
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