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

moosetechnology / GitProjectHealth / 17940792567

23 Sep 2025 08:54AM UTC coverage: 72.789% (-0.6%) from 73.342%
17940792567

Pull #233

github

web-flow
Merge 47f4a2b17 into dd8ffa1f6
Pull Request #233: V2.0.0 : Refactoring importers

408 of 676 new or added lines in 18 files covered. (60.36%)

57 existing lines in 6 files now uncovered.

18768 of 25784 relevant lines covered (72.79%)

0.73 hits per line

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

79.52
/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 : #'import - commits' }
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 : #'import - notes' }
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 - branches' }
190
BitBucketModelImporter >> importBranchesOf: aGLHProject [
×
191

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

×
202
        glhBranches do: [ :glhBranch |
×
203
                aGLHProject repository addBranch: glhBranch ].
×
204

×
205
        self glhModel addAll: glhBranches unless: self blockForBranchEquality.
×
206

×
207
        ^ glhBranches
×
208
]
×
209

210
{ #category : #'import - commits' }
211
BitBucketModelImporter >> importCommit: aCommitID ofProject: aGLHProject [
1✔
212

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

1✔
225
        parsedResult := self glhModel addAll: { parsedResult } unless: self blockOnIdEquality.
1✔
226
        ^ parsedResult anyOne
1✔
227
]
1✔
228

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

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

1✔
244

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

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

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

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

1✔
265

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

1✔
271

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

1✔
285

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

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

1✔
302
        aGLHUser contributedProjects: userProjects.
1✔
303

1✔
304
        ^ userProjects
1✔
305
]
1✔
306

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

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

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

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

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

1✔
332
        diffsResult := self convertBitBucketDiffToGitDiff: result.
1✔
333

1✔
334

1✔
335
        diffsResult := aCommit diffs
1✔
336
                               addAll: diffsResult
1✔
337
                               unless: self blockForDiffEquality.
1✔
338

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

1✔
342
        ^ diffsResult
1✔
343
]
1✔
344

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

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

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

1✔
358
        ^ self glhModel add: projectResult unless: self blockOnIdEquality
1✔
359
]
1✔
360

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

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

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

1✔
375
        mergeRequest commits: commits.
1✔
376

1✔
377
        ^ commits
1✔
378
]
1✔
379

