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

moosetechnology / GitProjectHealth / 17204645772

25 Aug 2025 09:17AM UTC coverage: 73.156% (-0.07%) from 73.223%
17204645772

Pull #222

github

web-flow
Merge e1193dcc0 into 28e7c6e1e
Pull Request #222: `importBranchesOf:` is required when performing the full metric analysis

0 of 23 new or added lines in 1 file covered. (0.0%)

33 existing lines in 2 files now uncovered.

18461 of 25235 relevant lines covered (73.16%)

0.73 hits per line

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

77.78
/src/BitBucketHealth-Model-Importer/BitBucketModelImporter.class.st
1
Class {
2
        #name : #BitBucketModelImporter,
3
        #superclass : #GitModelImporter,
4
        #instVars : [
5
                'withInitialCommits'
6
        ],
7
        #category : #'BitBucketHealth-Model-Importer'
8
}
9

10
{ #category : #accessing }
11
BitBucketModelImporter >> bitBucketApi [
×
12

×
13
        self
×
14
                deprecated: 'Use #repoApi instead'
×
15
                on: '7 October 2024'
×
16
                in:
×
17
                'Pharo-11.0.0+build.726.sha.aece1b5473acf3830a0e082c1bc3a15d4ff3522b (64 Bit)'.
×
18

×
19
        ^ repoApi
×
20
]
×
21

22
{ #category : #accessing }
23
BitBucketModelImporter >> bitBucketApi: anObject [
×
24

×
25
        self
×
26
                deprecated: 'Use #repoApi: instead'
×
27
                on: '7 October 2024'
×
28
                in:
×
29
                'Pharo-11.0.0+build.726.sha.aece1b5473acf3830a0e082c1bc3a15d4ff3522b (64 Bit)'.
×
30

×
31
        repoApi := anObject
×
32
]
×
33

34
{ #category : #commit }
35
BitBucketModelImporter >> completeImportedCommit: aCommit [ 
1✔
36
        
1✔
37
        ('completing commit: ' , aCommit short_id printString) recordInfo.
1✔
38
        self importCreatorOfCommit: aCommit.
1✔
39

1✔
40
        self withCommitDiffs ifTrue: [
1✔
41
                | diffs |
1✔
42
                aCommit diffs ifEmpty: [
1✔
43
                        diffs := self importDiffOfCommit: aCommit.
1✔
44
                        self glhModel addAll: diffs unless: self blockForDiffEquality ] ].
1✔
45

1✔
46
        ^ aCommit
1✔
47
]
1✔
48

49
{ #category : #'import - projects' }
50
BitBucketModelImporter >> completeImportedProject: aGLHProject [
1✔
51

1✔
52
        aGLHProject repository: GLHRepository new.
1✔
53
        self glhModel add: aGLHProject repository.
1✔
54
        "TODO: import repository"
1✔
55
        ^ aGLHProject
1✔
56
]
1✔
57

58
{ #category : #'private - api' }
59
BitBucketModelImporter >> convertBitBucketDiffToGitDiff: response [
1✔
60

1✔
61
        | fromHash toHash sourceLine sourceSpan destinationLine destinationSpan result filePathSource filePathDestination |
1✔
62
        fromHash := (response at: 'fromHash') ifNil: ''.
1✔
63
        toHash := (response at: 'toHash') ifNil: ''.
1✔
64

1✔
65

1✔
66
        "Iterate over each diff in 'diffs'"
1✔
67
        result := (response at: #diffs) collect: [ :diff | "Extract file path, hashes"
1✔
68
                          | gitDiff hunks|
1✔
69
                          gitDiff := ''.
1✔
70
                          filePathSource := (diff at: 'source')
1✔
71
                                                    ifNil: ''
1✔
72
                                                    ifNotNil: [ :source |
1✔
73
                                                    source at: 'toString' ].
1✔
74
                          filePathDestination := (diff at: 'destination')
1✔
75
                                                         ifNil: ''
1✔
76
                                                         ifNotNil: [ :destination |
1✔
77
                                                         destination at: 'toString' ].
1✔
78

1✔
79
                          "Build the diff header"
1✔
80
                          " gitDiff := gitDiff , 'diff --git a/', filePath, ' b/', filePath, String cr."
1✔
81
                          " gitDiff := gitDiff , 'index ', fromHash, '..', toHash, ' 100644', String cr."
1✔
82
                          gitDiff := gitDiff , '--- a/' , filePathSource , String cr.
1✔
83
                          gitDiff := gitDiff , '+++ b/' , filePathDestination
1✔
84
                                     , String cr.
1✔
85

1✔
86
                          "Iterate over hunks"
1✔
87
                                         hunks := diff at: #hunks ifPresent: [ :value | value ]  ifAbsent: [ { } ]. 
1✔
88
                          hunks do: [ :hunk |
1✔
89
                                  sourceLine := hunk at: 'sourceLine'.
1✔
90
                                  sourceSpan := hunk at: 'sourceSpan'.
1✔
91
                                  destinationLine := hunk at: 'destinationLine'.
1✔
92
                                  destinationSpan := hunk at: 'destinationSpan'.
1✔
93

1✔
94
                                  "Hunk header"
1✔
95
                                  gitDiff := gitDiff
1✔
96
                                             , ('@@ -{1},{2} +{3},{4} @@' format: {
1✔
97
                                                                      sourceLine.
1✔
98
                                                                      sourceSpan.
1✔
99
                                                                      destinationLine.
1✔
100
                                                                      destinationSpan }) , String cr.
1✔
101

1✔
102
                                  "Iterate over segments"
1✔
103
                                  (hunk at: 'segments') do: [ :segment |
1✔
104
                                          (segment at: 'lines') do: [ :line |
1✔
105
                                                  (segment at: 'type') = 'CONTEXT' ifTrue: [
1✔
106
                                                          gitDiff := gitDiff , (line at: 'line') , String cr ].
1✔
107
                                                  (segment at: 'type') = 'REMOVED' ifTrue: [
1✔
108
                                                          gitDiff := gitDiff , '-' , (line at: 'line')
1✔
109
                                                                     , String cr ].
1✔
110
                                                  (segment at: 'type') = 'ADDED' ifTrue: [
1✔
111
                                                          gitDiff := gitDiff , '+' , (line at: 'line')
1✔
112
                                                                     , String cr ] ] ] ].
1✔
113
                          GLHDiff new
1✔
114
                                  diffString: gitDiff;
1✔
115
                                  old_path: filePathSource;
1✔
116
                                  new_path: filePathDestination ].
1✔
117

1✔
118
        ^ result
1✔
119
]
1✔
120

121
{ #category : #'as yet unclassified' }
122
BitBucketModelImporter >> extractNoteFromComment: aDictionary [
×
123

×
124
        ^ GLHNote new
×
125
                  created_at:
×
126
                          (DateAndTime fromUnixTime: (aDictionary at: #createdDate) / 1000);
×
127
                  id: (aDictionary at: #id);
×
128
                  author: (aDictionary at: #user);
×
129
                  body: (aDictionary at: #comment at: #text);
×
130
                  yourself
×
131
]
×
132

133
{ #category : #'private - api' }
134
BitBucketModelImporter >> getContributionFromDiffs: diffs [
1✔
135

1✔
136
        | contribution |
1✔
137
        contribution := {
1✔
138
                                ('additions' -> 0).
1✔
139
                                ('deletions' -> 0) } asDictionary.
1✔
140

1✔
141
        diffs do: [ :diff |
1✔
142
                | hunks segments |
1✔
143
                hunks := diff at: #hunks ifAbsent: Array new.
1✔
144

1✔
145
                hunks do: [ :hunk |
1✔
146
                        | addedSegment removedSegment |
1✔
147
                        segments := hunk at: #segments.
1✔
148

1✔
149
                        addedSegment := segments
1✔
150
                                                detect: [ :segment |
1✔
151
                                                (segment at: #type) = 'ADDED' ]
1✔
152
                                                ifNone: [ nil ].
1✔
153
                        removedSegment := segments
1✔
154
                                                  detect: [ :segment |
1✔
155
                                                  (segment at: #type) = 'REMOVED' ]
1✔
156
                                                  ifNone: [ nil ].
1✔
157

1✔
158
                        addedSegment ifNotNil: [
1✔
159
                                contribution
1✔
160
                                        at: #additions
1✔
161
                                        put:
1✔
162
                                        (contribution at: #additions) + (addedSegment at: #lines) size ].
1✔
163
                        removedSegment ifNotNil: [
1✔
164
                                contribution
1✔
165
                                        at: #deletions
1✔
166
                                        put:
1✔
167
                                        (contribution at: #deletions) + (removedSegment at: #lines) size ] ] ].
1✔
168

1✔
169
        ^ contribution
1✔
170
]
1✔
171

172
{ #category : #'import - commits' }
173
BitBucketModelImporter >> importAndLoadLatestsCommitsOfProject: aGLHProject [
1✔
174

1✔
175
        | commits |
1✔
176
        self completeImportedProject: aGLHProject.
1✔
177

1✔
178
        commits := self
1✔
179
                           importCommitsOfProject: aGLHProject
1✔
180
                           since: (Date today - 3 week) asDateAndTime
1✔
181
                           until: Date today asDateAndTime.
1✔
182
        commits do: [ :commit | self completeImportedCommit: commit ].
1✔
183
        
1✔
184
        self chainsCommitsFrom: commits.
1✔
185
        
1✔
186
        ^ commits
1✔
187
]
1✔
188

189
{ #category : #'import - repositories' }
NEW
190
BitBucketModelImporter >> importBranchesOf: aGLHProject [
×
NEW
191

×
NEW
192
        | branches glhBranches |
×
NEW
193
        branches := self repoApi branches
×
NEW
194
                            allWithParams: {  } asDictionary
×
NEW
195
                            inRepository: aGLHProject id
×
NEW
196
                            ofProject: aGLHProject group id.
×
NEW
197
        glhBranches := branches collect: [ :branch | self parseBranchIntoGLHBranch: branch ].
×
NEW
198

×
NEW
199
        glhBranches do: [ :glhBranch | aGLHProject repository addBranch: glhBranch ].
×
NEW
200

×
NEW
201
        self glhModel
×
NEW
202
                            addAll: glhBranches
×
NEW
203
                            unless: self blockForBranchEquality.
×
NEW
204

×
NEW
205
        ^ glhBranches
×
NEW
206
]
×
207

208
{ #category : #'import - commits' }
209
BitBucketModelImporter >> importCommit: aCommitID ofProject: aGLHProject [
×
210

×
211
        | result parsedResult |
×
212
        (self glhModel allWithType: GLHCommit) asOrderedCollection
×
213
                detect: [ :commit | commit id = aCommitID ]
×
214
                ifFound: [ :commit | ^ commit ].
×
215
        result := self repoApi commits
×
216
                          get: aCommitID
×
217
                          inRepository: aGLHProject id
×
218
                          ofProject: aGLHProject group id.
×
219
        parsedResult := self
×
220
                                parseCommitIntoGLHCommit: result
×
221
                                ofProject: aGLHProject.
×
222

×
223
        parsedResult := self glhModel addAll: { parsedResult } unless: self blockOnIdEquality.
×
224
        ^ parsedResult
×
225
]
×
226

227
{ #category : #'import - commits' }
228
BitBucketModelImporter >> importCommitsOfProject: aGLHProject since: since until: until [
1✔
229

1✔
230
        | commits |
1✔
231
        commits := self repoApi commits
1✔
232
                           allSince: since
1✔
233
                           until: until
1✔
234
                           inRepository: aGLHProject id
1✔
235
                           ofProject: aGLHProject group id.
1✔
236
                
1✔
237
        commits := commits collect: [ :commit |
1✔
238
                           self
1✔
239
                                   parseCommitIntoGLHCommit: commit
1✔
240
                                   ofProject: aGLHProject ].
1✔
241

1✔
242

1✔
243
        commits := self glhModel
1✔
244
                           addAll: commits
1✔
245
                           unless: self blockOnIdEquality.
1✔
246
        ^ aGLHProject repository commits
1✔
247
                  addAll: commits
1✔
248
                  unless: self blockOnIdEquality
1✔
249
]
1✔
250

251
{ #category : #'import - projects' }
252
BitBucketModelImporter >> importContributedProjectsOfUser: aGLHUser [
1✔
253

1✔
254
        | projects repositories repositoriesCommits userRepositories userProjects |
1✔
255
        "get all projects"
1✔
256
        projects := self repoApi projects all.
1✔
257

1✔
258
        "get all repos of projects"
1✔
259
        repositories := projects flatCollect: [ :project |
1✔
260
                                self repoApi repositories allInProject:
1✔
261
                                        (project at: #key) ].
1✔
262

1✔
263

1✔
264
        "get all commits of repo"
1✔
265
        repositoriesCommits := repositories collect: [ :repository |
1✔
266
                                       repository -> (self repoApi commits allSince: DateAndTime now - 10 days until: DateAndTime now inRepository: (repository at: #slug) ofProject:  ((repository at: #project) at: #key))
1✔
267
                                                 ].
1✔
268

1✔
269

1✔
270
        "look if user is author of min one commit"
1✔
271
        userRepositories := repositoriesCommits select: [ :repository |
1✔
272
                                    | repos |
1✔
273
                                    repos := repository value
1✔
274
                                                     ifEmpty: [ false ]
1✔
275
                                                     ifNotEmpty: [
1✔
276
                                                             repository value
1✔
277
                                                                     detect: [ :commit |
1✔
278
                                                                     ((commit at: #author) at: #name)
1✔
279
                                                                     = aGLHUser username ]
1✔
280
                                                                     ifFound: [ true ]
1✔
281
                                                                     ifNone: [ false ] ] ].
1✔
282

1✔
283

1✔
284
        "Transform user repositories in GLHProject"
1✔
285
        userProjects := userRepositories collect: [ :repoCommits |
1✔
286
                                | repo project |
1✔
287
                                repo := repoCommits key.
1✔
288
                                project := repo at: #project.
1✔
289

1✔
290
                                (self glhModel allWithType: GLHProject)
1✔
291
                                        detect: [ :glhProject |
1✔
292
                                        glhProject id = (project at: #key) ]
1✔
293
                                        ifFound: [ :glhProject | glhProject ]
1✔
294
                                        ifNone: [
1✔
295
                                                | glhProject |
1✔
296
                                                glhProject := self parseRepoIntoGLHProject: repo.
1✔
297
                                                glhModel add: glhProject.
1✔
298
                                                glhProject ] ].
1✔
299

1✔
300
        aGLHUser contributedProjects: userProjects.
1✔
301

1✔
302
        ^ userProjects
1✔
303
]
1✔
304

305
{ #category : #'import - commits' }
306
BitBucketModelImporter >> importCreatorOfCommit: aGLHCommit [
1✔
307

1✔
308
        | creator |
1✔
309
        (self glhModel allWithType: GLHUser)
1✔
310
                detect: [ :user | user username = aGLHCommit author_name ]
1✔
311
                ifFound: [ :user |
1✔
312
                        aGLHCommit commitCreator: user.
1✔
313
                        ^ user ].
1✔
314

1✔
315
        creator := self importUserByUsername: aGLHCommit author_name.
1✔
316
        aGLHCommit commitCreator: creator.
1✔
317
        ^ creator
1✔
318
]
1✔
319

320
{ #category : #'import - commits' }
321
BitBucketModelImporter >> importDiffOfCommit: aCommit [
1✔
322

1✔
323
        | result diffsResult |
1✔
324
        aCommit diffs ifNotEmpty: [
1✔
325
                'Diff already importer: ' , aCommit short_id printString recordInfo.
1✔
326
                ^ aCommit diffs ].
1✔
327
        ('Import diff of commit: ' , aCommit short_id printString) recordInfo.
1✔
328
        result := self repoApi commits diffOf: aCommit id inRepository: aCommit repository project id  ofProject: aCommit repository project group id.
1✔
329

1✔
330
        diffsResult := self convertBitBucketDiffToGitDiff: result.
1✔
331

1✔
332

1✔
333
        diffsResult := aCommit diffs
1✔
334
                               addAll: diffsResult
1✔
335
                               unless: self blockForDiffEquality.
1✔
336

1✔
337
        "changes are added into the model during the import"
1✔
338
        diffsResult do: [ :diff | self importDiffRangesForDiff: diff ].
1✔
339

1✔
340
        ^ diffsResult
1✔
341
]
1✔
342

343
{ #category : #'import - groups' }
344
BitBucketModelImporter >> importGroup: aGroupID [
1✔
345

1✔
346
        | result projectResult |
1✔
347
        ('Import group with id:  ' , aGroupID printString) recordInfo.
1✔
348

1✔
349
        (glhModel allWithType: GLHGroup)
1✔
350
                detect: [ :group | group id = aGroupID ]
1✔
351
                ifFound: [ :group | ^ group ].
1✔
352
        "group are named projects in bitbucket"
1✔
353
        result := self repoApi projects get: aGroupID.
1✔
354
        projectResult := self parseGroupResult: result.
1✔
355

1✔
356
        ^ self glhModel add: projectResult unless: self blockOnIdEquality
1✔
357
]
1✔
358

359
{ #category : #'import - merge-requests' }
360
BitBucketModelImporter >> importMergeRequestCommits: mergeRequest [
1✔
361

1✔
362
        | commits |
1✔
363
        commits := self repoApi pullRequests
1✔
364
                           commitsOf: mergeRequest id
1✔
365
                           inRepository: mergeRequest project id
1✔
366
                           ofProject: mergeRequest project group id.
1✔
367

1✔
368
        commits := commits collect: [ :commit |
1✔
369
                           self
1✔
370
                                   parseCommitIntoGLHCommit: commit
1✔
371
                                   ofProject: mergeRequest project ].
1✔
372

1✔
373
        mergeRequest commits: commits.
1✔
374

1✔
375
        ^ commits
1✔
376
]
1✔
377

378
{ #category : #'import - merge request' }
UNCOV
379
BitBucketModelImporter >> importMergeRequestMergeCommits: aGLHMergeRequest [
×
UNCOV
380

×
381
        aGLHMergeRequest mergedCommit ifNotNil: [
×
382
                ^ { aGLHMergeRequest mergedCommit } ].
×
383
        aGLHMergeRequest project repository commits
×
384
                detect: [ :c |
×
385
                c parent_ids includes: aGLHMergeRequest commits last id ]
×
386
                ifFound: [ :found |
×
387
                        aGLHMergeRequest mergedCommit: found.
×
388
                        aGLHMergeRequest merge_commit_sha: found id.
×
389
                        self importMergeRequestStats: aGLHMergeRequest.
×
390
                        ^ { found } ].
×
391

×
392
        self
×
393
                importCommitsOfProject: aGLHMergeRequest project
×
394
                since: aGLHMergeRequest created_at
×
395
                until: aGLHMergeRequest merged_at.
×
396
        self chainsCommitsFrom: aGLHMergeRequest project repository commits.
×
397
        aGLHMergeRequest project repository commits
×
398
                detect: [ :c |
×
399
                c parent_ids includes: aGLHMergeRequest commits last id ]
×
400
                ifFound: [ :found |
×
401
                        aGLHMergeRequest mergedCommit: found.
×
402
                        aGLHMergeRequest merge_commit_sha: found id.
×
403
                        self importMergeRequestStats: aGLHMergeRequest.
×
404
                        ^ { found } ]
×
405
]
×
406

407
{ #category : #'import - merge request' }
408
BitBucketModelImporter >> importMergeRequestStats: aMergeRequest [
1✔
409

1✔
410
        | commitDiffs contribution |
1✔
411
        "can not recompute diff of mergedcommit if none"
1✔
412
        aMergeRequest mergedCommit ifNil: [ ^ self ].
1✔
413
        (aMergeRequest mergedCommit additions isNotNil and: [
1✔
414
                 aMergeRequest mergedCommit deletions isNotNil and: [
1✔
415
                         aMergeRequest mergedCommit additions ~= 0 or: [
1✔
416
                                 aMergeRequest mergedCommit deletions ~= 0 ] ] ]) ifTrue: [
1✔
417
                ^ self ].
1✔
418

1✔
419
        commitDiffs := self repoApi pullRequests
1✔
420
                               diffOf: aMergeRequest id
1✔
421
                               inRepository: aMergeRequest project id
1✔
422
                               ofProject: aMergeRequest project group id.
1✔
423

1✔
424
        contribution := self getContributionFromDiffs:
1✔
425
                                (commitDiffs at: #diffs).
1✔
426

1✔
427
        ^ aMergeRequest mergedCommit
1✔
428
                  additions: (contribution at: #additions);
1✔
429
                  deletions: (contribution at: #deletions)
1✔
430
]
1✔
431

432
{ #category : #'import - merge-requests' }
433
BitBucketModelImporter >> importMergeRequests: aGLHProject since: fromDate until: toDate [
1✔
434

1✔
435
        | pullRequests params |
1✔
436
        params := { 
1✔
437
                #state -> 'all'
1✔
438
         } asDictionary.
1✔
439
        pullRequests := self repoApi pullRequests allSince: fromDate until: toDate withParams: params  inRepository: aGLHProject id ofProject: aGLHProject group id.
1✔
440

1✔
441
        pullRequests := pullRequests collect: [ :pullRequest |
1✔
442
                                self parsePullRequestIntoGLPHEMergeRequest:
1✔
443
                                        pullRequest ].
1✔
444

1✔
445
        pullRequests := self glhModel
1✔
446
                                addAll: pullRequests
1✔
447
                                unless: self blockOnIdEquality.
1✔
448

1✔
449
        ^ pullRequests
1✔
450
]
1✔
451

452
{ #category : #'import - merge-requests' }
UNCOV
453
BitBucketModelImporter >> importMergeResquestAuthor: mergeRequest [
×
UNCOV
454
        mergeRequest author ifNotNil: [ ^mergeRequest ]
×
455
]
×
456

457
{ #category : #'import - merge-requests' }
458
BitBucketModelImporter >> importMergeResquestMerger: mergeRequest [
1✔
459

1✔
460
        | activities mergeActivity mergeUser |
1✔
461
        mergeRequest merge_user ifNotNil: [ ^ mergeRequest merge_user ].
1✔
462
        mergeRequest state = 'merged' ifFalse: [ ^ nil ].
1✔
463

1✔
464
        activities := self repoApi pullRequests activitiesOf: mergeRequest id  inRepository: mergeRequest project id  ofProject: mergeRequest project group id.
1✔
465

1✔
466
        mergeActivity := activities detect: [ :activity |
1✔
467
                                 (activity at: #action) = 'MERGED' ].
1✔
468

1✔
469
        mergeUser := mergeActivity at: #user.
1✔
470

1✔
471
        mergeUser := (glhModel allWithType: GLHUser)
1✔
472
                             detect: [ :user | user id = (mergeUser at: #id) ]
1✔
473
                             ifFound: [ :user | user ]
1✔
474
                             ifNone: [
1✔
475
                                     | glhUser |
1✔
476
                                     glhUser := self parseUserIntoGLHUser: mergeUser.
1✔
477
                                     glhModel add: glhUser.
1✔
478
                                     glhUser ].
1✔
479

1✔
480
        mergeRequest merge_user: mergeUser.
1✔
481
        ^ mergeUser
1✔
482
]
1✔
483

484
{ #category : #'import - notes' }
UNCOV
485
BitBucketModelImporter >> importNotesfromMergeRequest: mergeRequest [
×
UNCOV
486

×
487
        | results notes |
×
488
        results := self repoApi pullRequests
×
489
                           activitiesOf: mergeRequest id
×
490
                           inRepository: mergeRequest project id
×
491
                           ofProject: mergeRequest project group id.
×
492
        notes := results
×
493
                         select: [ :activity | (activity at: #action) = 'COMMENTED' ]
×
494
                         thenCollect: [ :commentActivity |
×
495
                         self extractNoteFromComment: commentActivity ].
×
496
        "notes := self parseNoteJson: results."
×
497
        notes do: [ :note |
×
498
                note author:
×
499
                        (self importUserByUsername: (note author at: #displayName)).
×
500
                note name: note id asString ].
×
501
        notes := notes flattened.
×
502
        notes := self glhModel addAll: notes unless: self blockOnIdEquality.
×
503
        notes := mergeRequest note
×
504
                         addAll: notes
×
505
                         unless: self blockOnIdEquality.
×
506
        ^ notes
×
507
]
×
508

509
{ #category : #'import - projects' }
UNCOV
510
BitBucketModelImporter >> importProject: aProjectID [
×
UNCOV
511

×
512
        Error signal:
×
513
                'Bitbucket api cannot import directly a project (in the sens of GPH). One need to import a group, then the projects of this group.'
×
514
]
×
515

516
{ #category : #'import - projects' }
UNCOV
517
BitBucketModelImporter >> importProject: aProjectID ofGroup: aGroup [
×
UNCOV
518

×
519
        | repoOfProject project |
×
520
        repoOfProject := self repoApi repositories
×
521
                                 get: aProjectID
×
522
                                 ofProject: aGroup id.
×
523
        project := self parseRepoIntoGLHProject: repoOfProject.
×
524
        self glhModel add: project.
×
525
        ^ project
×
526
]
×
527

528
{ #category : #'import - users' }
529
BitBucketModelImporter >> importUserByUsername: username [
1✔
530

1✔
531
        ^ self userCatalogue collectUsernames at: username ifAbsent: [
1✔
532
                  | users glhUser user params|
1✔
533
                  params := { #filter -> username } asDictionary. 
1✔
534
                  users := self repoApi users allWithParams: params.
1✔
535
                  users ifEmpty: [ ^ nil ].
1✔
536
                  user := users first.
1✔
537

1✔
538
                  glhUser := self parseUserIntoGLHUser: user.
1✔
539
                  self glhModel add: glhUser unless: self blockOnIdEquality.
1✔
540
                  self userCatalogue addUser: glhUser withName: username.
1✔
541
                  glhUser ]
1✔
542
]
1✔
543

544
{ #category : #parsing }
NEW
UNCOV
545
BitBucketModelImporter >> parseBranchIntoGLHBranch: branchDictionary [ 
×
NEW
546
        ^ GLHBranch new
×
NEW
547
                name: (branchDictionary at: 'displayId');
×
NEW
548
                yourself
×
NEW
549
                
×
NEW
550
]
×
551

552
{ #category : #parsing }
553
BitBucketModelImporter >> parseCommitIntoGLHCommit: commitDictionary ofProject: aGLHProject [
1✔
554

1✔
555
        | author committer parentIds commitDiffs contribution |
1✔
556
        author := commitDictionary at: #author.
1✔
557
        committer := commitDictionary at: #committer.
1✔
558

1✔
559
        parentIds := (commitDictionary at: #parents) collect: [ :parent |
1✔
560
                             parent at: #id ].
1✔
561

1✔
562
        commitDiffs := self repoApi commits
1✔
563
                               diffOf: (commitDictionary at: #id)
1✔
564
                               inRepository: aGLHProject id
1✔
565
                               ofProject: aGLHProject group id.
1✔
566

1✔
567
        contribution := self getContributionFromDiffs:
1✔
568
                                (commitDiffs at: #diffs).
1✔
569

1✔
570
        ^ GLHCommit new
1✔
571
                  id: (commitDictionary at: #id);
1✔
572
                  message: (commitDictionary at: #message);
1✔
573
                  title: (commitDictionary at: #message) lines first;
1✔
574
                  author_email: (author at: #emailAddress);
1✔
575
                  author_name: (author at: #name);
1✔
576
                  authored_date: (DateAndTime fromUnixTime:
1✔
577
                                           (commitDictionary at: #authorTimestamp) / 1000);
1✔
578
                  created_at: (DateAndTime fromUnixTime:
1✔
579
                                           (commitDictionary at: #authorTimestamp) / 1000);
1✔
580
                  committed_date: (DateAndTime fromUnixTime:
1✔
581
                                           (commitDictionary at: #committerTimestamp) / 1000);
1✔
582
                  committer_email: (committer at: #emailAddress);
1✔
583
                  committer_name: (committer at: #name);
1✔
584
                  parent_ids: parentIds;
1✔
585
                  additions: (contribution at: #additions);
1✔
586
                  deletions: (contribution at: #deletions)
1✔
587
]
1✔
588

589
{ #category : #parsing }
590
BitBucketModelImporter >> parseGroupResult: aDictionary [
1✔
591

1✔
592
        ^ GLHGroup new
1✔
593
                  id: (aDictionary at: #key);
1✔
594
                  "use key instead of id because key is use everywhere else for API"
1✔
595
                  description: (aDictionary at: #description);
1✔
596
                  name: (aDictionary at: #name);
1✔
597
                  web_url: ((aDictionary at: #links at: #self) anyOne at: #href);
1✔
598
                  yourself
1✔
599
]
1✔
600

601
{ #category : #parsing }
602
BitBucketModelImporter >> parseProjectIntoGLHGroup: projectRepository [
1✔
603

1✔
604
        ^ GLHGroup new
1✔
605
                  name: (projectRepository at: #name);
1✔
606
                  id: (projectRepository at: #key);
1✔
607
                  description: (projectRepository at: #description)
1✔
608
]
1✔
609

610
{ #category : #parsing }
611
BitBucketModelImporter >> parsePullRequestIntoGLPHEMergeRequest: pullRequestDictionary [
1✔
612

1✔
613
        | repository project toRef fromRef glpheMergeRequest author state reviewers |
1✔
614
        toRef := pullRequestDictionary at: #toRef.
1✔
615
        fromRef := pullRequestDictionary at: #fromRef.
1✔
616

1✔
617
        reviewers := pullRequestDictionary at: #reviewers.
1✔
618
        reviewers := reviewers collect: [ :reviewer |
1✔
619
                             | reviewerUser |
1✔
620
                             reviewerUser := reviewer at: #user.
1✔
621
                             (self glhModel allWithType: GLHUser)
1✔
622
                                     detect: [ :user | user id = (reviewerUser at: #id) ]
1✔
623
                                     ifFound: [ :user | user ]
1✔
624
                                     ifNone: [
1✔
625
                                             | glhUser |
1✔
626
                                             glhUser := self parseUserIntoGLHUser: reviewerUser.
1✔
627
                                             glhModel add: glhUser.
1✔
628
                                             glhUser ] ].
1✔
629

1✔
630
        repository := toRef at: #repository.
1✔
631
        project := (self glhModel allWithType: GLHProject)
1✔
632
                           detect: [ :glhProject |
1✔
633
                           glhProject id = (repository at: #slug) ]
1✔
634
                           ifFound: [ :glhProject | glhProject ]
1✔
635
                           ifNone: [
1✔
636
                                   project := self parseRepoIntoGLHProject: repository.
1✔
637
                                   self glhModel add: project.
1✔
638
                                   project ].
1✔
639

1✔
640

1✔
641
        author := pullRequestDictionary at: #author.
1✔
642
        author := (self glhModel allWithType: GLHUser)
1✔
643
                          detect: [ :user | user id = ((author at: #user) at: #id) ]
1✔
644
                          ifFound: [ :user | user ]
1✔
645
                          ifNone: [
1✔
646
                          self importUserByUsername:
1✔
647
                                  ((author at: #user) at: #displayName) ].
1✔
648

1✔
649

1✔
650
        glpheMergeRequest := GLHMergeRequest new
1✔
651
                                     name: (pullRequestDictionary at: #title);
1✔
652
                                     title: (pullRequestDictionary at: #title);
1✔
653
                                     id: (pullRequestDictionary at: #id);
1✔
654
                                     project: project;
1✔
655
                                     project_id: project id;
1✔
656
                                     target_branch: (toRef at: #id);
1✔
657
                                     target_project_id:
1✔
658
                                             ((toRef at: #repository) at: #id);
1✔
659
                                     source_branch: (fromRef at: #id);
1✔
660
                                     source_project_id:
1✔
661
                                             ((fromRef at: #repository) at: #id);
1✔
662
                                     updated_at: (DateAndTime fromUnixTime:
1✔
663
                                                              (pullRequestDictionary at: #updatedDate)
1✔
664
                                                              / 1000);
1✔
665
                                     created_at: (DateAndTime fromUnixTime:
1✔
666
                                                              (pullRequestDictionary at: #createdDate)
1✔
667
                                                              / 1000);
1✔
668
                                     author: author.
1✔
669

1✔
670
        "STATE"
1✔
671
        state := pullRequestDictionary at: #state.
1✔
672
        state = 'OPEN' ifTrue: [ glpheMergeRequest state: 'opened' ].
1✔
673
        state = 'MERGED' ifTrue: [
1✔
674
                glpheMergeRequest state: 'merged'.
1✔
675
                glpheMergeRequest merged_at: (DateAndTime fromUnixTime:
1✔
676
                                 (pullRequestDictionary at: #closedDate) / 1000) ].
1✔
677

1✔
678
        state = 'DECLINED' ifTrue: [
1✔
679
                glpheMergeRequest state: 'closed'.
1✔
680
                glpheMergeRequest closed_at: (DateAndTime fromUnixTime:
1✔
681
                                 (pullRequestDictionary at: #closedDate) / 1000) ].
1✔
682

1✔
683
        ^ glpheMergeRequest
1✔
684
]
1✔
685

686
{ #category : #parsing }
687
BitBucketModelImporter >> parseRepoIntoGLHProject: repositoryDictionary [
1✔
688

1✔
689
        | project group glhProject |
1✔
690
        project := repositoryDictionary at: #project.
1✔
691

1✔
692
        group := (self glhModel allWithType: GLHGroup)
1✔
693
                         detect: [ :glhGroup | glhGroup id = (project at: #key) ]
1✔
694
                         ifFound: [ :glhGroup | glhGroup ]
1✔
695
                         ifNone: [
1✔
696
                                 | newGroup |
1✔
697
                                 newGroup := self parseProjectIntoGLHGroup: project.
1✔
698
                                 glhModel add: newGroup.
1✔
699
                                 newGroup ].
1✔
700

1✔
701

1✔
702
        glhProject := GLHProject new
1✔
703
                              name: (repositoryDictionary at: #name);
1✔
704
                              id: (repositoryDictionary at: #slug);
1✔
705
                              repository: GLHRepository new;
1✔
706
                              group: group.
1✔
707

1✔
708
        group addProject: glhProject.
1✔
709

1✔
710
        ^ glhProject
1✔
711
]
1✔
712

713
{ #category : #parsing }
714
BitBucketModelImporter >> parseUserIntoGLHUser: userDictionnary [
1✔
715

1✔
716
        ^ GLHUser new
1✔
717
                  name: (userDictionnary at: #displayName);
1✔
718
                  public_email: (userDictionnary at: #emailAddress ifAbsent: [ nil ]);
1✔
719
                  id: (userDictionnary at: #id);
1✔
720
                  username: (userDictionnary at: #name)
1✔
721
]
1✔
722

723
{ #category : #accessing }
UNCOV
724
BitBucketModelImporter >> withInitialCommits [
×
UNCOV
725

×
UNCOV
726
        ^ withInitialCommits
×
UNCOV
727
]
×
728

729
{ #category : #accessing }
UNCOV
730
BitBucketModelImporter >> withInitialCommits: anObject [
×
731

×
732
        withInitialCommits := anObject
×
733
]
×
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