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

moosetechnology / GitProjectHealth / 11498155021

24 Oct 2024 11:15AM UTC coverage: 59.724% (+0.8%) from 58.906%
11498155021

push

github

web-flow
Merge pull request #96 from moosetechnology/develop

Develop

713 of 970 new or added lines in 22 files covered. (73.51%)

15 existing lines in 5 files now uncovered.

9449 of 15821 relevant lines covered (59.72%)

0.6 hits per line

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

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

7
{ #category : #commit }
UNCOV
8
GLPHModelImporter >> commitsOfProject: aGLHProject forRefName: refName until: toDate [
×
9

×
10
        | newlyFoundCommit page |
×
11
        page := 0.
×
12
        newlyFoundCommit := { true }.
×
13
        [ newlyFoundCommit isNotEmpty ] whileTrue: [
×
14
                | results parsedResults existingCommits |
×
15
                page := page + 1.
×
16
                ('import commit page ' , page printString) recordInfo.
×
17
                results := self glhApi
×
18
                                   commitsOfProject: aGLHProject id
×
19
                                   forRefName: refName
×
20
                                   since: nil
×
21
                                   until: nil
×
22
                                   path: nil
×
23
                                   author: nil
×
24
                                   all: nil
×
25
                                   with_stats: nil
×
26
                                   firstParent: nil
×
27
                                   order: nil
×
28
                                   trailers: nil
×
29
                                   perPage: 100
×
30
                                   page: page.
×
31
                parsedResults := self parseCommitsResult: results.
×
32
                existingCommits := aGLHProject mooseModel allWithType: GLHCommit.
×
33

×
34
                newlyFoundCommit := parsedResults reject: [ :commitParsed |
×
35
                                            (toDate isNil or: [
×
36
                                                     commitParsed committed_date
×
37
                                                     < toDate asDateAndTime ]) or: [
×
38
                                                    existingCommits anySatisfy: [ :existingCommit |
×
39
                                                            existingCommit id = commitParsed id ] ] ].
×
40
                self glhModel addAll: newlyFoundCommit unless: self blockOnIdEquality.
×
41
                aGLHProject repository commits addAll: newlyFoundCommit unless: self blockOnIdEquality  ].
×
42
        self withCommitDiffs ifTrue: [
×
43
                aGLHProject repository commits do: [ :commit |
×
44
                        self importDiffOfCommit: commit ] ]
×
45
]
×
46

47
{ #category : #'private - api' }
48
GLPHModelImporter >> completeImportProject: aGLHProject [
1✔
49
        |completedProject|
1✔
50
        completedProject := super completeImportProject: aGLHProject.
1✔
51

1✔
52
        "for this initial import, with only look at some but not all MR"
1✔
53
        withInitialMergeRequest ifTrue: [ self
1✔
54
                importMergeRequests: completedProject
1✔
55
                since: DateAndTime today
1✔
56
                until: DateAndTime now. ].
1✔
57

1✔
58
        ^ completedProject
1✔
59
]
1✔
60

61
{ #category : #'private - configure reader' }
62
GLPHModelImporter >> configureReaderForMergeRequest: reader [
1✔
63
        "declare quil y a un array a mapper"
1✔
64

1✔
65
        reader for: #ArrayOfMergeRequest customDo: [ :customMappting |
1✔
66
                customMappting listOfElementSchema: GLPHEMergeRequest ].
1✔
67

1✔
68
        "declare la liste des properties"
1✔
69
        reader for: GLPHEMergeRequest do: [ :mapping |
1✔
70
                mapping mapInstVars:
1✔
71
                        #( blocking_discussions_resolved changes_count description
1✔
72
                           detailed_merge_status discussion_locked downvotes draft first_deployed_to_production_at
1✔
73
                           force_remove_source_branch has_conflicts id iid labels latest_build_finished_at
1✔
74
                           latest_build_started_at merge_commit_sha merge_status
1✔
75
                           merge_when_pipeline_succeeds merged_at milestone project_id
1✔
76
                           reference references_full references_relative
1✔
77
                           references_short sha should_remove_source_branch
1✔
78
                           source_branch source_project_id squash squash_commit_sha
1✔
79
                           squash_on_merge state subscribed target_branch target_project_id
1✔
80
                           task_completion_status_completed_count
1✔
81
                           task_completion_status_count time_stats_human_time_estimate
1✔
82
                           time_stats_human_total_time_spent
1✔
83
                           time_stats_time_estimate time_stats_total_time_spent
1✔
84
                           title updated_at upvotes user_notes_count web_url work_in_progress ).
1✔
85
                (mapping mapInstVar: #created_at) valueSchema: DateAndTime.
1✔
86
                (mapping mapInstVar: #updated_at) valueSchema: DateAndTime.
1✔
87
                (mapping mapInstVar: #merged_at) valueSchema: DateAndTime.
1✔
88
                (mapping mapInstVar: #closed_at) valueSchema: DateAndTime.
1✔
89
                "(mapping mapInstVar: #assignee) valueSchema: GLHUser."
1✔
90
                mapping
1✔
91
                        mapProperty: #author
1✔
92
                        getter: [  ]
1✔
93
                        setter: [ :object :value |
1✔
94
                        object cacheAt: #authorID put: (value at: #id) ].
1✔
95
                mapping
1✔
96
                        mapProperty: #merge_user
1✔
97
                        getter: [  ]
1✔
98
                        setter: [ :object :value | 
1✔
99
                                value ifNotNil: [
1✔
100
                                        object cacheAt: #mergeUserID put: (value at: #id) ] ] ].
1✔
101

1✔
102
        "(mapping mapInstVar: #closed_by) valueSchema: GLHUser.
1✔
103
        (mapping mapInstVar: #mergeCommit) valueSchema: GLHCommit."
1✔
104
        "indique ce que doit faire le reader lorsqu'il parse une DateAndTime object"
1✔
105
        reader for: DateAndTime customDo: [ :mapping |
1✔
106
                mapping decoder: [ :string |
1✔
107
                        string ifNil: [ nil ] ifNotNil: [ DateAndTime fromString: string ] ] ]
1✔
108
]
1✔
109

110
{ #category : #import }
111
GLPHModelImporter >> importCommitsOfBranch: aGLHBranch [
×
112

×
113
        | commits |
×
114
        "        result := self glhApi
×
115
                          commitsOfProject: aGLHBranch repository project id
×
116
                          forRefName: aGLHBranch name."
×
117
        commits := self
×
118
                           importCommitsOfBranch: aGLHBranch
×
119
                           forRefName: aGLHBranch name
×
120
                           since: withCommitsSince.
×
121

×
122
        self chainsCommitsFrom: commits.
×
123

×
124
        commits do: [ :aCommit |
×
125
                aCommit repository: aGLHBranch repository.
×
126
                self completeImportedCommit: aCommit. 
×
127
                 ]
×
128
]
×
129

130
{ #category : #api }
131
GLPHModelImporter >> importDiffOfCommit: aCommit [
1✔
132

1✔
133
        super importDiffOfCommit: aCommit.
1✔
134
        
1✔
135
        "changes are added into the model during the import"
1✔
136
        aCommit diffs do: [ :diff | self importDiffRangesForDiff: diff ].
1✔
137

1✔
138
        ^ aCommit diffs
1✔
139
]
1✔
140

141
{ #category : #'as yet unclassified' }
142
GLPHModelImporter >> importDiffOfMergeRequest: aMergeRequest [
1✔
143

1✔
144
        | result diffsResult |
1✔
145
        aMergeRequest diffs ifNotEmpty: [
1✔
146
                'Diff of already importer: '
1✔
147
                , aMergeRequest iid printString recordInfo.
1✔
148
                ^ aMergeRequest diffs ].
1✔
149
        ('Import diff commits of MR ' , aMergeRequest iid printString)
1✔
150
                recordInfo.
1✔
151
        result := self glhApi
1✔
152
                          diffsMergeRequestOfProject: aMergeRequest project_id
1✔
153
                          withId: aMergeRequest iid.
1✔
154

1✔
155
        diffsResult := self newParseDiffResult: result.
1✔
156

1✔
157

1✔
158
        aMergeRequest diffs
1✔
159
                addAll: diffsResult
1✔
160
                unless: self blockForDiffEquality.
1✔
161
        self glhModel
1✔
162
                addAll: aMergeRequest diffs
1✔
163
                unless: self blockForDiffEquality.
1✔
164

1✔
165
        aMergeRequest diffs do: [ :diff | self importDiffRangesForDiff: diff ].
1✔
166

1✔
167
        ^ aMergeRequest diffs
1✔
168
]
1✔
169

170
{ #category : #'import - merge request' }
UNCOV
171
GLPHModelImporter >> importMergeRequestCommits: aGLPHEMergeRequest [
×
172

×
173
        | results page commits parseResult |
×
174
        aGLPHEMergeRequest commits ifNotNil: [ ^ aGLPHEMergeRequest commits ].
×
175
        page := 1.
×
176

×
177
        parseResult := { nil }.
×
178
        commits := OrderedCollection new.
×
179

×
180
        [
×
NEW
181
        results := repoApi
×
182
                           commitsOfMergeRequest: aGLPHEMergeRequest iid
×
183
                           ofProject: aGLPHEMergeRequest project id
×
184
                           page: page
×
185
                           perPage: 100.
×
186
        parseResult := self parseCommitsResult: results.
×
187

×
188
        commits addAll: parseResult.
×
189
        page := page + 1 ] doWhileTrue: [ parseResult isNotEmpty ].
×
190

×
191

×
192
        commits := commits collect: [ :commit | self importCommit: commit id ofProject: aGLPHEMergeRequest project ].
×
193
        aGLPHEMergeRequest commits: commits.
×
194

×
195

×
196
        ^ commits
×
197
]
×
198

199
{ #category : #import }
200
GLPHModelImporter >> importMergeRequestMergeCommits: aGLPHEMergeRequest [
1✔
201

1✔
202
        | foundCommits |
1✔
203
        foundCommits := OrderedCollection new.
1✔
204

1✔
205
        ('Import commit sha of MR:  ' , aGLPHEMergeRequest iid printString)
1✔
206
                recordInfo.
1✔
207
        "the founds commits are added to the model during their respective import"
1✔
208
        aGLPHEMergeRequest mergeRequestCommit: ((self
1✔
209
                          importCommitOfProject: aGLPHEMergeRequest project
1✔
210
                          withId: aGLPHEMergeRequest sha) ifNotNil: [ :commit |
1✔
211
                         foundCommits add: commit ]).
1✔
212

1✔
213
        ('Import commit merge_commit_sha of MR:  '
1✔
214
         , aGLPHEMergeRequest iid printString) recordInfo.
1✔
215
        aGLPHEMergeRequest mergedCommit: ((self
1✔
216
                          importCommitOfProject: aGLPHEMergeRequest project
1✔
217
                          withId: aGLPHEMergeRequest merge_commit_sha) ifNotNil: [ :commit |
1✔
218
                         foundCommits add: commit ]).
1✔
219

1✔
220
        ('Import commit squash_commit_sha of MR:  '
1✔
221
         , aGLPHEMergeRequest iid printString) recordInfo.
1✔
222
        aGLPHEMergeRequest squashCommit: ((self
1✔
223
                          importCommitOfProject: aGLPHEMergeRequest project
1✔
224
                          withId: aGLPHEMergeRequest squash_commit_sha) ifNotNil: [ :commit |
1✔
225
                         foundCommits add: commit ]).
1✔
226

1✔
227

1✔
228
        self chainsCommitsFrom: foundCommits.
1✔
229
        ^ foundCommits
1✔
230
]
1✔
231

232
{ #category : #'import - merge request' }
233
GLPHModelImporter >> importMergeRequests: aGLHProject [
1✔
234

1✔
235
        | results parsedResults mrs|
1✔
236
        ('Import merge request of Project: ' , aGLHProject id printString)
1✔
237
                recordInfo.
1✔
238

1✔
239
        results := self glhApi mergeRequestOfProject: aGLHProject id.
1✔
240
        parsedResults := self parseMergeRequestResult: results.
1✔
241

1✔
242
        aGLHProject mergeRequests
1✔
243
                addAll: parsedResults
1✔
244
                unless: self blockOnIdEquality.
1✔
245

1✔
246
        mrs := self glhModel
1✔
247
                addAll: aGLHProject mergeRequests
1✔
248
                unless: self blockOnIdEquality.
1✔
249

1✔
250

1✔
251
        "gets it related commits"
1✔
252
        aGLHProject mergeRequests do: [ :mr |
1✔
253
                self importMergeRequestMergeCommits: mr ].
1✔
254

1✔
255

1✔
256
        self withCommitDiffs ifTrue: [
1✔
257
                aGLHProject mergeRequests do: [ :mr |
1✔
258
                        self importDiffOfMergeRequest: mr ] ].
1✔
259
        
1✔
260
        ^ mrs
1✔
261
]
1✔
262

263
{ #category : #'import - merge request' }
264
GLPHModelImporter >> importMergeRequests: aGLHProject since: fromDate until: toDate [
×
265

×
266
        | newlyFoundMR page foundMR |
×
267
        ('import MR of Project ' , aGLHProject name) recordInfo.
×
268

×
269
        page := 0.
×
270
        foundMR := OrderedCollection new.
×
271
        newlyFoundMR := { true }.
×
272
        [ newlyFoundMR isNotEmpty ] whileTrue: [
×
273
                | results |
×
274
                page := page + 1.
×
275
                ('import MR page ' , page printString) recordInfo.
×
NEW
276
                results := self repoApi
×
277
                                   mergeRequestsOfProject: aGLHProject id
×
278
                                   createdAfter:
×
279
                                   (fromDate ifNotNil: [ fromDate asDateAndTime asString ])
×
280
                                   createdBefore:
×
281
                                   (toDate ifNotNil: [ toDate asDateAndTime asString ])
×
282
                                   authorId: nil
×
283
                                   authorUsername: nil
×
284
                                   scope: 'all'
×
285
                                   orderBy: 'created_at'
×
286
                                   page: page.
×
287

×
288

×
289
                newlyFoundMR := aGLHProject mergeRequests
×
290
                                        addAll: (self parseMergeRequestResult: results)
×
291
                                        unless: self blockOnIdEquality.
×
292
                foundMR addAll: newlyFoundMR ].
×
293

×
294

×
295
        "gets it related commits"
×
296
        aGLHProject mergeRequests do: [ :mr |
×
297
                self importMergeRequestMergeCommits: mr ].
×
298

×
299
        self withCommitDiffs ifTrue: [
×
300
                aGLHProject mergeRequests do: [ :mr |
×
301
                        self importDiffOfMergeRequest: mr ] ].
×
302

×
303
        self glhModel addAll: foundMR unless: (self blockEqualityOn: #iid).
×
304

×
305
        ^ foundMR
×
306
]
×
307

308
{ #category : #'import - merge request' }
309
GLPHModelImporter >> importMergeResquestApprovals: aGLPHEMergeRequest [
×
310

×
311
        | results parsedResult |
×
312
        (String streamContents: [ :str |
×
313
                 str << 'Check approvals of '.
×
314
                 aGLPHEMergeRequest printOn: str ]) recordInfo.
×
315
        results := self glhApi
×
316
                           approvalsOfMergeQuest: aGLPHEMergeRequest iid
×
317
                           ofProject: aGLPHEMergeRequest project id.
×
318

×
319
        parsedResult := generalReader
×
320
                                on: results readStream;
×
321
                                next.
×
322

×
323
        (parsedResult at: #approved_by) do: [ :approvedUser |
×
324
                aGLPHEMergeRequest addApproved_by:
×
325
                        (self importUser: ((approvedUser at: #user) at: #id)) ].
×
326
        aGLPHEMergeRequest approved: (parsedResult at: #approved).
×
327
        ^ aGLPHEMergeRequest
×
328
]
×
329

330
{ #category : #'import - merge request' }
331
GLPHModelImporter >> importMergeResquestAuthor: aGLPHEMergeRequest [
1✔
332

1✔
333
        | authorID |
1✔
334
        aGLPHEMergeRequest author ifNotNil: [ ^ aGLPHEMergeRequest author ].
1✔
335
        authorID := aGLPHEMergeRequest cacheAt: #authorID ifAbsent: [
1✔
336
                            (generalReader
1✔
337
                                     on: (self glhApi
1✔
338
                                                      mergeRequestOfProject:
1✔
339
                                                              aGLPHEMergeRequest project_id
1✔
340
                                                      withId: aGLPHEMergeRequest iid) readStream;
1✔
341
                                     next) at: #author at: #id ].
1✔
342
        aGLPHEMergeRequest author: (self importUser: authorID)
1✔
343
]
1✔
344

345
{ #category : #'import - merge request' }
346
GLPHModelImporter >> importMergeResquestMerger: aGLPHEMergeRequest [
1✔
347

1✔
348
        | authorID |
1✔
349
        aGLPHEMergeRequest merge_user ifNotNil: [
1✔
350
                ^ aGLPHEMergeRequest merge_user ].
1✔
351
        authorID := aGLPHEMergeRequest cacheAt: #mergeUserID ifAbsent: [
1✔
352
                            (generalReader
1✔
353
                                     on: (self glhApi
1✔
354
                                                      mergeRequestOfProject:
1✔
355
                                                              aGLPHEMergeRequest project_id
1✔
356
                                                      withId: aGLPHEMergeRequest iid) readStream;
1✔
357
                                     next)
1✔
358
                                    at: #merge_user
1✔
359
                                    ifPresent: [ :mergeUser |
1✔
360
                                    mergeUser ifNotNil: [ :mruser | mruser at: #id ] ] ].
1✔
361
        aGLPHEMergeRequest merge_user: (self importUser: authorID)
1✔
362
]
1✔
363

364
{ #category : #'private - api' }
365
GLPHModelImporter >> importProject: aProjectID [
1✔
366

1✔
367
        | result projectResult |
1✔
368
        ('Import project with id:  ' , aProjectID printString) recordInfo.
1✔
369

1✔
370
        result := self repoApi project: aProjectID.
1✔
371
        projectResult := self parseProjectResult: result.
1✔
372

1✔
373
        ^ self completeImportProject: projectResult
1✔
374
]
1✔
375

376
{ #category : #'private - api' }
377
GLPHModelImporter >> importRepository: aGLHRepository [
1✔
378

1✔
379
        super importRepository: aGLHRepository.
1✔
380

1✔
381
        withInitialCommits ifTrue: [
1✔
382
                aGLHRepository branches do: [ :branch |
1✔
383
                        self importCommitsOfBranch: branch ] ]
1✔
384
]
1✔
385

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

1✔
389
        super initReader.
1✔
390
        self configureReaderForMergeRequest: generalReader
1✔
391
]
1✔
392

393
{ #category : #initialization }
394
GLPHModelImporter >> initialize [
1✔
395

1✔
396
        super initialize.
1✔
397
        withCommitDiffs := true
1✔
398
]
1✔
399

400
{ #category : #parsing }
401
GLPHModelImporter >> parseMergeRequestResult: result [
1✔
402

1✔
403
        generalReader on: result readStream.
1✔
404
        ^ generalReader nextAs: #ArrayOfMergeRequest
1✔
405
]
1✔
406

407
{ #category : #parsing }
408
GLPHModelImporter >> parseProjectResult: aResult [ 
1✔
409
                | reader |
1✔
410
        reader := NeoJSONReader on: aResult readStream.
1✔
411
        reader for: GLHProject do: [ :mapping |
1✔
412
                mapping mapInstVars. ].
1✔
413
"        reader mapInstVarsFor: GLHProject."
1✔
414

1✔
415
        ^ reader nextAs: GLHProject
1✔
416
]
1✔
417

1✔
418
{ #category : #accessing }
1✔
419
GLPHModelImporter >> withCommitsSince: someDays [
1✔
420
        "substract the current date with a given number of days. Use to retrieve the commits submit in the last giving days"
1✔
421

1✔
422
        "(GLPHModelImporter new withCommitsSince: 1 week ) >>> (Date today - 1 week) asDateAndTime"
1✔
423

1✔
424
        "(GLPHModelImporter new withCommitsSince: 30 day ) >>> (Date today - 30 day) asDateAndTime"
1✔
425

1✔
426
        (someDays isKindOf: DateAndTime)
1✔
427
                ifTrue: [ withCommitsSince := someDays ]
1✔
428
                ifFalse: [
1✔
429
                withCommitsSince := (Date today - someDays) asDateAndTime ]
1✔
430
]
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

© 2025 Coveralls, Inc