380
{ #category : #'import - merge-requests' }
381
BitBucketModelImporter >> importMergeRequestMergeCommits: aGLHMergeRequest [
×
382

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

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

409
{ #category : #'import - merge-requests' }
410
BitBucketModelImporter >> importMergeRequestStats: aMergeRequest [
1✔
411

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

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

1✔
426
        contribution := self getContributionFromDiffs:
1✔
427
                                (commitDiffs at: #diffs).
1✔
428

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

434
{ #category : #'import - merge-requests' }
435
BitBucketModelImporter >> importMergeRequestsOfProject: aGLHProject since: fromDate until: toDate [
1✔
436

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

1✔
443
        pullRequests := pullRequests collect: [ :pullRequest |
1✔
444
                                self parsePullRequestIntoGLPHEMergeRequest:
1✔
445
                                        pullRequest ].
1✔
446

1✔
447
        pullRequests := self glhModel
1✔
448
                                addAll: pullRequests
1✔
449
                                unless: self blockOnIdEquality.
1✔
450

1✔
451
        ^ pullRequests
1✔
452
]
1✔
453

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

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

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

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

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

1✔
471
        mergeUser := mergeActivity at: #user.
1✔
472

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

1✔
482
        mergeRequest merge_user: mergeUser.
1✔
483
        ^ mergeUser
1✔
484
]
1✔
485

486
{ #category : #'import - notes' }
NEW
487
BitBucketModelImporter >> importNotesOfMergeRequest: mergeRequest [
×
488

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

511
{ #category : #'import - projects' }
512
BitBucketModelImporter >> importProject: aProjectID [
×
513

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

518
{ #category : #'import - projects' }
519
BitBucketModelImporter >> importProject: aProjectID ofGroup: aGroup [
×
520

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

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

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

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

546
{ #category : #parsing }
547
BitBucketModelImporter >> parseBranchIntoGLHBranch: branchDictionary ofProject: aGLHProject [
×
548

×
549
        | commit |
×
550
        commit := self
×
551
                          importCommit: (branchDictionary at: #latestCommit)
×
552
                          ofProject: aGLHProject.
×
553
        ^ GLHBranch new
×
554
                  name: (branchDictionary at: #displayId);
×
555
                  commits: { commit } asOrderedCollection;
×
556
                  yourself
×
557
]
×
558

559
{ #category : #parsing }
560
BitBucketModelImporter >> parseCommitIntoGLHCommit: commitDictionary ofProject: aGLHProject [
1✔
561

1✔
562
        | author committer parentIds commitDiffs contribution |
1✔
563
        author := commitDictionary at: #author.
1✔
564
        committer := commitDictionary at: #committer.
1✔
565

1✔
566
        parentIds := (commitDictionary at: #parents) collect: [ :parent |
1✔
567
                             parent at: #id ].
1✔
568

1✔
569
        commitDiffs := self repoApi commits
1✔
570
                               diffOf: (commitDictionary at: #id)
1✔
571
                               inRepository: aGLHProject id
1✔
572
                               ofProject: aGLHProject group id.
1✔
573

1✔
574
        contribution := self getContributionFromDiffs:
1✔
575
                                (commitDiffs at: #diffs).
1✔
576

1✔
577
        ^ GLHCommit new
1✔
578
                  id: (commitDictionary at: #id);
1✔
579
                  message: (commitDictionary at: #message);
1✔
580
                  title: (commitDictionary at: #message) lines first;
1✔
581
                  author_email: (author at: #emailAddress);
1✔
582
                  author_name: (author at: #name);
1✔
583
                  authored_date: (DateAndTime fromUnixTime:
1✔
584
                                           (commitDictionary at: #authorTimestamp) / 1000);
1✔
585
                  created_at: (DateAndTime fromUnixTime:
1✔
586
                                           (commitDictionary at: #authorTimestamp) / 1000);
1✔
587
                  committed_date: (DateAndTime fromUnixTime:
1✔
588
                                           (commitDictionary at: #committerTimestamp) / 1000);
1✔
589
                  committer_email: (committer at: #emailAddress);
1✔
590
                  committer_name: (committer at: #name);
1✔
591
                  parent_ids: parentIds;
1✔
592
                  additions: (contribution at: #additions);
1✔
593
                  deletions: (contribution at: #deletions)
1✔
594
]
1✔
595

596
{ #category : #parsing }
597
BitBucketModelImporter >> parseGroupResult: aDictionary [
1✔
598

1✔
599
        ^ GLHGroup new
1✔
600
                  id: (aDictionary at: #key);
1✔
601
                  "use key instead of id because key is use everywhere else for API"
1✔
602
                  description: (aDictionary at: #description);
1✔
603
                  name: (aDictionary at: #name);
1✔
604
                  web_url: ((aDictionary at: #links at: #self) anyOne at: #href);
1✔
605
                  yourself
1✔
606
]
1✔
607

608
{ #category : #parsing }
609
BitBucketModelImporter >> parseProjectIntoGLHGroup: projectRepository [
1✔
610

1✔
611
        ^ GLHGroup new
1✔
612
                  name: (projectRepository at: #name);
1✔
613
                  id: (projectRepository at: #key);
1✔
614
                  description: (projectRepository at: #description)
1✔
615
]
1✔
616

617
{ #category : #parsing }
618
BitBucketModelImporter >> parsePullRequestIntoGLPHEMergeRequest: pullRequestDictionary [
1✔
619

1✔
620
        | repository project toRef fromRef glpheMergeRequest author state reviewers |
1✔
621
        toRef := pullRequestDictionary at: #toRef.
1✔
622
        fromRef := pullRequestDictionary at: #fromRef.
1✔
623

1✔
624
        reviewers := pullRequestDictionary at: #reviewers.
1✔
625
        reviewers := reviewers collect: [ :reviewer |
1✔
626
                             | reviewerUser |
1✔
627
                             reviewerUser := reviewer at: #user.
1✔
628
                             (self glhModel allWithType: GLHUser)
1✔
629
                                     detect: [ :user | user id = (reviewerUser at: #id) ]
1✔
630
                                     ifFound: [ :user | user ]
1✔
631
                                     ifNone: [
1✔
632
                                             | glhUser |
1✔
633
                                             glhUser := self parseUserIntoGLHUser: reviewerUser.
1✔
634
                                             glhModel add: glhUser.
1✔
635
                                             glhUser ] ].
1✔
636

1✔
637
        repository := toRef at: #repository.
1✔
638
        project := (self glhModel allWithType: GLHProject)
1✔
639
                           detect: [ :glhProject |
1✔
640
                           glhProject id = (repository at: #slug) ]
1✔
641
                           ifFound: [ :glhProject | glhProject ]
1✔
642
                           ifNone: [
1✔
643
                                   project := self parseRepoIntoGLHProject: repository.
1✔
644
                                   self glhModel add: project.
1✔
645
                                   project ].
1✔
646

1✔
647

1✔
648
        author := pullRequestDictionary at: #author.
1✔
649
        author := (self glhModel allWithType: GLHUser)
1✔
650
                          detect: [ :user | user id = ((author at: #user) at: #id) ]
1✔
651
                          ifFound: [ :user | user ]
1✔
652
                          ifNone: [
1✔
653
                          self importUserByUsername:
1✔
654
                                  ((author at: #user) at: #displayName) ].
1✔
655

1✔
656

1✔
657
        glpheMergeRequest := GLHMergeRequest new
1✔
658
                                     name: (pullRequestDictionary at: #title);
1✔
659
                                     title: (pullRequestDictionary at: #title);
1✔
660
                                     id: (pullRequestDictionary at: #id);
1✔
661
                                     project: project;
1✔
662
                                     project_id: project id;
1✔
663
                                     target_branch: (toRef at: #id);
1✔
664
                                     target_project_id:
1✔
665
                                             ((toRef at: #repository) at: #id);
1✔
666
                                     source_branch: (fromRef at: #id);
1✔
667
                                     source_project_id:
1✔
668
                                             ((fromRef at: #repository) at: #id);
1✔
669
                                     updated_at: (DateAndTime fromUnixTime:
1✔
670
                                                              (pullRequestDictionary at: #updatedDate)
1✔
671
                                                              / 1000);
1✔
672
                                     created_at: (DateAndTime fromUnixTime:
1✔
673
                                                              (pullRequestDictionary at: #createdDate)
1✔
674
                                                              / 1000);
1✔
675
                                     author: author.
1✔
676

1✔
677
        "STATE"
1✔
678
        state := pullRequestDictionary at: #state.
1✔
679
        state = 'OPEN' ifTrue: [ glpheMergeRequest state: 'opened' ].
1✔
680
        state = 'MERGED' ifTrue: [
1✔
681
                glpheMergeRequest state: 'merged'.
1✔
682
                glpheMergeRequest merged_at: (DateAndTime fromUnixTime:
1✔
683
                                 (pullRequestDictionary at: #closedDate) / 1000) ].
1✔
684

1✔
685
        state = 'DECLINED' ifTrue: [
1✔
686
                glpheMergeRequest state: 'closed'.
1✔
687
                glpheMergeRequest closed_at: (DateAndTime fromUnixTime:
1✔
688
                                 (pullRequestDictionary at: #closedDate) / 1000) ].
1✔
689

1✔
690
        ^ glpheMergeRequest
1✔
691
]
1✔
692

693
{ #category : #parsing }
694
BitBucketModelImporter >> parseRepoIntoGLHProject: repositoryDictionary [
1✔
695

1✔
696
        | project group glhProject |
1✔
697
        project := repositoryDictionary at: #project.
1✔
698

1✔
699
        group := (self glhModel allWithType: GLHGroup)
1✔
700
                         detect: [ :glhGroup | glhGroup id = (project at: #key) ]
1✔
701
                         ifFound: [ :glhGroup | glhGroup ]
1✔
702
                         ifNone: [
1✔
703
                                 | newGroup |
1✔
704
                                 newGroup := self parseProjectIntoGLHGroup: project.
1✔
705
                                 glhModel add: newGroup.
1✔
706
                                 newGroup ].
1✔
707

1✔
708

1✔
709
        glhProject := GLHProject new
1✔
710
                              name: (repositoryDictionary at: #name);
1✔
711
                              id: (repositoryDictionary at: #slug);
1✔
712
                              repository: GLHRepository new;
1✔
713
                              group: group.
1✔
714

1✔
715
        group addProject: glhProject.
1✔
716

1✔
717
        ^ glhProject
1✔
718
]
1✔
719

720
{ #category : #parsing }
721
BitBucketModelImporter >> parseUserIntoGLHUser: userDictionnary [
1✔
722

1✔
723
        ^ GLHUser new
1✔
724
                  name: (userDictionnary at: #displayName);
1✔
725
                  public_email: (userDictionnary at: #emailAddress ifAbsent: [ nil ]);
1✔
726
                  id: (userDictionnary at: #id);
1✔
727
                  username: (userDictionnary at: #name)
1✔
728
]
1✔
729

730
{ #category : #accessing }
731
BitBucketModelImporter >> withInitialCommits [
×
732

×
733
        ^ withInitialCommits
×
734
]
×
735

736
{ #category : #accessing }
737
BitBucketModelImporter >> withInitialCommits: anObject [
×
738

×
739
        withInitialCommits := anObject
×
740
]
×
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