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

moosetechnology / GitProjectHealth / 11496926157

24 Oct 2024 09:54AM UTC coverage: 58.906% (+0.6%) from 58.319%
11496926157

push

github

web-flow
Merge pull request #93 from moosetechnology/revert-92-develop

Revert "Develop"

810 of 1504 new or added lines in 51 files covered. (53.86%)

31 existing lines in 4 files now uncovered.

8903 of 15114 relevant lines covered (58.91%)

0.59 hits per line

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

93.09
/src/BitBucketHealth-Model-Importer/BitBucketModelImporter.class.st
1
Class {
2
        #name : #BitBucketModelImporter,
3
        #superclass : #GPModelImporter,
4
        #instVars : [
5
                'bitBucketApi',
6
                'withCommitDiffs',
7
                'withInitialCommits',
8
                'userCatalogue'
9
        ],
10
        #category : #'BitBucketHealth-Model-Importer'
11
}
12

13
{ #category : #accessing }
14
BitBucketModelImporter >> bitBucketApi [
1✔
15

1✔
16
        ^ bitBucketApi
1✔
17
]
1✔
18

19
{ #category : #accessing }
20
BitBucketModelImporter >> bitBucketApi: anObject [
1✔
21

1✔
22
        bitBucketApi := anObject
1✔
23
]
1✔
24

25
{ #category : #equality }
26
BitBucketModelImporter >> blockOnIdEquality [
1✔
27

1✔
28
        ^ [ :existing :new | existing id = new id ]
1✔
29
]
1✔
30

31
{ #category : #'private - api' }
32
BitBucketModelImporter >> completeImportProject: aGLHProject [
1✔
33

1✔
34
        aGLHProject repository: GLHRepository new.
1✔
35
        self glhModel add: aGLHProject repository.
1✔
36
        "TODO: import repository"
1✔
37
        ^ aGLHProject
1✔
38
]
1✔
39

40
{ #category : #'private - api' }
41
BitBucketModelImporter >> getContributionFromDiffs: diffs [
1✔
42

1✔
43
        | contribution |
1✔
44
        contribution := {
1✔
45
                                ('additions' -> 0).
1✔
46
                                ('deletions' -> 0) } asDictionary.
1✔
47

1✔
48
        diffs do: [ :diff |
1✔
49
                | hunks segments |
1✔
50
                hunks := diff at: #hunks ifAbsent: Array new.
1✔
51

1✔
52
                hunks do: [ :hunk |
1✔
53
                        | addedSegment removedSegment |
1✔
54
                        segments := hunk at: #segments.
1✔
55

1✔
56
                        addedSegment := segments
1✔
57
                                                detect: [ :segment |
1✔
58
                                                (segment at: #type) = 'ADDED' ]
1✔
59
                                                ifNone: [ nil ].
1✔
60
                        removedSegment := segments
1✔
61
                                                  detect: [ :segment |
1✔
62
                                                  (segment at: #type) = 'REMOVED' ]
1✔
63
                                                  ifNone: [ nil ].
1✔
64

1✔
65
                        addedSegment ifNotNil: [
1✔
66
                                contribution
1✔
67
                                        at: #additions
1✔
68
                                        put:
1✔
69
                                        (contribution at: #additions) + (addedSegment at: #lines) size ].
1✔
70
                        removedSegment ifNotNil: [
1✔
71
                                contribution
1✔
72
                                        at: #deletions
1✔
73
                                        put:
1✔
74
                                        (contribution at: #deletions) + (removedSegment at: #lines) size ] ] ].
1✔
75

1✔
76
        ^ contribution
1✔
77
]
1✔
78

79
{ #category : #'import - commits' }
80
BitBucketModelImporter >> importCommitsOfProject: aGLHProject since: since until: until [
1✔
81

1✔
82
        | commits |
1✔
83
        commits := bitBucketApi
1✔
84
                           commitsOfRepo: aGLHProject id
1✔
85
                           inProject: aGLHProject group id
1✔
86
                           since: since
1✔
87
                           until: until.
1✔
88

1✔
89
        commits := commits collect: [ :commit |
1✔
90
                           | glhCommit commitDiffs contribution |
1✔
91
                           glhCommit := self parseCommitIntoGLHCommit: commit.
1✔
92
                           commitDiffs := self bitBucketApi
1✔
93
                                                  diffsOfCommit: glhCommit id
1✔
94
                                                  inRepo: aGLHProject id
1✔
95
                                                  inProject: aGLHProject group id.
1✔
96

1✔
97
                           contribution := self getContributionFromDiffs:
1✔
98
                                                   (commitDiffs at: #diffs).
1✔
99
                           glhCommit additions: (contribution at: #additions).
1✔
100
                           glhCommit deletions: (contribution at: #deletions).
1✔
101
                           glhCommit ].
1✔
102

1✔
103
        aGLHProject repository commits: commits.
1✔
104
        self glhModel addAll: commits unless: self blockOnIdEquality.
1✔
105

1✔
106
        ^ commits
1✔
107
]
1✔
108

109
{ #category : #'import - projects' }
110
BitBucketModelImporter >> importContributedProjectsOfUser: aGLHUser [
1✔
111

1✔
112
        | projects repositories repositoriesCommits userRepositories userProjects |
1✔
113
        "get all projects"
1✔
114
        projects := self bitBucketApi projects.
1✔
115

1✔
116
        "get all repos of projects"
1✔
117
        repositories := projects flatCollect: [ :project |
1✔
118
                                self bitBucketApi repositoriesOfProject:
1✔
119
                                        (project at: #key) ].
1✔
120

1✔
121

1✔
122
        "get all commits of repo"
1✔
123
        repositoriesCommits := repositories collect: [ :repository |
1✔
124
                                       repository -> (self bitBucketApi
1✔
125
                                                commitsOfRepo: (repository at: #slug)
1✔
126
                                                inProject:
1✔
127
                                                ((repository at: #project) at: #key)
1✔
128
                                                since: DateAndTime now - 10 days
1✔
129
                                                until: DateAndTime now) ].
1✔
130

1✔
131

1✔
132
        "look if user is author of min one commit"
1✔
133
        userRepositories := repositoriesCommits select: [ :repository |
1✔
134
                                    | repos |
1✔
135
                                    repos := repository value
1✔
136
                                                     ifEmpty: [ false ]
1✔
137
                                                     ifNotEmpty: [
1✔
138
                                                             repository value
1✔
139
                                                                     detect: [ :commit |
1✔
140
                                                                     ((commit at: #author) at: #name)
1✔
141
                                                                     = aGLHUser username ]
1✔
142
                                                                     ifFound: [ true ]
1✔
143
                                                                     ifNone: [ false ] ] ].
1✔
144

1✔
145

1✔
146
        "Transform user repositories in GLHProject"
1✔
147
        userProjects := userRepositories collect: [ :repoCommits |
1✔
148
                                | repo project |
1✔
149
                                repo := repoCommits key.
1✔
150
                                project := repo at: #project.
1✔
151

1✔
152
                                (self glhModel allWithType: GLHProject)
1✔
153
                                        detect: [ :glhProject |
1✔
154
                                        glhProject id = (project at: #key) ]
1✔
155
                                        ifFound: [ :glhProject | glhProject ]
1✔
156
                                        ifNone: [
1✔
157
                                                | glhProject |
1✔
158
                                                glhProject := self parseRepoIntoGLHProject: repo.
1✔
159
                                                glhModel add: glhProject.
1✔
160
                                                glhProject ] ].
1✔
161

1✔
162
        aGLHUser contributedProjects: userProjects.
1✔
163

1✔
164
        ^ userProjects
1✔
165
]
1✔
166

167
{ #category : #'import - commits' }
168
BitBucketModelImporter >> importCreatorOfCommit: aGLHCommit [
1✔
169

1✔
170
        | creator |
1✔
171
        (self glhModel allWithType: GLHUser)
1✔
172
                detect: [ :user | user username = aGLHCommit author_name ]
1✔
173
                ifFound: [ :user |
1✔
174
                        aGLHCommit commitCreator: user.
1✔
175
                        ^ user ].
1✔
176

1✔
177
        creator := self importUserByUsername: aGLHCommit author_name.
1✔
178
        aGLHCommit commitCreator: creator.
1✔
179
        ^ creator
1✔
180
]
1✔
181

182
{ #category : #'import - merge-requests' }
183
BitBucketModelImporter >> importMergeRequestCommits: mergeRequest [
1✔
184

1✔
185
        | commits |
1✔
186
        commits := self bitBucketApi
1✔
187
                           commitsOfPullRequest: mergeRequest id
1✔
188
                           ofRepo: mergeRequest project id
1✔
189
                           inProject: mergeRequest project group id.
1✔
190

1✔
191
        commits := commits collect: [ :commit |
1✔
192
                           self parseCommitIntoGLHCommit: commit ].
1✔
193

1✔
194
        mergeRequest commits: commits.
1✔
195

1✔
196
        ^ commits
1✔
197
]
1✔
198

199
{ #category : #'import - merge-requests' }
200
BitBucketModelImporter >> importMergeRequests: aGLHProject since: fromDate until: toDate [
1✔
201

1✔
202
        | pullRequests |
1✔
203
        pullRequests := bitBucketApi
1✔
204
                                pullRequestsOfRepo: aGLHProject id
1✔
205
                                inProject: aGLHProject group id
1✔
206
                                since: fromDate
1✔
207
                                until: toDate.
1✔
208

1✔
209
        pullRequests := pullRequests collect: [ :pullRequest |
1✔
210
                                self parsePullRequestIntoGLPHEMergeRequest:
1✔
211
                                        pullRequest ].
1✔
212

1✔
213
        self glhModel addAll: pullRequests unless: self blockOnIdEquality.
1✔
214

1✔
215
        ^ pullRequests
1✔
216
]
1✔
217

218
{ #category : #'import - merge-requests' }
219
BitBucketModelImporter >> importMergeResquestAuthor: mergeRequest [
×
220
        mergeRequest author ifNotNil: [ ^mergeRequest ]
×
221
]
×
222

223
{ #category : #'import - merge-requests' }
224
BitBucketModelImporter >> importMergeResquestMerger: mergeRequest [
1✔
225

1✔
226
        | activities mergeActivity mergeUser |
1✔
227
        mergeRequest merge_user ifNotNil: [ ^ mergeRequest merge_user ].
1✔
228
        mergeRequest state = 'merged' ifFalse: [ ^ nil ].
1✔
229

1✔
230
        activities := self bitBucketApi
1✔
231
                              activitiesOfPullRequest: mergeRequest id
1✔
232
                              inRepo: mergeRequest project id
1✔
233
                              ofProject: mergeRequest project group id.
1✔
234

1✔
235
        mergeActivity := activities detect: [ :activity |
1✔
236
                                 (activity at: #action) = 'MERGED' ].
1✔
237

1✔
238
        mergeUser := mergeActivity at: #user.
1✔
239

1✔
240
        mergeUser := (glhModel allWithType: GLHUser)
1✔
241
                             detect: [ :user | user id = (mergeUser at: #id) ]
1✔
242
                             ifFound: [ :user | user ]
1✔
243
                             ifNone: [
1✔
244
                                     | glhUser |
1✔
245
                                     glhUser := self parseUserIntoGLHUser: mergeUser.
1✔
246
                                     glhModel add: glhUser.
1✔
247
                                     glhUser ].
1✔
248

1✔
249
        mergeRequest merge_user: mergeUser.
1✔
250
        ^ mergeUser
1✔
251
]
1✔
252

253
{ #category : #'import - users' }
254
BitBucketModelImporter >> importUserByUsername: username [
1✔
255

1✔
256
        | users user glhUser |
1✔
257
        users := self bitBucketApi usersByUsername: username.
1✔
258
        
1✔
259
        users ifEmpty: [ ^nil ].
1✔
260

1✔
261
        user := users first.
1✔
262

1✔
263
        glhUser := self parseUserIntoGLHUser: user.
1✔
264

1✔
265
        self glhModel add: glhUser unless: [ :nu :ou | nu id = ou id ].
1✔
266
        ^ glhUser
1✔
267
]
1✔
268

269
{ #category : #parsing }
270
BitBucketModelImporter >> parseCommitIntoGLHCommit: commitDictionary [
1✔
271

1✔
272
        | author committer parentIds |
1✔
273
        author := commitDictionary at: #author.
1✔
274
        committer := commitDictionary at: #committer.
1✔
275

1✔
276
        parentIds := (commitDictionary at: #parents) collect: [ :parent |
1✔
277
                             parent at: #id ].
1✔
278

1✔
279
        ^ GLHCommit new
1✔
280
                  id: (commitDictionary at: #id);
1✔
281
                  message: (commitDictionary at: #message);
1✔
282
                  author_email: (author at: #emailAddress);
1✔
283
                  author_name: (author at: #name);
1✔
284
                  authored_date: (DateAndTime fromUnixTime:
1✔
285
                                           (commitDictionary at: #authorTimestamp) / 1000);
1✔
286
                  created_at: (DateAndTime fromUnixTime:
1✔
287
                                           (commitDictionary at: #authorTimestamp) / 1000);
1✔
288
                  committed_date: (DateAndTime fromUnixTime:
1✔
289
                                           (commitDictionary at: #committerTimestamp) / 1000);
1✔
290
                  committer_email: (committer at: #emailAddress);
1✔
291
                  committer_name: (committer at: #name);
1✔
292
                  parent_ids: parentIds
1✔
293
]
1✔
294

295
{ #category : #parsing }
296
BitBucketModelImporter >> parseProjectIntoGLHGroup: projectRepository [
1✔
297

1✔
298
        ^GLHGroup new
1✔
299
                                                     name: (projectRepository at: #name);
1✔
300
                                                     id: (projectRepository at: #key);
1✔
301
                                                     description: (projectRepository at: #description).
1✔
302
]
1✔
303

304
{ #category : #parsing }
305
BitBucketModelImporter >> parsePullRequestIntoGLPHEMergeRequest: pullRequestDictionary [
1✔
306

1✔
307
        | repository project toRef fromRef glpheMergeRequest author state reviewers |
1✔
308
        toRef := pullRequestDictionary at: #toRef.
1✔
309
        fromRef := pullRequestDictionary at: #fromRef.
1✔
310
        
1✔
311
        reviewers := pullRequestDictionary at: #reviewers.
1✔
312
        reviewers := reviewers collect: [ :reviewer | 
1✔
313
                |reviewerUser|
1✔
314
                reviewerUser := reviewer at: #user.
1✔
315
                (self glhModel allWithType: GLHUser) detect: [ :user | user id = (reviewerUser at: #id) ]         ifFound: [ :user | user ] ifNone: [ 
1✔
316
                        |glhUser|
1✔
317
                        glhUser := self parseUserIntoGLHUser: reviewerUser.
1✔
318
                        glhModel  add: glhUser.
1✔
319
                        glhUser.                
1✔
320
                ]
1✔
321
                
1✔
322
        ].
1✔
323

1✔
324
        repository := toRef at: #repository.
1✔
325
        project := (self glhModel allWithType: GLHProject)
1✔
326
                           detect: [ :glhProject |
1✔
327
                           glhProject id = (repository at: #id) ]
1✔
328
                           ifFound: [ :glhProject | glhProject ]
1✔
329
                           ifNone: [
1✔
330
                                   project := self parseRepoIntoGLHProject: repository.
1✔
331
                                   self glhModel add: project.
1✔
332
                                   project ].
1✔
333

1✔
334

1✔
335
        author := pullRequestDictionary at: #author.
1✔
336
        author := (self glhModel allWithType: GLHUser)
1✔
337
                          detect: [ :user | user id = ((author at: #user) at: #id) ]
1✔
338
                          ifFound: [ :user | user ]
1✔
339
                          ifNone: [
1✔
340
                          self importUserByUsername:
1✔
341
                                  ((author at: #user) at: #displayName) ].
1✔
342

1✔
343

1✔
344
        glpheMergeRequest := GLPHEMergeRequest new
1✔
345
                                     name: (pullRequestDictionary at: #title);
1✔
346
                                     title: (pullRequestDictionary at: #title);
1✔
347
                                     id: (pullRequestDictionary at: #id);
1✔
348
                                     project: project;
1✔
349
                                     project_id: project id;
1✔
350
                                     target_branch: (toRef at: #id);
1✔
351
                                     target_project_id:
1✔
352
                                             ((toRef at: #repository) at: #id);
1✔
353
                                     source_branch: (fromRef at: #id);
1✔
354
                                     target_project_id:
1✔
355
                                             ((fromRef at: #repository) at: #id);
1✔
356
                                     updated_at: (DateAndTime fromUnixTime:
1✔
357
                                                              (pullRequestDictionary at: #updatedDate)
1✔
358
                                                              / 1000);
1✔
359
                                     created_at: (DateAndTime fromUnixTime:
1✔
360
                                                              (pullRequestDictionary at: #createdDate)
1✔
361
                                                              / 1000);
1✔
362
                                     author: author.
1✔
363

1✔
364
        "STATE"
1✔
365
        state := pullRequestDictionary at: #state.
1✔
366
        state = 'OPEN' ifTrue: [ glpheMergeRequest state: 'opened' ].
1✔
367
        state = 'MERGED' ifTrue: [
1✔
368
                glpheMergeRequest state: 'merged'.
1✔
369
                glpheMergeRequest merged_at: (DateAndTime fromUnixTime:
1✔
370
                                 (pullRequestDictionary at: #closedDate) / 1000) ].
1✔
371

1✔
372
        state = 'DECLINED' ifTrue: [
1✔
373
                glpheMergeRequest state: 'closed'.
1✔
374
                glpheMergeRequest closed_at: (DateAndTime fromUnixTime:
1✔
375
                                 (pullRequestDictionary at: #closedDate) / 1000) ].
1✔
376

1✔
377
        ^ glpheMergeRequest
1✔
378
]
1✔
379

380
{ #category : #parsing }
381
BitBucketModelImporter >> parseRepoIntoGLHProject: repositoryDictionary [
1✔
382

1✔
383
        | project group glhProject |
1✔
384
        project := repositoryDictionary at: #project.
1✔
385

1✔
386
        group := (self glhModel allWithType: GLHGroup)
1✔
387
                         detect: [ :glhGroup | glhGroup id = (project at: #key) ]
1✔
388
                         ifFound: [ :glhGroup | glhGroup ]
1✔
389
                         ifNone: [
1✔
390
                                 | newGroup |
1✔
391
                                 newGroup := self parseProjectIntoGLHGroup: project.
1✔
392
                                 glhModel add: newGroup.
1✔
393
                                 newGroup ].
1✔
394

1✔
395

1✔
396
        glhProject := GLHProject new
1✔
397
                              name: (repositoryDictionary at: #name);
1✔
398
                              id: (repositoryDictionary at: #slug);
1✔
399
                                                  repository: GLHRepository new;
1✔
400
                              group: group.
1✔
401

1✔
402
        group addProject: glhProject.
1✔
403

1✔
404
        ^ glhProject
1✔
405
]
1✔
406

407
{ #category : #parsing }
408
BitBucketModelImporter >> parseUserIntoGLHUser: userDictionnary [
1✔
409

1✔
410
        ^ GLHUser new name: (userDictionnary at: #displayName);
1✔
411
                public_email: (userDictionnary at: #emailAddress);
1✔
412
                id: (userDictionnary at: #id);
1✔
413
                username: (userDictionnary at: #name).
1✔
414
]
1✔
415

416
{ #category : #accessing }
NEW
417
BitBucketModelImporter >> userCatalogue [
×
NEW
418

×
NEW
419
        ^ userCatalogue
×
NEW
420
]
×
421

422
{ #category : #accessing }
NEW
423
BitBucketModelImporter >> userCatalogue: anObject [
×
NEW
424

×
NEW
425
        userCatalogue := anObject
×
NEW
426
]
×
427

428
{ #category : #accessing }
NEW
429
BitBucketModelImporter >> withCommitDiffs [
×
NEW
430

×
NEW
431
        ^ withCommitDiffs
×
NEW
432
]
×
433

434
{ #category : #accessing }
NEW
435
BitBucketModelImporter >> withCommitDiffs: anObject [
×
NEW
436

×
NEW
437
        withCommitDiffs := anObject
×
NEW
438
]
×
439

440
{ #category : #accessing }
441
BitBucketModelImporter >> withInitialCommits [
×
442

×
443
        ^ withInitialCommits
×
444
]
×
445

446
{ #category : #accessing }
447
BitBucketModelImporter >> withInitialCommits: anObject [
×
448

×
449
        withInitialCommits := anObject
×
450
]
×
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