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

moosetechnology / GitProjectHealth / 18275233369

01 Oct 2025 07:30AM UTC coverage: 77.946% (+4.6%) from 73.342%
18275233369

Pull #233

github

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

4743 of 5132 new or added lines in 45 files covered. (92.42%)

32 existing lines in 8 files now uncovered.

23068 of 29595 relevant lines covered (77.95%)

0.78 hits per line

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

76.74
/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

×
NEW
192
        | branches glhBranches |
×
NEW
193
        self
×
NEW
194
                deprecated: 'Use importBranchesOfProject: instead of current one'
×
NEW
195
                on: '26 September 2025'
×
NEW
196
                in:
×
NEW
197
                'Pharo-12.0.0+SNAPSHOT.build.1571.sha.cf5fcd22e66957962c97dffc58b0393b7f368147 (64 Bit)'.
×
NEW
198
        branches := self repoApi branches
×
NEW
199
                            allWithParams: {  } asDictionary
×
NEW
200
                            inRepository: aGLHProject id
×
NEW
201
                            ofProject: aGLHProject group id.
×
NEW
202
        glhBranches := branches collect: [ :branch |
×
NEW
203
                               self
×
NEW
204
                                       parseBranchIntoGLHBranch: branch
×
NEW
205
                                       ofProject: aGLHProject ].
×
NEW
206

×
NEW
207
        glhBranches do: [ :glhBranch |
×
NEW
208
                aGLHProject repository addBranch: glhBranch ].
×
NEW
209

×
NEW
210
        self glhModel addAll: glhBranches unless: self blockForBranchEquality.
×
NEW
211

×
NEW
212
        ^ glhBranches
×
NEW
213
]
×
214

