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

moosetechnology / GitProjectHealth / 14404766613

11 Apr 2025 01:54PM UTC coverage: 72.997% (+0.5%) from 72.511%
14404766613

Pull #186

github

web-flow
Merge pull request #191 from moosetechnology/badetitou-patch-1

autoreneraku v1.0.10
Pull Request #186: Develop

195 of 300 new or added lines in 9 files covered. (65.0%)

10 existing lines in 1 file now uncovered.

15693 of 21498 relevant lines covered (73.0%)

0.73 hits per line

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

79.9
/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 commitsOf: mergeRequest id inRepository: mergeRequest project id ofProject: mergeRequest project group id.
1✔
345

1✔
346
        commits := commits collect: [ :commit |
1✔
347
                           self
1✔
348
                                   parseCommitIntoGLHCommit: commit
1✔
349
                                   ofProject: mergeRequest project ].
1✔
350

1✔
351
        mergeRequest commits: commits.
1✔
352

1✔
353
        ^ commits
1✔
354
]
1✔
355

356
{ #category : #'import - merge request' }
NEW
357
BitBucketModelImporter >> importMergeRequestMergeCommits: aGLHMergeRequest [
×
NEW
358

×
NEW
359
        aGLHMergeRequest mergedCommit ifNotNil: [
×
NEW
360
                ^ { aGLHMergeRequest mergedCommit } ].
×
NEW
361

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

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

384
{ #category : #'import - merge-requests' }
385
BitBucketModelImporter >> importMergeRequests: aGLHProject since: fromDate until: toDate [
1✔
386

1✔
387
        | pullRequests params |
1✔
388
        params := { 
1✔
389
                #state -> 'all'
1✔
390
         } asDictionary.
1✔
391
        pullRequests := self repoApi pullRequests allSince: fromDate until: toDate withParams: params  inRepository: aGLHProject id ofProject: aGLHProject group id.
1✔
392

1✔
393
        pullRequests := pullRequests collect: [ :pullRequest |
1✔
394
                                self parsePullRequestIntoGLPHEMergeRequest:
1✔
395
                                        pullRequest ].
1✔
396

1✔
397
        pullRequests := self glhModel
1✔
398
                                addAll: pullRequests
1✔
399
                                unless: self blockOnIdEquality.
1✔
400

1✔
401
        ^ pullRequests
1✔
402
]
1✔
403

404
{ #category : #'import - merge-requests' }
405
BitBucketModelImporter >> importMergeResquestAuthor: mergeRequest [
×
406
        mergeRequest author ifNotNil: [ ^mergeRequest ]
×
407
]
×
408

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

1✔
412
        | activities mergeActivity mergeUser |
1✔
413
        mergeRequest merge_user ifNotNil: [ ^ mergeRequest merge_user ].
1✔
414
        mergeRequest state = 'merged' ifFalse: [ ^ nil ].
1✔
415

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

1✔
418
        mergeActivity := activities detect: [ :activity |
1✔
419
                                 (activity at: #action) = 'MERGED' ].
1✔
420

1✔
421
        mergeUser := mergeActivity at: #user.
1✔
422

1✔
423
        mergeUser := (glhModel allWithType: GLHUser)
1✔
424
                             detect: [ :user | user id = (mergeUser at: #id) ]
1✔
425
                             ifFound: [ :user | user ]
1✔
426
                             ifNone: [
1✔
427
                                     | glhUser |
1✔
428
                                     glhUser := self parseUserIntoGLHUser: mergeUser.
1✔
429
                                     glhModel add: glhUser.
1✔
430
                                     glhUser ].
1✔
431

1✔
432
        mergeRequest merge_user: mergeUser.
1✔
433
        ^ mergeUser
1✔
434
]
1✔
435

436
{ #category : #'import - notes' }
NEW
437
BitBucketModelImporter >> importNotesfromMergeRequest: mergeRequest [
×
NEW
438

×
NEW
439
        | results notes |
×
NEW
440
        results := self repoApi pullRequests
×
NEW
441
                           activitiesOf: mergeRequest id
×
NEW
442
                           inRepository: mergeRequest project id
×
NEW
443
                           ofProject: mergeRequest project group id.
×
NEW
444
        notes := results
×
NEW
445
                         select: [ :activity | (activity at: #action) = 'COMMENTED' ]
×
NEW
446
                         thenCollect: [ :commentActivity |
×
NEW
447
                         self extractNoteFromComment: commentActivity ].
×
NEW
448
        "notes := self parseNoteJson: results."
×
NEW
449
        notes do: [ :note |
×
NEW
450
                note author:
×
NEW
451
                        (self importUserByUsername: (note author at: #displayName)).
×
NEW
452
                note name: note id asString ].
×
NEW
453
        notes := notes flattened.
×
NEW
454
        notes := self glhModel addAll: notes unless: self blockOnIdEquality.
×
NEW
455
        notes := mergeRequest note
×
NEW
456
                         addAll: notes
×
NEW
457
                         unless: self blockOnIdEquality.
×
NEW
458
        ^ notes
×
NEW
459
]
×
460

461
{ #category : #'import - projects' }
NEW
462
BitBucketModelImporter >> importProject: aProjectID [
×
NEW
463

×
NEW
464
        Error signal:
×
NEW
465
                '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
466
]
×
467

468
{ #category : #'import - projects' }
NEW
469
BitBucketModelImporter >> importProject: aProjectID ofGroup: aGroup [
×
NEW
470

×
NEW
471
        | repoOfProject project |
×
NEW
472
        repoOfProject := self repoApi repositories
×
NEW
473
                                 get: aProjectID
×
NEW
474
                                 ofProject: aGroup id.
×
NEW
475
        project := self parseRepoIntoGLHProject: repoOfProject.
×
NEW
476
        self glhModel add: project.
×
NEW
477
        ^ project
×
NEW
478
]
×
479

480
{ #category : #'import - users' }
481
BitBucketModelImporter >> importUserByUsername: username [
1✔
482

1✔
483
        ^ self userCatalogue collectUsernames at: username ifAbsent: [
1✔
484
                  | users glhUser user params|
1✔
485
                  params := { #filter -> username } asDictionary. 
1✔
486
                  users := self repoApi users allWithParams: params.
1✔
487
                  users ifEmpty: [ ^ nil ].
1✔
488
                  user := users first.
1✔
489

1✔
490
                  glhUser := self parseUserIntoGLHUser: user.
1✔
491
                  self glhModel add: glhUser unless: self blockOnIdEquality.
1✔
492
                  self userCatalogue addUser: glhUser withName: username.
1✔
493
                  glhUser ]
1✔
494
]
1✔
495

496
{ #category : #parsing }
497
BitBucketModelImporter >> parseCommitIntoGLHCommit: commitDictionary ofProject: aGLHProject [
1✔
498

1✔
499
        | author committer parentIds commitDiffs contribution |
1✔
500
        author := commitDictionary at: #author.
1✔
501
        committer := commitDictionary at: #committer.
1✔
502

1✔
503
        parentIds := (commitDictionary at: #parents) collect: [ :parent |
1✔
504
                             parent at: #id ].
1✔
505

1✔
506
        commitDiffs := self repoApi commits
1✔
507
                               diffOf: (commitDictionary at: #id)
1✔
508
                               inRepository: aGLHProject id
1✔
509
                               ofProject: aGLHProject group id.
1✔
510

1✔
511
        contribution := self getContributionFromDiffs:
1✔
512
                                (commitDiffs at: #diffs).
1✔
513

1✔
514
        ^ GLHCommit new
1✔
515
                  id: (commitDictionary at: #id);
1✔
516
                  message: (commitDictionary at: #message);
1✔
517
                  title: (commitDictionary at: #message) lines first;
1✔
518
                  author_email: (author at: #emailAddress);
1✔
519
                  author_name: (author at: #name);
1✔
520
                  authored_date: (DateAndTime fromUnixTime:
1✔
521
                                           (commitDictionary at: #authorTimestamp) / 1000);
1✔
522
                  created_at: (DateAndTime fromUnixTime:
1✔
523
                                           (commitDictionary at: #authorTimestamp) / 1000);
1✔
524
                  committed_date: (DateAndTime fromUnixTime:
1✔
525
                                           (commitDictionary at: #committerTimestamp) / 1000);
1✔
526
                  committer_email: (committer at: #emailAddress);
1✔
527
                  committer_name: (committer at: #name);
1✔
528
                  parent_ids: parentIds;
1✔
529
                  additions: (contribution at: #additions);
1✔
530
                  deletions: (contribution at: #deletions)
1✔
531
]
1✔
532

533
{ #category : #parsing }
534
BitBucketModelImporter >> parseGroupResult: aDictionary [
1✔
535

1✔
536
        ^ GLHGroup new
1✔
537
                  id: (aDictionary at: #key);
1✔
538
                  "use key instead of id because key is use everywhere else for API"
1✔
539
                  description: (aDictionary at: #description);
1✔
540
                  name: (aDictionary at: #name);
1✔
541
                  web_url: ((aDictionary at: #links at: #self) anyOne at: #href);
1✔
542
                  yourself
1✔
543
]
1✔
544

545
{ #category : #parsing }
546
BitBucketModelImporter >> parseProjectIntoGLHGroup: projectRepository [
1✔
547

1✔
548
        ^ GLHGroup new
1✔
549
                  name: (projectRepository at: #name);
1✔
550
                  id: (projectRepository at: #key);
1✔
551
                  description: (projectRepository at: #description)
1✔
552
]
1✔
553

554
{ #category : #parsing }
555
BitBucketModelImporter >> parsePullRequestIntoGLPHEMergeRequest: pullRequestDictionary [
1✔
556

1✔
557
        | repository project toRef fromRef glpheMergeRequest author state reviewers |
1✔
558
        toRef := pullRequestDictionary at: #toRef.
1✔
559
        fromRef := pullRequestDictionary at: #fromRef.
1✔
560

1✔
561
        reviewers := pullRequestDictionary at: #reviewers.
1✔
562
        reviewers := reviewers collect: [ :reviewer |
1✔
563
                             | reviewerUser |
1✔
564
                             reviewerUser := reviewer at: #user.
1✔
565
                             (self glhModel allWithType: GLHUser)
1✔
566
                                     detect: [ :user | user id = (reviewerUser at: #id) ]
1✔
567
                                     ifFound: [ :user | user ]
1✔
568
                                     ifNone: [
1✔
569
                                             | glhUser |
1✔
570
                                             glhUser := self parseUserIntoGLHUser: reviewerUser.
1✔
571
                                             glhModel add: glhUser.
1✔
572
                                             glhUser ] ].
1✔
573

1✔
574
        repository := toRef at: #repository.
1✔
575
        project := (self glhModel allWithType: GLHProject)
1✔
576
                           detect: [ :glhProject |
1✔
577
                           glhProject id = (repository at: #slug) ]
1✔
578
                           ifFound: [ :glhProject | glhProject ]
1✔
579
                           ifNone: [
1✔
580
                                   project := self parseRepoIntoGLHProject: repository.
1✔
581
                                   self glhModel add: project.
1✔
582
                                   project ].
1✔
583

1✔
584

1✔
585
        author := pullRequestDictionary at: #author.
1✔
586
        author := (self glhModel allWithType: GLHUser)
1✔
587
                          detect: [ :user | user id = ((author at: #user) at: #id) ]
1✔
588
                          ifFound: [ :user | user ]
1✔
589
                          ifNone: [
1✔
590
                          self importUserByUsername:
1✔
591
                                  ((author at: #user) at: #displayName) ].
1✔
592

1✔
593

1✔
594
        glpheMergeRequest := GLHMergeRequest new
1✔
595
                                     name: (pullRequestDictionary at: #title);
1✔
596
                                     title: (pullRequestDictionary at: #title);
1✔
597
                                     id: (pullRequestDictionary at: #id);
1✔
598
                                     project: project;
1✔
599
                                     project_id: project id;
1✔
600
                                     target_branch: (toRef at: #id);
1✔
601
                                     target_project_id:
1✔
602
                                             ((toRef at: #repository) at: #id);
1✔
603
                                     source_branch: (fromRef at: #id);
1✔
604
                                     source_project_id:
1✔
605
                                             ((fromRef at: #repository) at: #id);
1✔
606
                                     updated_at: (DateAndTime fromUnixTime:
1✔
607
                                                              (pullRequestDictionary at: #updatedDate)
1✔
608
                                                              / 1000);
1✔
609
                                     created_at: (DateAndTime fromUnixTime:
1✔
610
                                                              (pullRequestDictionary at: #createdDate)
1✔
611
                                                              / 1000);
1✔
612
                                     author: author.
1✔
613

1✔
614
        "STATE"
1✔
615
        state := pullRequestDictionary at: #state.
1✔
616
        state = 'OPEN' ifTrue: [ glpheMergeRequest state: 'opened' ].
1✔
617
        state = 'MERGED' ifTrue: [
1✔
618
                glpheMergeRequest state: 'merged'.
1✔
619
                glpheMergeRequest merged_at: (DateAndTime fromUnixTime:
1✔
620
                                 (pullRequestDictionary at: #closedDate) / 1000) ].
1✔
621

1✔
622
        state = 'DECLINED' ifTrue: [
1✔
623
                glpheMergeRequest state: 'closed'.
1✔
624
                glpheMergeRequest closed_at: (DateAndTime fromUnixTime:
1✔
625
                                 (pullRequestDictionary at: #closedDate) / 1000) ].
1✔
626

1✔
627
        ^ glpheMergeRequest
1✔
628
]
1✔
629

630
{ #category : #parsing }
631
BitBucketModelImporter >> parseRepoIntoGLHProject: repositoryDictionary [
1✔
632

1✔
633
        | project group glhProject |
1✔
634
        project := repositoryDictionary at: #project.
1✔
635

1✔
636
        group := (self glhModel allWithType: GLHGroup)
1✔
637
                         detect: [ :glhGroup | glhGroup id = (project at: #key) ]
1✔
638
                         ifFound: [ :glhGroup | glhGroup ]
1✔
639
                         ifNone: [
1✔
640
                                 | newGroup |
1✔
641
                                 newGroup := self parseProjectIntoGLHGroup: project.
1✔
642
                                 glhModel add: newGroup.
1✔
643
                                 newGroup ].
1✔
644

1✔
645

1✔
646
        glhProject := GLHProject new
1✔
647
                              name: (repositoryDictionary at: #name);
1✔
648
                              id: (repositoryDictionary at: #slug);
1✔
649
                              repository: GLHRepository new;
1✔
650
                              group: group.
1✔
651

1✔
652
        group addProject: glhProject.
1✔
653

1✔
654
        ^ glhProject
1✔
655
]
1✔
656

657
{ #category : #parsing }
658
BitBucketModelImporter >> parseUserIntoGLHUser: userDictionnary [
1✔
659

1✔
660
        ^ GLHUser new
1✔
661
                  name: (userDictionnary at: #displayName);
1✔
662
                  public_email: (userDictionnary at: #emailAddress ifAbsent: [ nil ]);
1✔
663
                  id: (userDictionnary at: #id);
1✔
664
                  username: (userDictionnary at: #name)
1✔
665
]
1✔
666

667
{ #category : #accessing }
668
BitBucketModelImporter >> withInitialCommits [
×
669

×
670
        ^ withInitialCommits
×
671
]
×
672

673
{ #category : #accessing }
674
BitBucketModelImporter >> withInitialCommits: anObject [
×
675

×
676
        withInitialCommits := anObject
×
677
]
×
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