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

moosetechnology / GitProjectHealth / 9682577336

26 Jun 2024 03:32PM UTC coverage: 29.519% (+2.6%) from 26.896%
9682577336

Pull #7

github

web-flow
Merge 0d36202b7 into dfd76b711
Pull Request #7: Optimize code and writting tests

514 of 1154 new or added lines in 11 files covered. (44.54%)

17 existing lines in 3 files now uncovered.

2177 of 7375 relevant lines covered (29.52%)

0.3 hits per line

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

73.53
/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 : #import }
93
GLPHModelImporter >> importCommitsOfBranch: aGLHBranch [
×
94

×
95
        | commits |
×
96
        "        result := self glhApi
×
97
                          commitsOfProject: aGLHBranch repository project id
×
98
                          forRefName: aGLHBranch name."
×
99
        commits := self
×
100
                           importCommitsOfBranch: aGLHBranch
×
101
                           forRefName: aGLHBranch name
×
102
                           since: withCommitsSince.
×
103

×
104
        self chainsCommitsFrom: commits.
×
105

×
106
        commits do: [ :aCommit |
×
107
                aCommit repository: aGLHBranch repository.
×
108
                self completeImportedCommit: aCommit. 
×
109
                 ]
×
110
]
×
111

112
{ #category : #importer }
113
GLPHModelImporter >> importCommitsOfMergeResquest: aGLPHEMergeRequest [
1✔
114

1✔
115
        | foundCommits |
1✔
116
        foundCommits := OrderedCollection new.
1✔
117

1✔
118
        ('Import commit sha of MR:  ' , aGLPHEMergeRequest iid printString)
1✔
119
                recordInfo.
1✔
120
        "the founds commits are added to the model during their respective import"
1✔
121
        aGLPHEMergeRequest mergeRequestCommit: ((self
1✔
122
                          importCommitOfProject: aGLPHEMergeRequest project
1✔
123
                          withId: aGLPHEMergeRequest sha) ifNotNil: [ :commit |
1✔
124
                         foundCommits add: commit ]).
1✔
125

1✔
126
        ('Import commit merge_commit_sha of MR:  '
1✔
127
         , aGLPHEMergeRequest iid printString) recordInfo.
1✔
128
        aGLPHEMergeRequest mergedCommit: ((self
1✔
129
                          importCommitOfProject: aGLPHEMergeRequest project
1✔
130
                          withId: aGLPHEMergeRequest merge_commit_sha) ifNotNil: [ :commit |
1✔
131
                         foundCommits add: commit ]).
1✔
132

1✔
133
        ('Import commit squash_commit_sha of MR:  '
1✔
134
         , aGLPHEMergeRequest iid printString) recordInfo.
1✔
135
        aGLPHEMergeRequest squashCommit: ((self
1✔
136
                          importCommitOfProject: aGLPHEMergeRequest project
1✔
137
                          withId: aGLPHEMergeRequest squash_commit_sha) ifNotNil: [ :commit |
1✔
138
                         foundCommits add: commit ]).
1✔
139

1✔
140

1✔
141
        self chainsCommitsFrom: foundCommits.
1✔
142
        ^ foundCommits
1✔
143
]
1✔
144

145
{ #category : #api }
146
GLPHModelImporter >> importDiffOfCommit: aCommit [
1✔
147

1✔
148
        super importDiffOfCommit: aCommit.
1✔
149
        
1✔
150
        "changes are added into the model during the import"
1✔
151
        aCommit diffs do: [ :diff | self importDiffRangesForDiff: diff ].
1✔
152

1✔
153
        ^ aCommit diffs
1✔
154
]
1✔
155

156
{ #category : #'as yet unclassified' }
157
GLPHModelImporter >> importDiffOfMergeRequest: aMergeRequest [
1✔
158

1✔
159
        | result diffsResult |
1✔
160
        aMergeRequest diffs ifNotEmpty: [
1✔
161
                'Diff of already importer: '
1✔
162
                , aMergeRequest iid printString recordInfo.
1✔
163
                ^ aMergeRequest diffs ].
1✔
164
        ('Import diff commits of MR ' , aMergeRequest iid printString)
1✔
165
                recordInfo.
1✔
166
        result := self glhApi
1✔
167
                          diffsMergeRequestOfProject: aMergeRequest project_id
1✔
168
                          withId: aMergeRequest iid.
1✔
169

1✔
170
        diffsResult := self parseDiffResult: result.
1✔
171

1✔
172

1✔
173
        aMergeRequest diffs
1✔
174
                addAll: diffsResult
1✔
175
                unless: self blockForDiffEquality.
1✔
176
        self glhModel
1✔
177
                addAll: aMergeRequest diffs
1✔
178
                unless: self blockForDiffEquality.
1✔
179

1✔
180
        aMergeRequest diffs do: [ :diff | self importDiffRangesForDiff: diff ].
1✔
181

1✔
182
        ^ aMergeRequest diffs
1✔
183
]
1✔
184

185
{ #category : #import }
186
GLPHModelImporter >> importDiffRangesForDiff: aGLHDiff [
1✔
187

1✔
188
        | diffRanges |
1✔
189
        aGLHDiff diffRanges ifNotEmpty: [
1✔
190
                ('Diffs already imported for ' , aGLHDiff printString) recordInfo.
1✔
191
                ^ aGLHDiff diffRanges ].
1✔
192

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

1✔
196
        diffRanges := self glhModel
1✔
197
                              addAll: (self parseDiffString: aGLHDiff)
1✔
198
                              unless: self blockForDiffRangeEquality.
1✔
199
        ^ aGLHDiff diffRanges
1✔
200
                  addAll: diffRanges
1✔
201
                  unless: self blockForDiffRangeEquality
1✔
202
]
1✔
203

204
{ #category : #import }
205
GLPHModelImporter >> importMergeRequests: aGLHProject [
1✔
206

1✔
207
        | results parsedResults |
1✔
208
        
1✔
209
        ('Import merge request of Project:  ' , aGLHProject id printString) recordInfo.
1✔
210
        
1✔
211
        results := self glhApi mergeRequestOfProject: aGLHProject id.
1✔
212
        parsedResults := self parseMergeRequestResult: results.
1✔
213

1✔
214
        aGLHProject mergeRequests
1✔
215
                addAll: parsedResults
1✔
216
                unless: self blockOnIdEquality.
1✔
217

1✔
218
        self glhModel
1✔
219
                addAll: aGLHProject mergeRequests
1✔
220
                unless: self blockOnIdEquality.
1✔
221

1✔
222

1✔
223
        "gets it related commits"
1✔
224
        aGLHProject mergeRequests do: [ :mr |
1✔
225
                self importCommitsOfMergeResquest: mr ].
1✔
226

1✔
227

1✔
228
        self withCommitDiffs ifTrue: [
1✔
229
                aGLHProject mergeRequests do: [ :mr |
1✔
230
                        self importDiffOfMergeRequest: mr ] ]
1✔
231
]
1✔
232

233
{ #category : #import }
234
GLPHModelImporter >> importMergeRequests: aGLHProject since: fromDate until: toDate [
×
235

×
236
        | newlyFoundMR page foundMR |
×
NEW
237
        ('import MR of Project ' , aGLHProject name) recordInfo.
×
238

×
239
        page := 0.
×
240
        foundMR := OrderedCollection new.
×
241
        newlyFoundMR := { true }.
×
242
        [ newlyFoundMR isNotEmpty ] whileTrue: [
×
243
                | results |
×
244
                page := page + 1.
×
245
                ('import MR page ' , page printString) recordInfo.
×
246
                results := self glhApi
×
247
                                   mergeRequestsOfProject: aGLHProject id
×
248
                                   createdAfter:
×
249
                                   (fromDate ifNotNil: [ fromDate asDateAndTime asString ])
×
250
                                   createdBefore:
×
251
                                   (toDate ifNotNil: [ toDate asDateAndTime asString ])
×
252
                                   authorId: nil
×
253
                                   authorUsername: nil
×
254
                                   scope: 'all'
×
255
                                   orderBy: 'created_at'
×
256
                                   page: page.
×
257

×
258

×
259
                newlyFoundMR := aGLHProject mergeRequests
×
260
                                        addAll: (self parseMergeRequestResult: results)
×
261
                                        unless: self blockOnIdEquality.
×
262
                foundMR addAll: newlyFoundMR ].
×
263

×
264

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

×
269
        self withCommitDiffs ifTrue: [
×
270
                aGLHProject mergeRequests do: [ :mr |
×
271
                        self importDiffOfMergeRequest: mr ] ].
×
NEW
272
        
×
NEW
273
        self glhModel addAll: foundMR unless: (self blockEqualityOn: #iid).
×
274

×
275
        ^ foundMR
×
276
]
×
277

278
{ #category : #'as yet unclassified' }
279
GLPHModelImporter >> importProject: aProjectID [
1✔
280

1✔
281
        | result projectResult |
1✔
282
        ('Import project with id:  ' , aProjectID printString) recordInfo.
1✔
283

1✔
284
        result := self glhApi project: aProjectID.
1✔
285
        projectResult := self parseProjectResult: result.
1✔
286

1✔
287
        ^ self completeImportProject: projectResult
1✔
288
]
1✔
289

290
{ #category : #'private - api' }
291
GLPHModelImporter >> importRepository: aGLHRepository [
1✔
292

1✔
293
        super importRepository: aGLHRepository.
1✔
294

1✔
295
        withInitialCommits ifTrue: [
1✔
296
                aGLHRepository branches do: [ :branch |
1✔
297
                        self importCommitsOfBranch: branch ] ]
1✔
298
]
1✔
299

300
{ #category : #initialization }
301
GLPHModelImporter >> initialize [
1✔
302

1✔
303
        super initialize.
1✔
304
        withCommitDiffs := true
1✔
305
]
1✔
306

307
{ #category : #parsing }
308
GLPHModelImporter >> parseDiffString: aDiff [
1✔
309
        "parse diff string to create entities for each lines"
1✔
310

1✔
311
        | lines range index firstChangeRange |
1✔
312
        lines := aDiff diffString lines.
1✔
313
        index := 0.
1✔
314
        range := nil.
1✔
315

1✔
316
        lines ifEmpty: [ ^ aDiff diffRanges ].
1✔
317
        lines := self filterCommitChanges: lines.
1✔
318
        (lines first beginsWith: '@@') ifFalse: [ ^ aDiff diffRanges ].
1✔
319

1✔
320
        lines do: [ :line |
1✔
321
                | aChange |
1✔
322
                firstChangeRange := false.
1✔
323
                (line trim beginsWith: #'@@') ifTrue: [
1✔
324
                        range := GLPHEDiffRange newFrom: line.
1✔
325
                        firstChangeRange := true.
1✔
326
                        range := aDiff diffRanges add: range unless: [ :existing :new |
1✔
327
                                         existing originalLineRange = new originalLineRange and: [
1✔
328
                                                 existing newLineRange = new newLineRange ] ] ].
1✔
329

1✔
330
                self withCommitDiffs ifTrue: [
1✔
331
                        firstChangeRange ifFalse: [
1✔
332
                                aChange := GLPHEChange newFrom: line.
1✔
333
                                aChange relativeIndex: index.
1✔
334
                                aChange := range changes add: aChange unless: [ :existing :new |
1✔
335
                                                   existing sourceCode = new sourceCode and: [
1✔
336
                                                           existing index = new index ] ].
1✔
337
                                index := index + 1 ] ] ].
1✔
338

1✔
339
        "add changes to the diff range"
1✔
340
        aDiff diffRanges do: [ :diffRange |
1✔
341
                self glhModel addAll: diffRange changes unless: [ :existing :new |
1✔
342
                        existing diffRange mooseID = new diffRange mooseID and: [
1✔
343
                                existing sourceCode = new sourceCode and: [
1✔
344
                                        existing index = new index ] ] ] ].
1✔
345

1✔
346
        ^ aDiff diffRanges
1✔
347
]
1✔
348

349
{ #category : #parsing }
350
GLPHModelImporter >> parseMergeRequestResult: result [
1✔
351

1✔
352
        | reader |
1✔
353
        reader := NeoJSONReader on: result readStream.
1✔
354

1✔
355
        "declare quil y a un array a mapper"
1✔
356
        reader for: #ArrayOfMergeRequest customDo: [ :customMappting |
1✔
357
                customMappting listOfElementSchema: GLPHEMergeRequest ].
1✔
358

1✔
359
        "declare la liste des properties"
1✔
360
        reader for: GLPHEMergeRequest do: [ :mapping |
1✔
361
                mapping mapInstVars:
1✔
362
                        #( blocking_discussions_resolved changes_count description
1✔
363
                           detailed_merge_status discussion_locked downvotes draft first_deployed_to_production_at
1✔
364
                           force_remove_source_branch has_conflicts id iid labels latest_build_finished_at
1✔
365
                           latest_build_started_at merge_commit_sha merge_status
1✔
366
                           merge_when_pipeline_succeeds merged_at milestone project_id
1✔
367
                           reference references_full references_relative
1✔
368
                           references_short sha should_remove_source_branch
1✔
369
                           source_branch source_project_id squash squash_commit_sha
1✔
370
                           squash_on_merge state subscribed target_branch target_project_id
1✔
371
                           task_completion_status_completed_count
1✔
372
                           task_completion_status_count time_stats_human_time_estimate
1✔
373
                           time_stats_human_total_time_spent
1✔
374
                           time_stats_time_estimate time_stats_total_time_spent
1✔
375
                           title updated_at upvotes user_notes_count web_url work_in_progress ).
1✔
376
                        (mapping mapInstVar: #created_at) valueSchema: DateAndTime.
1✔
377
                        (mapping mapInstVar: #updated_at) valueSchema: DateAndTime.
1✔
378
                        (mapping mapInstVar: #merged_at) valueSchema: DateAndTime.
1✔
379
                        (mapping mapInstVar: #closed_at) valueSchema: DateAndTime.
1✔
380
                "                
1✔
381
                (mapping mapInstVar: #assignee) valueSchema: GLHUser.
1✔
382
                (mapping mapInstVar: #author) valueSchema: GLHUser.
1✔
383
                (mapping mapInstVar: #closed_by) valueSchema: GLHUser.
1✔
384
                (mapping mapInstVar: #mergeCommit) valueSchema: GLHCommit."
1✔
385

1✔
386
         ].
1✔
387

1✔
388
                "indique ce que doit faire le reader lorsqu'il parse une DateAndTime object"
1✔
389
                reader for: DateAndTime customDo: [ :mapping |
1✔
390
                mapping decoder: [ :string | string ifNil: [nil] ifNotNil: [ DateAndTime fromString: string ]   ] ].
1✔
391

1✔
392

1✔
393
        ^ reader nextAs: #ArrayOfMergeRequest
1✔
394
]
1✔
395

396
{ #category : #parsing }
397
GLPHModelImporter >> parseProjectResult: aResult [ 
1✔
398
                | reader |
1✔
399
        reader := NeoJSONReader on: aResult readStream.
1✔
400
        reader for: GLHProject do: [ :mapping |
1✔
401
                mapping mapInstVars. ].
1✔
402
"        reader mapInstVarsFor: GLHProject."
1✔
403

1✔
404
        ^ reader nextAs: GLHProject
1✔
405
]
1✔
406

1✔
407
{ #category : #accessing }
1✔
408
GLPHModelImporter >> withCommitsSince: someDays [
1✔
409
        "substract the current date with a given number of days. Use to retrieve the commits submit in the last giving days"
1✔
410
        "(GLPHModelImporter new withCommitsSince: 1 week ) >>> (Date today - 1 week) asDateAndTime"
1✔
411
        "(GLPHModelImporter new withCommitsSince: 30 day ) >>> (Date today - 30 day) asDateAndTime"
1✔
412
        withCommitsSince := (Date today - someDays) asDateAndTime
1✔
413
]
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