• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In
Build has been canceled!

moosetechnology / GitProjectHealth / 11496852352

24 Oct 2024 09:49AM UTC coverage: 58.319% (-0.6%) from 58.906%
11496852352

Pull #92

github

web-flow
Merge pull request #91 from moosetechnology/feature-merge-metamodel

Merge Extended and default metamodel
Pull Request #92: Develop

1334 of 2585 new or added lines in 64 files covered. (51.61%)

21 existing lines in 6 files now uncovered.

9446 of 16197 relevant lines covered (58.32%)

0.58 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
        #package : 'GitLabProjectHealth-Model-Importer'
6
}
7

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

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

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

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

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

1✔
59
        ^ completedProject
1✔
60
]
1✔
61

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

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

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

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

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

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

×
123
        self chainsCommitsFrom: commits.
×
124

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

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

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

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

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

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

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

1✔
158

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

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

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

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

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

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

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

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

×
192

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

×
196

×
197
        ^ commits
×
198
]
×
199

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

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

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

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

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

1✔
228

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

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

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

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

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

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

1✔
251

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

1✔
256

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

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

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

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

×
289

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

×
295

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

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

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

×
306
        ^ foundMR
×
307
]
×
308

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

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

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

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

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

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

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

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

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

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

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

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

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

1✔
380
        super importRepository: aGLHRepository.
1✔
381

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

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

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

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

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

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

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

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

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

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

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

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

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