215
{ #category : #'import - branches' }
NEW
216
BitBucketModelImporter >> importBranchesOfProject: aGLHProject [
×
NEW
217

×
218
        | branches glhBranches |
×
219
        branches := self repoApi branches
×
220
                            allWithParams: {  } asDictionary
×
221
                            inRepository: aGLHProject id
×
222
                            ofProject: aGLHProject group id.
×
223
        glhBranches := branches collect: [ :branch |
×
224
                               self
×
225
                                       parseBranchIntoGLHBranch: branch
×
226
                                       ofProject: aGLHProject ].
×
227

×
228
        glhBranches do: [ :glhBranch |
×
229
                aGLHProject repository addBranch: glhBranch ].
×
230

×
231
        self glhModel addAll: glhBranches unless: self blockForBranchEquality.
×
232

×
233
        ^ glhBranches
×
234
]
×
235

236
{ #category : #'import - commits' }
237
BitBucketModelImporter >> importCommit: aCommitID ofProject: aGLHProject [
1✔
238

1✔
239
        | result parsedResult |
1✔
240
        (self glhModel allWithType: GLHCommit) asOrderedCollection
1✔
241
                detect: [ :commit | commit id = aCommitID ]
1✔
242
                ifFound: [ :commit | ^ commit ].
1✔
243
        result := self repoApi commits
1✔
244
                          get: aCommitID
1✔
245
                          inRepository: aGLHProject id
1✔
246
                          ofProject: aGLHProject group id.
1✔
247
        parsedResult := self
1✔
248
                                parseCommitIntoGLHCommit: result
1✔
249
                                ofProject: aGLHProject.
1✔
250

1✔
251
        parsedResult := self glhModel addAll: { parsedResult } unless: self blockOnIdEquality.
1✔
252
        ^ parsedResult anyOne
1✔
253
]
1✔
254

255
{ #category : #'import - commits' }
256
BitBucketModelImporter >> importCommitsOfProject: aGLHProject since: since until: until [
1✔
257

1✔
258
        | commits |
1✔
259
        commits := self repoApi commits
1✔
260
                           allSince: since
1✔
261
                           until: until
1✔
262
                           inRepository: aGLHProject id
1✔
263
                           ofProject: aGLHProject group id.
1✔
264
                
1✔
265
        commits := commits collect: [ :commit |
1✔
266
                           self
1✔
267
                                   parseCommitIntoGLHCommit: commit
1✔
268
                                   ofProject: aGLHProject ].
1✔
269

1✔
270

1✔
271
        commits := self glhModel
1✔
272
                           addAll: commits
1✔
273
                           unless: self blockOnIdEquality.
1✔
274
        ^ aGLHProject repository commits
1✔
275
                  addAll: commits
1✔
276
                  unless: self blockOnIdEquality
1✔
277
]
1✔
278

279
{ #category : #'import - projects' }
280
BitBucketModelImporter >> importContributedProjectsOfUser: aGLHUser [
1✔
281

1✔
282
        | projects repositories repositoriesCommits userRepositories userProjects |
1✔
283
        "get all projects"
1✔
284
        projects := self repoApi projects all.
1✔
285

1✔
286
        "get all repos of projects"
1✔
287
        repositories := projects flatCollect: [ :project |
1✔
288
                                self repoApi repositories allInProject:
1✔
289
                                        (project at: #key) ].
1✔
290

1✔
291

1✔
292
        "get all commits of repo"
1✔
293
        repositoriesCommits := repositories collect: [ :repository |
1✔
294
                                       repository -> (self repoApi commits allSince: DateAndTime now - 10 days until: DateAndTime now inRepository: (repository at: #slug) ofProject:  ((repository at: #project) at: #key))
1✔
295
                                                 ].
1✔
296

1✔
297

1✔
298
        "look if user is author of min one commit"
1✔
299
        userRepositories := repositoriesCommits select: [ :repository |
1✔
300
                                    | repos |
1✔
301
                                    repos := repository value
1✔
302
                                                     ifEmpty: [ false ]
1✔
303
                                                     ifNotEmpty: [
1✔
304
                                                             repository value
1✔
305
                                                                     detect: [ :commit |
1✔
306
                                                                     ((commit at: #author) at: #name)
1✔
307
                                                                     = aGLHUser username ]
1✔
308
                                                                     ifFound: [ true ]
1✔
309
                                                                     ifNone: [ false ] ] ].
1✔
310

1✔
311

1✔
312
        "Transform user repositories in GLHProject"
1✔
313
        userProjects := userRepositories collect: [ :repoCommits |
1✔
314
                                | repo project |
1✔
315
                                repo := repoCommits key.
1✔
316
                                project := repo at: #project.
1✔
317

1✔
318
                                (self glhModel allWithType: GLHProject)
1✔
319
                                        detect: [ :glhProject |
1✔
320
                                        glhProject id = (project at: #key) ]
1✔
321
                                        ifFound: [ :glhProject | glhProject ]
1✔
322
                                        ifNone: [
1✔
323
                                                | glhProject |
1✔
324
                                                glhProject := self parseRepoIntoGLHProject: repo.
1✔
325
                                                glhModel add: glhProject.
1✔
326
                                                glhProject ] ].
1✔
327

1✔
328
        aGLHUser contributedProjects: userProjects.
1✔
329

1✔
330
        ^ userProjects
1✔
331
]
1✔
332

333
{ #category : #'import - commits' }
334
BitBucketModelImporter >> importCreatorOfCommit: aGLHCommit [
1✔
335

1✔
336
        | creator |
1✔
337
        (self glhModel allWithType: GLHUser)
1✔
338
                detect: [ :user | user username = aGLHCommit author_name ]
1✔
339
                ifFound: [ :user |
1✔
340
                        aGLHCommit commitCreator: user.
1✔
341
                        ^ user ].
1✔
342

1✔
343
        creator := self importUserByUsername: aGLHCommit author_name.
1✔
344
        aGLHCommit commitCreator: creator.
1✔
345
        ^ creator
1✔
346
]
1✔
347

348
{ #category : #'import - commits' }
349
BitBucketModelImporter >> importDiffOfCommit: aCommit [
1✔
350

1✔
351
        | result diffsResult |
1✔
352
        aCommit diffs ifNotEmpty: [
1✔
353
                'Diff already importer: ' , aCommit short_id printString recordInfo.
1✔
354
                ^ aCommit diffs ].
1✔
355
        ('Import diff of commit: ' , aCommit short_id printString) recordInfo.
1✔
356
        result := self repoApi commits diffOf: aCommit id inRepository: aCommit repository project id  ofProject: aCommit repository project group id.
1✔
357

1✔
358
        diffsResult := self convertBitBucketDiffToGitDiff: result.
1✔
359

1✔
360

1✔
361
        diffsResult := aCommit diffs
1✔
362
                               addAll: diffsResult
1✔
363
                               unless: self blockForDiffEquality.
1✔
364

1✔
365
        "changes are added into the model during the import"
1✔
366
        diffsResult do: [ :diff | self importDiffRangesForDiff: diff ].
1✔
367

1✔
368
        ^ diffsResult
1✔
369
]
1✔
370

371
{ #category : #'import - groups' }
372
BitBucketModelImporter >> importGroup: aGroupID [
1✔
373

1✔
374
        | result projectResult |
1✔
375
        ('Import group with id:  ' , aGroupID printString) recordInfo.
1✔
376

1✔
377
        (glhModel allWithType: GLHGroup)
1✔
378
                detect: [ :group | group id = aGroupID ]
1✔
379
                ifFound: [ :group | ^ group ].
1✔
380
        "group are named projects in bitbucket"
1✔
381
        result := self repoApi projects get: aGroupID.
1✔
382
        projectResult := self parseGroupResult: result.
1✔
383

1✔
384
        ^ self glhModel add: projectResult unless: self blockOnIdEquality
1✔
385
]
1✔
386

387
{ #category : #'import - merge-requests' }
388
BitBucketModelImporter >> importMergeRequestCommits: mergeRequest [
1✔
389

1✔
390
        | commits |
1✔
391
        commits := self repoApi pullRequests
1✔
392
                           commitsOf: mergeRequest id
1✔
393
                           inRepository: mergeRequest project id
1✔
394
                           ofProject: mergeRequest project group id.
1✔
395

1✔
396
        commits := commits collect: [ :commit |
1✔
397
                           self
1✔
398
                                   parseCommitIntoGLHCommit: commit
1✔
399
                                   ofProject: mergeRequest project ].
1✔
400

1✔
401
        mergeRequest commits: commits.
1✔
402

1✔
403
        ^ commits
1✔
404
]
1✔
405

406
{ #category : #'import - merge-requests' }
407
BitBucketModelImporter >> importMergeRequestMergeCommits: aGLHMergeRequest [
×
408

×
409
        aGLHMergeRequest mergedCommit ifNotNil: [
×
410
                ^ { aGLHMergeRequest mergedCommit } ].
×
411
        aGLHMergeRequest project repository commits
×
412
                detect: [ :c |
×
413
                c parent_ids includes: aGLHMergeRequest commits last id ]
×
414
                ifFound: [ :found |
×
415
                        aGLHMergeRequest mergedCommit: found.
×
416
                        aGLHMergeRequest merge_commit_sha: found id.
×
417
                        self importMergeRequestStats: aGLHMergeRequest.
×
418
                        ^ { found } ].
×
419

×
420
        self
×
421
                importCommitsOfProject: aGLHMergeRequest project
×
422
                since: aGLHMergeRequest created_at
×
423
                until: aGLHMergeRequest merged_at.
×
424
        self chainsCommitsFrom: aGLHMergeRequest project repository commits.
×
425
        aGLHMergeRequest project repository commits
×
426
                detect: [ :c |
×
427
                c parent_ids includes: aGLHMergeRequest commits last id ]
×
428
                ifFound: [ :found |
×
429
                        aGLHMergeRequest mergedCommit: found.
×
430
                        aGLHMergeRequest merge_commit_sha: found id.
×
431
                        self importMergeRequestStats: aGLHMergeRequest.
×
432
                        ^ { found } ]
×
433
]
×
434

435
{ #category : #'import - merge-requests' }
436
BitBucketModelImporter >> importMergeRequestStats: aMergeRequest [
1✔
437

1✔
438
        | commitDiffs contribution |
1✔
439
        "can not recompute diff of mergedcommit if none"
1✔
440
        aMergeRequest mergedCommit ifNil: [ ^ self ].
1✔
441
        (aMergeRequest mergedCommit additions isNotNil and: [
1✔
442
                 aMergeRequest mergedCommit deletions isNotNil and: [
1✔
443
                         aMergeRequest mergedCommit additions ~= 0 or: [
1✔
444
                                 aMergeRequest mergedCommit deletions ~= 0 ] ] ]) ifTrue: [
1✔
445
                ^ self ].
1✔
446

1✔
447
        commitDiffs := self repoApi pullRequests
1✔
448
                               diffOf: aMergeRequest id
1✔
449
                               inRepository: aMergeRequest project id
1✔
450
                               ofProject: aMergeRequest project group id.
1✔
451

1✔
452
        contribution := self getContributionFromDiffs:
1✔
453
                                (commitDiffs at: #diffs).
1✔
454

1✔
455
        ^ aMergeRequest mergedCommit
1✔
456
                  additions: (contribution at: #additions);
1✔
457
                  deletions: (contribution at: #deletions)
1✔
458
]
1✔
459

460
{ #category : #'import - merge-requests' }
461
BitBucketModelImporter >> importMergeRequestsOfProject: aGLHProject since: fromDate until: toDate [
1✔
462

1✔
463
        | pullRequests params |
1✔
464
        params := { 
1✔
465
                #state -> 'all'
1✔
466
         } asDictionary.
1✔
467
        pullRequests := self repoApi pullRequests allSince: fromDate until: toDate withParams: params  inRepository: aGLHProject id ofProject: aGLHProject group id.
1✔
468

1✔
469
        pullRequests := pullRequests collect: [ :pullRequest |
1✔
470
                                self parsePullRequestIntoGLPHEMergeRequest:
1✔
471
                                        pullRequest ].
1✔
472

1✔
473
        pullRequests := self glhModel
1✔
474
                                addAll: pullRequests
1✔
475
                                unless: self blockOnIdEquality.
1✔
476

1✔
477
        ^ pullRequests
1✔
478
]
1✔
479

480
{ #category : #'import - merge-requests' }
481
BitBucketModelImporter >> importMergeResquestAuthor: mergeRequest [
×
482
        mergeRequest author ifNotNil: [ ^mergeRequest ]
×
483
]
×
484

485
{ #category : #'import - merge-requests' }
486
BitBucketModelImporter >> importMergeResquestMerger: mergeRequest [
1✔
487

1✔
488
        | activities mergeActivity mergeUser |
1✔
489
        mergeRequest merge_user ifNotNil: [ ^ mergeRequest merge_user ].
1✔
490
        mergeRequest state = 'merged' ifFalse: [ ^ nil ].
1✔
491

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

1✔
494
        mergeActivity := activities detect: [ :activity |
1✔
495
                                 (activity at: #action) = 'MERGED' ].
1✔
496

1✔
497
        mergeUser := mergeActivity at: #user.
1✔
498

1✔
499
        mergeUser := (glhModel allWithType: GLHUser)
1✔
500
                             detect: [ :user | user id = (mergeUser at: #id) ]
1✔
501
                             ifFound: [ :user | user ]
1✔
502
                             ifNone: [
1✔
503
                                     | glhUser |
1✔
504
                                     glhUser := self parseUserIntoGLHUser: mergeUser.
1✔
505
                                     glhModel add: glhUser.
1✔
506
                                     glhUser ].
1✔
507

1✔
508
        mergeRequest merge_user: mergeUser.
1✔
509
        ^ mergeUser
1✔
510
]
1✔
511

512
{ #category : #'import - notes' }
NEW
513
BitBucketModelImporter >> importNotesOfMergeRequest: mergeRequest [
×
514

×
515
        | results notes |
×
516
        results := self repoApi pullRequests
×
517
                           activitiesOf: mergeRequest id
×
518
                           inRepository: mergeRequest project id
×
519
                           ofProject: mergeRequest project group id.
×
520
        notes := results
×
521
                         select: [ :activity | (activity at: #action) = 'COMMENTED' ]
×
522
                         thenCollect: [ :commentActivity |
×
523
                         self extractNoteFromComment: commentActivity ].
×
524
        "notes := self parseNoteJson: results."
×
525
        notes do: [ :note |
×
526
                note author:
×
527
                        (self importUserByUsername: (note author at: #displayName)).
×
528
                note name: note id asString ].
×
529
        notes := notes flattened.
×
530
        notes := self glhModel addAll: notes unless: self blockOnIdEquality.
×
531
        notes := mergeRequest note
×
532
                         addAll: notes
×
533
                         unless: self blockOnIdEquality.
×
534
        ^ notes
×
535
]
×
536

537
{ #category : #'import - projects' }
538
BitBucketModelImporter >> importProject: aProjectID [
×
539

×
540
        Error signal:
×
541
                'Bitbucket api cannot import directly a project (in the sens of GPH). One need to import a group, then the projects of this group.'
×
542
]
×
543

544
{ #category : #'import - projects' }
545
BitBucketModelImporter >> importProject: aProjectID ofGroup: aGroup [
×
546

×
547
        | repoOfProject project |
×
548
        repoOfProject := self repoApi repositories
×
549
                                 get: aProjectID
×
550
                                 ofProject: aGroup id.
×
551
        project := self parseRepoIntoGLHProject: repoOfProject.
×
552
        self glhModel add: project.
×
553
        ^ project
×
554
]
×
555

556
{ #category : #'import - users' }
557
BitBucketModelImporter >> importUserByUsername: username [
1✔
558

1✔
559
        ^ self userCatalogue collectUsernames at: username ifAbsent: [
1✔
560
                  | users glhUser user params|
1✔
561
                  params := { #filter -> username } asDictionary. 
1✔
562
                  users := self repoApi users allWithParams: params.
1✔
563
                  users ifEmpty: [ ^ nil ].
1✔
564
                  user := users first.
1✔
565

1✔
566
                  glhUser := self parseUserIntoGLHUser: user.
1✔
567
                  self glhModel add: glhUser unless: self blockOnIdEquality.
1✔
568
                  self userCatalogue addUser: glhUser withName: username.
1✔
569
                  glhUser ]
1✔
570
]
1✔
571

572
{ #category : #parsing }
573
BitBucketModelImporter >> parseBranchIntoGLHBranch: branchDictionary ofProject: aGLHProject [
×
574

×
575
        | commit |
×
576
        commit := self
×
577
                          importCommit: (branchDictionary at: #latestCommit)
×
578
                          ofProject: aGLHProject.
×
579
        ^ GLHBranch new
×
580
                  name: (branchDictionary at: #displayId);
×
581
                  commits: { commit } asOrderedCollection;
×
582
                  yourself
×
583
]
×
584

585
{ #category : #parsing }
586
BitBucketModelImporter >> parseCommitIntoGLHCommit: commitDictionary ofProject: aGLHProject [
1✔
587

1✔
588
        | author committer parentIds commitDiffs contribution |
1✔
589
        author := commitDictionary at: #author.
1✔
590
        committer := commitDictionary at: #committer.
1✔
591

1✔
592
        parentIds := (commitDictionary at: #parents) collect: [ :parent |
1✔
593
                             parent at: #id ].
1✔
594

1✔
595
        commitDiffs := self repoApi commits
1✔
596
                               diffOf: (commitDictionary at: #id)
1✔
597
                               inRepository: aGLHProject id
1✔
598
                               ofProject: aGLHProject group id.
1✔
599

1✔
600
        contribution := self getContributionFromDiffs:
1✔
601
                                (commitDiffs at: #diffs).
1✔
602

1✔
603
        ^ GLHCommit new
1✔
604
                  id: (commitDictionary at: #id);
1✔
605
                  message: (commitDictionary at: #message);
1✔
606
                  title: (commitDictionary at: #message) lines first;
1✔
607
                  author_email: (author at: #emailAddress);
1✔
608
                  author_name: (author at: #name);
1✔
609
                  authored_date: (DateAndTime fromUnixTime:
1✔
610
                                           (commitDictionary at: #authorTimestamp) / 1000);
1✔
611
                  created_at: (DateAndTime fromUnixTime:
1✔
612
                                           (commitDictionary at: #authorTimestamp) / 1000);
1✔
613
                  committed_date: (DateAndTime fromUnixTime:
1✔
614
                                           (commitDictionary at: #committerTimestamp) / 1000);
1✔
615
                  committer_email: (committer at: #emailAddress);
1✔
616
                  committer_name: (committer at: #name);
1✔
617
                  parent_ids: parentIds;
1✔
618
                  additions: (contribution at: #additions);
1✔
619
                  deletions: (contribution at: #deletions)
1✔
620
]
1✔
621

622
{ #category : #parsing }
623
BitBucketModelImporter >> parseGroupResult: aDictionary [
1✔
624

1✔
625
        ^ GLHGroup new
1✔
626
                  id: (aDictionary at: #key);
1✔
627
                  "use key instead of id because key is use everywhere else for API"
1✔
628
                  description: (aDictionary at: #description);
1✔
629
                  name: (aDictionary at: #name);
1✔
630
                  web_url: ((aDictionary at: #links at: #self) anyOne at: #href);
1✔
631
                  yourself
1✔
632
]
1✔
633

634
{ #category : #parsing }
635
BitBucketModelImporter >> parseProjectIntoGLHGroup: projectRepository [
1✔
636

1✔
637
        ^ GLHGroup new
1✔
638
                  name: (projectRepository at: #name);
1✔
639
                  id: (projectRepository at: #key);
1✔
640
                  description: (projectRepository at: #description)
1✔
641
]
1✔
642

643
{ #category : #parsing }
644
BitBucketModelImporter >> parsePullRequestIntoGLPHEMergeRequest: pullRequestDictionary [
1✔
645

1✔
646
        | repository project toRef fromRef glpheMergeRequest author state reviewers |
1✔
647
        toRef := pullRequestDictionary at: #toRef.
1✔
648
        fromRef := pullRequestDictionary at: #fromRef.
1✔
649

1✔
650
        reviewers := pullRequestDictionary at: #reviewers.
1✔
651
        reviewers := reviewers collect: [ :reviewer |
1✔
652
                             | reviewerUser |
1✔
653
                             reviewerUser := reviewer at: #user.
1✔
654
                             (self glhModel allWithType: GLHUser)
1✔
655
                                     detect: [ :user | user id = (reviewerUser at: #id) ]
1✔
656
                                     ifFound: [ :user | user ]
1✔
657
                                     ifNone: [
1✔
658
                                             | glhUser |
1✔
659
                                             glhUser := self parseUserIntoGLHUser: reviewerUser.
1✔
660
                                             glhModel add: glhUser.
1✔
661
                                             glhUser ] ].
1✔
662

1✔
663
        repository := toRef at: #repository.
1✔
664
        project := (self glhModel allWithType: GLHProject)
1✔
665
                           detect: [ :glhProject |
1✔
666
                           glhProject id = (repository at: #slug) ]
1✔
667
                           ifFound: [ :glhProject | glhProject ]
1✔
668
                           ifNone: [
1✔
669
                                   project := self parseRepoIntoGLHProject: repository.
1✔
670
                                   self glhModel add: project.
1✔
671
                                   project ].
1✔
672

1✔
673

1✔
674
        author := pullRequestDictionary at: #author.
1✔
675
        author := (self glhModel allWithType: GLHUser)
1✔
676
                          detect: [ :user | user id = ((author at: #user) at: #id) ]
1✔
677
                          ifFound: [ :user | user ]
1✔
678
                          ifNone: [
1✔
679
                          self importUserByUsername:
1✔
680
                                  ((author at: #user) at: #displayName) ].
1✔
681

1✔
682

1✔
683
        glpheMergeRequest := GLHMergeRequest new
1✔
684
                                     name: (pullRequestDictionary at: #title);
1✔
685
                                     title: (pullRequestDictionary at: #title);
1✔
686
                                     id: (pullRequestDictionary at: #id);
1✔
687
                                     project: project;
1✔
688
                                     project_id: project id;
1✔
689
                                     target_branch: (toRef at: #id);
1✔
690
                                     target_project_id:
1✔
691
                                             ((toRef at: #repository) at: #id);
1✔
692
                                     source_branch: (fromRef at: #id);
1✔
693
                                     source_project_id:
1✔
694
                                             ((fromRef at: #repository) at: #id);
1✔
695
                                     updated_at: (DateAndTime fromUnixTime:
1✔
696
                                                              (pullRequestDictionary at: #updatedDate)
1✔
697
                                                              / 1000);
1✔
698
                                     created_at: (DateAndTime fromUnixTime:
1✔
699
                                                              (pullRequestDictionary at: #createdDate)
1✔
700
                                                              / 1000);
1✔
701
                                     author: author.
1✔
702

1✔
703
        "STATE"
1✔
704
        state := pullRequestDictionary at: #state.
1✔
705
        state = 'OPEN' ifTrue: [ glpheMergeRequest state: 'opened' ].
1✔
706
        state = 'MERGED' ifTrue: [
1✔
707
                glpheMergeRequest state: 'merged'.
1✔
708
                glpheMergeRequest merged_at: (DateAndTime fromUnixTime:
1✔
709
                                 (pullRequestDictionary at: #closedDate) / 1000) ].
1✔
710

1✔
711
        state = 'DECLINED' ifTrue: [
1✔
712
                glpheMergeRequest state: 'closed'.
1✔
713
                glpheMergeRequest closed_at: (DateAndTime fromUnixTime:
1✔
714
                                 (pullRequestDictionary at: #closedDate) / 1000) ].
1✔
715

1✔
716
        ^ glpheMergeRequest
1✔
717
]
1✔
718

719
{ #category : #parsing }
720
BitBucketModelImporter >> parseRepoIntoGLHProject: repositoryDictionary [
1✔
721

1✔
722
        | project group glhProject |
1✔
723
        project := repositoryDictionary at: #project.
1✔
724

1✔
725
        group := (self glhModel allWithType: GLHGroup)
1✔
726
                         detect: [ :glhGroup | glhGroup id = (project at: #key) ]
1✔
727
                         ifFound: [ :glhGroup | glhGroup ]
1✔
728
                         ifNone: [
1✔
729
                                 | newGroup |
1✔
730
                                 newGroup := self parseProjectIntoGLHGroup: project.
1✔
731
                                 glhModel add: newGroup.
1✔
732
                                 newGroup ].
1✔
733

1✔
734

1✔
735
        glhProject := GLHProject new
1✔
736
                              name: (repositoryDictionary at: #name);
1✔
737
                              id: (repositoryDictionary at: #slug);
1✔
738
                              repository: GLHRepository new;
1✔
739
                              group: group.
1✔
740

1✔
741
        group addProject: glhProject.
1✔
742

1✔
743
        ^ glhProject
1✔
744
]
1✔
745

746
{ #category : #parsing }
747
BitBucketModelImporter >> parseUserIntoGLHUser: userDictionnary [
1✔
748

1✔
749
        ^ GLHUser new
1✔
750
                  name: (userDictionnary at: #displayName);
1✔
751
                  public_email: (userDictionnary at: #emailAddress ifAbsent: [ nil ]);
1✔
752
                  id: (userDictionnary at: #id);
1✔
753
                  username: (userDictionnary at: #name)
1✔
754
]
1✔
755

756
{ #category : #accessing }
757
BitBucketModelImporter >> withInitialCommits [
×
758

×
759
        ^ withInitialCommits
×
760
]
×
761

762
{ #category : #accessing }
763
BitBucketModelImporter >> withInitialCommits: anObject [
×
764

×
765
        withInitialCommits := anObject
×
766
]
×
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