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

moosetechnology / GitProjectHealth / 14831041681

05 May 2025 07:12AM UTC coverage: 73.222% (+0.7%) from 72.511%
14831041681

push

github

web-flow
Merge pull request #186 from moosetechnology/develop

Develop

379 of 486 new or added lines in 10 files covered. (77.98%)

10 existing lines in 1 file now uncovered.

15876 of 21682 relevant lines covered (73.22%)

0.73 hits per line

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

80.6
/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 }
UNCOV
23
BitBucketModelImporter >> bitBucketApi: anObject [
×
UNCOV
24

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

×
UNCOV
31
        repoApi := anObject
×
UNCOV
32
]
×
33

34
{ #category : #'import - projects' }
35
BitBucketModelImporter >> completeImportProject: aGLHProject [
1✔
36

1✔
37
        aGLHProject repository: GLHRepository new.
1✔
38
        self glhModel add: aGLHProject repository.
1✔
39
        "TODO: import repository"
1✔
40
        ^ aGLHProject
1✔
41
]
1✔
42

43
{ #category : #commit }
44
BitBucketModelImporter >> completeImportedCommit: aCommit [ 
1✔
45
        
1✔
46
        ('completing commit: ' , aCommit short_id printString) recordInfo.
1✔
47
        self importCreatorOfCommit: aCommit.
1✔
48

1✔
49
        self withCommitDiffs ifTrue: [
1✔
50
                | diffs |
1✔
51
                aCommit diffs ifEmpty: [
1✔
52
                        diffs := self importDiffOfCommit: aCommit.
1✔
53
                        self glhModel addAll: diffs unless: self blockForDiffEquality ] ].
1✔
54

1✔
55
        ^ aCommit
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' }
NEW
122
BitBucketModelImporter >> extractNoteFromComment: aDictionary [
×
NEW
123

×
NEW
124
        ^ GLHNote new
×
NEW
125
                  created_at:
×
NEW
126
                          (DateAndTime fromUnixTime: (aDictionary at: #createdDate) / 1000);
×
NEW
127
                  id: (aDictionary at: #id);
×
NEW
128
                  author: (aDictionary at: #user);
×
NEW
129
                  body: (aDictionary at: #comment at: #text);
×
NEW
130
                  yourself
×
NEW
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 completeImportProject: 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 - commits' }
NEW
190
BitBucketModelImporter >> importCommit: aCommitID ofProject: aGLHProject [
×
NEW
191

×
NEW
192
        | result parsedResult |
×
NEW
193
        (self glhModel allWithType: GLHCommit) asOrderedCollection
×
NEW
194
                detect: [ :commit | commit id = aCommitID ]
×
NEW
195
                ifFound: [ :commit | ^ commit ].
×
NEW
196
        result := self repoApi commits
×
NEW
197
                          get: aCommitID
×
NEW
198
                          inRepository: aGLHProject id
×
NEW
199
                          ofProject: aGLHProject group id.
×
NEW
200
        parsedResult := self
×
NEW
201
                                parseCommitIntoGLHCommit: result
×
NEW
202
                                ofProject: aGLHProject.
×
NEW
203

×
NEW
204
        self glhModel addAll: { parsedResult } unless: self blockOnIdEquality.
×
NEW
205
        ^ parsedResult
×
NEW
206
]
×
207

208
{ #category : #'import - commits' }
209
BitBucketModelImporter >> importCommitsOfProject: aGLHProject since: since until: until [
1✔
210

1✔
211
        | commits |
1✔
212
        commits := self repoApi commits
1✔
213
                           allSince: since
1✔
214
                           until: until
1✔
215
                           inRepository: aGLHProject id
1✔
216
                           ofProject: aGLHProject group id.
1✔
217
                
1✔
218
        commits := commits collect: [ :commit |
1✔
219
                           self
1✔
220
                                   parseCommitIntoGLHCommit: commit
1✔
221
                                   ofProject: aGLHProject ].
1✔
222

1✔
223

1✔
224
        commits := self glhModel
1✔
225
                           addAll: commits
1✔
226
                           unless: self blockOnIdEquality.
1✔
227
        ^ aGLHProject repository commits
1✔
228
                  addAll: commits
1✔
229
                  unless: self blockOnIdEquality
1✔
230
]
1✔
231

232
{ #category : #'import - projects' }
233
BitBucketModelImporter >> importContributedProjectsOfUser: aGLHUser [
1✔
234

1✔
235
        | projects repositories repositoriesCommits userRepositories userProjects |
1✔
236
        "get all projects"
1✔
237
        projects := self repoApi projects all.
1✔
238

1✔
239
        "get all repos of projects"
1✔
240
        repositories := projects flatCollect: [ :project |
1✔
241
                                self repoApi repositories allInProject:
1✔
242
                                        (project at: #key) ].
1✔
243

1✔
244

1✔
245
        "get all commits of repo"
1✔
246
        repositoriesCommits := repositories collect: [ :repository |
1✔
247
                                       repository -> (self repoApi commits allSince: DateAndTime now - 10 days until: DateAndTime now inRepository: (repository at: #slug) ofProject:  ((repository at: #project) at: #key))
1✔
248
                                                 ].
1✔
249

1✔
250

1✔
251
        "look if user is author of min one commit"
1✔
252
        userRepositories := repositoriesCommits select: [ :repository |
1✔
253
                                    | repos |
1✔
254
                                    repos := repository value
1✔
255
                                                     ifEmpty: [ false ]
1✔
256
                                                     ifNotEmpty: [
1✔
257
                                                             repository value
1✔
258
                                                                     detect: [ :commit |
1✔
259
                                                                     ((commit at: #author) at: #name)
1✔
260
                                                                     = aGLHUser username ]
1✔
261
                                                                     ifFound: [ true ]
1✔
262
                                                                     ifNone: [ false ] ] ].
1✔
263

1✔
264

1✔
265
        "Transform user repositories in GLHProject"
1✔
266
        userProjects := userRepositories collect: [ :repoCommits |
1✔
267
                                | repo project |
1✔
268
                                repo := repoCommits key.
1✔
269
                                project := repo at: #project.
1✔
270

1✔
271
                                (self glhModel allWithType: GLHProject)
1✔
272
                                        detect: [ :glhProject |
1✔
273
                                        glhProject id = (project at: #key) ]
1✔
274
                                        ifFound: [ :glhProject | glhProject ]
1✔
275
                                        ifNone: [
1✔
276
                                                | glhProject |
1✔
277
                                                glhProject := self parseRepoIntoGLHProject: repo.
1✔
278
                                                glhModel add: glhProject.
1✔
279
                                                glhProject ] ].
1✔
280

1✔
281
        aGLHUser contributedProjects: userProjects.
1✔
282

1✔
283
        ^ userProjects
1✔
284
]
1✔
285

286
{ #category : #'import - commits' }
287
BitBucketModelImporter >> importCreatorOfCommit: aGLHCommit [
1✔
288

1✔
289
        | creator |
1✔
290
        (self glhModel allWithType: GLHUser)
1✔
291
                detect: [ :user | user username = aGLHCommit author_name ]
1✔
292
                ifFound: [ :user |
1✔
293
                        aGLHCommit commitCreator: user.
1✔
294
                        ^ user ].
1✔
295

1✔
296
        creator := self importUserByUsername: aGLHCommit author_name.
1✔
297
        aGLHCommit commitCreator: creator.
1✔
298
        ^ creator
1✔
299
]
1✔
300

301
{ #category : #'import - commits' }
302
BitBucketModelImporter >> importDiffOfCommit: aCommit [
1✔
303

1✔
304
        | result diffsResult |
1✔
305
        aCommit diffs ifNotEmpty: [
1✔
306
                'Diff already importer: ' , aCommit short_id printString recordInfo.
1✔
307
                ^ aCommit diffs ].
1✔
308
        ('Import diff of commit: ' , aCommit short_id printString) recordInfo.
1✔
309
        result := self repoApi commits diffOf: aCommit id inRepository: aCommit repository project id  ofProject: aCommit repository project group id.
1✔
310

1✔
311
        diffsResult := self convertBitBucketDiffToGitDiff: result.
1✔
312

1✔
313

1✔
314
        diffsResult := aCommit diffs
1✔
315
                               addAll: diffsResult
1✔
316
                               unless: self blockForDiffEquality.
1✔
317

1✔
318
        "changes are added into the model during the import"
1✔
319
        diffsResult do: [ :diff | self importDiffRangesForDiff: diff ].
1✔
320

1✔
321
        ^ diffsResult
1✔
322
]
1✔
323

324
{ #category : #'import - groups' }
325
BitBucketModelImporter >> importGroup: aGroupID [
1✔
326

1✔
327
        | result projectResult |
1✔
328
        ('Import group with id:  ' , aGroupID printString) recordInfo.
1✔
329

1✔
330
        (glhModel allWithType: GLHGroup)
1✔
331
                detect: [ :group | group id = aGroupID ]
1✔
332
                ifFound: [ :group | ^ group ].
1✔
333
        "group are named projects in bitbucket"
1✔
334
        result := self repoApi projects get: aGroupID.
1✔
335
        projectResult := self parseGroupResult: result.
1✔
336

1✔
337
        ^ self glhModel add: projectResult unless: self blockOnIdEquality
1✔
338
]
1✔
339

340
{ #category : #'import - merge-requests' }
341
BitBucketModelImporter >> importMergeRequestCommits: mergeRequest [
1✔
342

1✔
343
        | commits |
1✔
344
        commits := self repoApi pullRequests
1✔
345
                           commitsOf: mergeRequest id
1✔
346
                           inRepository: mergeRequest project id
1✔
347
                           ofProject: mergeRequest project group id.
1✔
348

1✔
349
        commits := commits collect: [ :commit |
1✔
350
                           self
1✔
351
                                   parseCommitIntoGLHCommit: commit
1✔
352
                                   ofProject: mergeRequest project ].
1✔
353

1✔
354
        mergeRequest commits: commits.
1✔
355

1✔
356
        ^ commits
1✔
357
]
1✔
358

359
{ #category : #'import - merge request' }
NEW
360
BitBucketModelImporter >> importMergeRequestMergeCommits: aGLHMergeRequest [
×
NEW
361

×
NEW
362
        aGLHMergeRequest mergedCommit ifNotNil: [
×
NEW
363
                ^ { aGLHMergeRequest mergedCommit } ].
×
NEW
364
        aGLHMergeRequest project repository commits
×
NEW
365
                detect: [ :c |
×
NEW
366
                c parent_ids includes: aGLHMergeRequest commits last id ]
×
NEW
367
                ifFound: [ :found |
×
NEW
368
                        aGLHMergeRequest mergedCommit: found.
×
NEW
369
                        aGLHMergeRequest merge_commit_sha: found id.
×
NEW
370
                        self importMergeRequestStats: aGLHMergeRequest.
×
NEW
371
                        ^ { found } ].
×
NEW
372

×
NEW
373
        self
×
NEW
374
                importCommitsOfProject: aGLHMergeRequest project
×
NEW
375
                since: aGLHMergeRequest created_at
×
NEW
376
                until: aGLHMergeRequest merged_at.
×
NEW
377
        self chainsCommitsFrom: aGLHMergeRequest project repository commits.
×
NEW
378
        aGLHMergeRequest project repository commits
×
NEW
379
                detect: [ :c |
×
NEW
380
                c parent_ids includes: aGLHMergeRequest commits last id ]
×
NEW
381
                ifFound: [ :found |
×
NEW
382
                        aGLHMergeRequest mergedCommit: found.
×
NEW
383
                        aGLHMergeRequest merge_commit_sha: found id.
×
NEW
384
                        self importMergeRequestStats: aGLHMergeRequest.
×
NEW
385
                        ^ { found } ]
×
NEW
386
]
×
387

388
{ #category : #'import - merge request' }
389
BitBucketModelImporter >> importMergeRequestStats: aMergeRequest [
1✔
390

1✔
391
        | commitDiffs contribution |
1✔
392
        "can not recompute diff of mergedcommit if none"
1✔
393
        aMergeRequest mergedCommit ifNil: [ ^ self ].
1✔
394
        (aMergeRequest mergedCommit additions isNotNil and: [
1✔
395
                 aMergeRequest mergedCommit deletions isNotNil and: [
1✔
396
                         aMergeRequest mergedCommit additions ~= 0 or: [
1✔
397
                                 aMergeRequest mergedCommit deletions ~= 0 ] ] ]) ifTrue: [
1✔
398
                ^ self ].
1✔
399

1✔
400
        commitDiffs := self repoApi pullRequests
1✔
401
                               diffOf: aMergeRequest id
1✔
402
                               inRepository: aMergeRequest project id
1✔
403
                               ofProject: aMergeRequest project group id.
1✔
404

1✔
405
        contribution := self getContributionFromDiffs:
1✔
406
                                (commitDiffs at: #diffs).
1✔
407

1✔
408
        ^ aMergeRequest mergedCommit
1✔
409
                  additions: (contribution at: #additions);
1✔
410
                  deletions: (contribution at: #deletions)
1✔
411
]
1✔
412

413
{ #category : #'import - merge-requests' }
414
BitBucketModelImporter >> importMergeRequests: aGLHProject since: fromDate until: toDate [
1✔
415

1✔
416
        | pullRequests params |
1✔
417
        params := { 
1✔
418
                #state -> 'all'
1✔
419
         } asDictionary.
1✔
420
        pullRequests := self repoApi pullRequests allSince: fromDate until: toDate withParams: params  inRepository: aGLHProject id ofProject: aGLHProject group id.
1✔
421

1✔
422
        pullRequests := pullRequests collect: [ :pullRequest |
1✔
423
                                self parsePullRequestIntoGLPHEMergeRequest:
1✔
424
                                        pullRequest ].
1✔
425

1✔
426
        pullRequests := self glhModel
1✔
427
                                addAll: pullRequests
1✔
428
                                unless: self blockOnIdEquality.
1✔
429

1✔
430
        ^ pullRequests
1✔
431
]
1✔
432

433
{ #category : #'import - merge-requests' }
434
BitBucketModelImporter >> importMergeResquestAuthor: mergeRequest [
×
435
        mergeRequest author ifNotNil: [ ^mergeRequest ]
×
436
]
×
437

438
{ #category : #'import - merge-requests' }
439
BitBucketModelImporter >> importMergeResquestMerger: mergeRequest [
1✔
440

1✔
441
        | activities mergeActivity mergeUser |
1✔
442
        mergeRequest merge_user ifNotNil: [ ^ mergeRequest merge_user ].
1✔
443
        mergeRequest state = 'merged' ifFalse: [ ^ nil ].
1✔
444

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

1✔
447
        mergeActivity := activities detect: [ :activity |
1✔
448
                                 (activity at: #action) = 'MERGED' ].
1✔
449

1✔
450
        mergeUser := mergeActivity at: #user.
1✔
451

1✔
452
        mergeUser := (glhModel allWithType: GLHUser)
1✔
453
                             detect: [ :user | user id = (mergeUser at: #id) ]
1✔
454
                             ifFound: [ :user | user ]
1✔
455
                             ifNone: [
1✔
456
                                     | glhUser |
1✔
457
                                     glhUser := self parseUserIntoGLHUser: mergeUser.
1✔
458
                                     glhModel add: glhUser.
1✔
459
                                     glhUser ].
1✔
460

1✔
461
        mergeRequest merge_user: mergeUser.
1✔
462
        ^ mergeUser
1✔
463
]
1✔
464

465
{ #category : #'import - notes' }
NEW
466
BitBucketModelImporter >> importNotesfromMergeRequest: mergeRequest [
×
NEW
467

×
NEW
468
        | results notes |
×
NEW
469
        results := self repoApi pullRequests
×
NEW
470
                           activitiesOf: mergeRequest id
×
NEW
471
                           inRepository: mergeRequest project id
×
NEW
472
                           ofProject: mergeRequest project group id.
×
NEW
473
        notes := results
×
NEW
474
                         select: [ :activity | (activity at: #action) = 'COMMENTED' ]
×
NEW
475
                         thenCollect: [ :commentActivity |
×
NEW
476
                         self extractNoteFromComment: commentActivity ].
×
NEW
477
        "notes := self parseNoteJson: results."
×
NEW
478
        notes do: [ :note |
×
NEW
479
                note author:
×
NEW
480
                        (self importUserByUsername: (note author at: #displayName)).
×
NEW
481
                note name: note id asString ].
×
NEW
482
        notes := notes flattened.
×
NEW
483
        notes := self glhModel addAll: notes unless: self blockOnIdEquality.
×
NEW
484
        notes := mergeRequest note
×
NEW
485
                         addAll: notes
×
NEW
486
                         unless: self blockOnIdEquality.
×
NEW
487
        ^ notes
×
NEW
488
]
×
489

490
{ #category : #'import - projects' }
NEW
491
BitBucketModelImporter >> importProject: aProjectID [
×
NEW
492

×
NEW
493
        Error signal:
×
NEW
494
                'Bitbucket api cannot import directly a project (in the sens of GPH). One need to import a group, then the projects of this group.'
×
NEW
495
]
×
496

497
{ #category : #'import - projects' }
NEW
498
BitBucketModelImporter >> importProject: aProjectID ofGroup: aGroup [
×
NEW
499

×
NEW
500
        | repoOfProject project |
×
NEW
501
        repoOfProject := self repoApi repositories
×
NEW
502
                                 get: aProjectID
×
NEW
503
                                 ofProject: aGroup id.
×
NEW
504
        project := self parseRepoIntoGLHProject: repoOfProject.
×
NEW
505
        self glhModel add: project.
×
NEW
506
        ^ project
×
NEW
507
]
×
508

509
{ #category : #'import - users' }
510
BitBucketModelImporter >> importUserByUsername: username [
1✔
511

1✔
512
        ^ self userCatalogue collectUsernames at: username ifAbsent: [
1✔
513
                  | users glhUser user params|
1✔
514
                  params := { #filter -> username } asDictionary. 
1✔
515
                  users := self repoApi users allWithParams: params.
1✔
516
                  users ifEmpty: [ ^ nil ].
1✔
517
                  user := users first.
1✔
518

1✔
519
                  glhUser := self parseUserIntoGLHUser: user.
1✔
520
                  self glhModel add: glhUser unless: self blockOnIdEquality.
1✔
521
                  self userCatalogue addUser: glhUser withName: username.
1✔
522
                  glhUser ]
1✔
523
]
1✔
524

525
{ #category : #parsing }
526
BitBucketModelImporter >> parseCommitIntoGLHCommit: commitDictionary ofProject: aGLHProject [
1✔
527

1✔
528
        | author committer parentIds commitDiffs contribution |
1✔
529
        author := commitDictionary at: #author.
1✔
530
        committer := commitDictionary at: #committer.
1✔
531

1✔
532
        parentIds := (commitDictionary at: #parents) collect: [ :parent |
1✔
533
                             parent at: #id ].
1✔
534

1✔
535
        commitDiffs := self repoApi commits
1✔
536
                               diffOf: (commitDictionary at: #id)
1✔
537
                               inRepository: aGLHProject id
1✔
538
                               ofProject: aGLHProject group id.
1✔
539

1✔
540
        contribution := self getContributionFromDiffs:
1✔
541
                                (commitDiffs at: #diffs).
1✔
542

1✔
543
        ^ GLHCommit new
1✔
544
                  id: (commitDictionary at: #id);
1✔
545
                  message: (commitDictionary at: #message);
1✔
546
                  title: (commitDictionary at: #message) lines first;
1✔
547
                  author_email: (author at: #emailAddress);
1✔
548
                  author_name: (author at: #name);
1✔
549
                  authored_date: (DateAndTime fromUnixTime:
1✔
550
                                           (commitDictionary at: #authorTimestamp) / 1000);
1✔
551
                  created_at: (DateAndTime fromUnixTime:
1✔
552
                                           (commitDictionary at: #authorTimestamp) / 1000);
1✔
553
                  committed_date: (DateAndTime fromUnixTime:
1✔
554
                                           (commitDictionary at: #committerTimestamp) / 1000);
1✔
555
                  committer_email: (committer at: #emailAddress);
1✔
556
                  committer_name: (committer at: #name);
1✔
557
                  parent_ids: parentIds;
1✔
558
                  additions: (contribution at: #additions);
1✔
559
                  deletions: (contribution at: #deletions)
1✔
560
]
1✔
561

562
{ #category : #parsing }
563
BitBucketModelImporter >> parseGroupResult: aDictionary [
1✔
564

1✔
565
        ^ GLHGroup new
1✔
566
                  id: (aDictionary at: #key);
1✔
567
                  "use key instead of id because key is use everywhere else for API"
1✔
568
                  description: (aDictionary at: #description);
1✔
569
                  name: (aDictionary at: #name);
1✔
570
                  web_url: ((aDictionary at: #links at: #self) anyOne at: #href);
1✔
571
                  yourself
1✔
572
]
1✔
573

574
{ #category : #parsing }
575
BitBucketModelImporter >> parseProjectIntoGLHGroup: projectRepository [
1✔
576

1✔
577
        ^ GLHGroup new
1✔
578
                  name: (projectRepository at: #name);
1✔
579
                  id: (projectRepository at: #key);
1✔
580
                  description: (projectRepository at: #description)
1✔
581
]
1✔
582

583
{ #category : #parsing }
584
BitBucketModelImporter >> parsePullRequestIntoGLPHEMergeRequest: pullRequestDictionary [
1✔
585

1✔
586
        | repository project toRef fromRef glpheMergeRequest author state reviewers |
1✔
587
        toRef := pullRequestDictionary at: #toRef.
1✔
588
        fromRef := pullRequestDictionary at: #fromRef.
1✔
589

1✔
590
        reviewers := pullRequestDictionary at: #reviewers.
1✔
591
        reviewers := reviewers collect: [ :reviewer |
1✔
592
                             | reviewerUser |
1✔
593
                             reviewerUser := reviewer at: #user.
1✔
594
                             (self glhModel allWithType: GLHUser)
1✔
595
                                     detect: [ :user | user id = (reviewerUser at: #id) ]
1✔
596
                                     ifFound: [ :user | user ]
1✔
597
                                     ifNone: [
1✔
598
                                             | glhUser |
1✔
599
                                             glhUser := self parseUserIntoGLHUser: reviewerUser.
1✔
600
                                             glhModel add: glhUser.
1✔
601
                                             glhUser ] ].
1✔
602

1✔
603
        repository := toRef at: #repository.
1✔
604
        project := (self glhModel allWithType: GLHProject)
1✔
605
                           detect: [ :glhProject |
1✔
606
                           glhProject id = (repository at: #slug) ]
1✔
607
                           ifFound: [ :glhProject | glhProject ]
1✔
608
                           ifNone: [
1✔
609
                                   project := self parseRepoIntoGLHProject: repository.
1✔
610
                                   self glhModel add: project.
1✔
611
                                   project ].
1✔
612

1✔
613

1✔
614
        author := pullRequestDictionary at: #author.
1✔
615
        author := (self glhModel allWithType: GLHUser)
1✔
616
                          detect: [ :user | user id = ((author at: #user) at: #id) ]
1✔
617
                          ifFound: [ :user | user ]
1✔
618
                          ifNone: [
1✔
619
                          self importUserByUsername:
1✔
620
                                  ((author at: #user) at: #displayName) ].
1✔
621

1✔
622

1✔
623
        glpheMergeRequest := GLHMergeRequest new
1✔
624
                                     name: (pullRequestDictionary at: #title);
1✔
625
                                     title: (pullRequestDictionary at: #title);
1✔
626
                                     id: (pullRequestDictionary at: #id);
1✔
627
                                     project: project;
1✔
628
                                     project_id: project id;
1✔
629
                                     target_branch: (toRef at: #id);
1✔
630
                                     target_project_id:
1✔
631
                                             ((toRef at: #repository) at: #id);
1✔
632
                                     source_branch: (fromRef at: #id);
1✔
633
                                     source_project_id:
1✔
634
                                             ((fromRef at: #repository) at: #id);
1✔
635
                                     updated_at: (DateAndTime fromUnixTime:
1✔
636
                                                              (pullRequestDictionary at: #updatedDate)
1✔
637
                                                              / 1000);
1✔
638
                                     created_at: (DateAndTime fromUnixTime:
1✔
639
                                                              (pullRequestDictionary at: #createdDate)
1✔
640
                                                              / 1000);
1✔
641
                                     author: author.
1✔
642

1✔
643
        "STATE"
1✔
644
        state := pullRequestDictionary at: #state.
1✔
645
        state = 'OPEN' ifTrue: [ glpheMergeRequest state: 'opened' ].
1✔
646
        state = 'MERGED' ifTrue: [
1✔
647
                glpheMergeRequest state: 'merged'.
1✔
648
                glpheMergeRequest merged_at: (DateAndTime fromUnixTime:
1✔
649
                                 (pullRequestDictionary at: #closedDate) / 1000) ].
1✔
650

1✔
651
        state = 'DECLINED' ifTrue: [
1✔
652
                glpheMergeRequest state: 'closed'.
1✔
653
                glpheMergeRequest closed_at: (DateAndTime fromUnixTime:
1✔
654
                                 (pullRequestDictionary at: #closedDate) / 1000) ].
1✔
655

1✔
656
        ^ glpheMergeRequest
1✔
657
]
1✔
658

659
{ #category : #parsing }
660
BitBucketModelImporter >> parseRepoIntoGLHProject: repositoryDictionary [
1✔
661

1✔
662
        | project group glhProject |
1✔
663
        project := repositoryDictionary at: #project.
1✔
664

1✔
665
        group := (self glhModel allWithType: GLHGroup)
1✔
666
                         detect: [ :glhGroup | glhGroup id = (project at: #key) ]
1✔
667
                         ifFound: [ :glhGroup | glhGroup ]
1✔
668
                         ifNone: [
1✔
669
                                 | newGroup |
1✔
670
                                 newGroup := self parseProjectIntoGLHGroup: project.
1✔
671
                                 glhModel add: newGroup.
1✔
672
                                 newGroup ].
1✔
673

1✔
674

1✔
675
        glhProject := GLHProject new
1✔
676
                              name: (repositoryDictionary at: #name);
1✔
677
                              id: (repositoryDictionary at: #slug);
1✔
678
                              repository: GLHRepository new;
1✔
679
                              group: group.
1✔
680

1✔
681
        group addProject: glhProject.
1✔
682

1✔
683
        ^ glhProject
1✔
684
]
1✔
685

686
{ #category : #parsing }
687
BitBucketModelImporter >> parseUserIntoGLHUser: userDictionnary [
1✔
688

1✔
689
        ^ GLHUser new
1✔
690
                  name: (userDictionnary at: #displayName);
1✔
691
                  public_email: (userDictionnary at: #emailAddress ifAbsent: [ nil ]);
1✔
692
                  id: (userDictionnary at: #id);
1✔
693
                  username: (userDictionnary at: #name)
1✔
694
]
1✔
695

696
{ #category : #accessing }
697
BitBucketModelImporter >> withInitialCommits [
×
698

×
699
        ^ withInitialCommits
×
700
]
×
701

702
{ #category : #accessing }
703
BitBucketModelImporter >> withInitialCommits: anObject [
×
704

×
705
        withInitialCommits := anObject
×
706
]
×
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