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

moosetechnology / GitProjectHealth / 11142394560

02 Oct 2024 10:45AM UTC coverage: 58.906% (+5.6%) from 53.297%
11142394560

Pull #74

github

web-flow
Merge 49e8023a1 into 0c3ed6880
Pull Request #74: feat: bitbucket importer

1940 of 2213 new or added lines in 12 files covered. (87.66%)

14 existing lines in 1 file now uncovered.

8903 of 15114 relevant lines covered (58.91%)

0.59 hits per line

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

0.0
/src/BitBucketHealth-Model-Importer/BitBucketApi.class.st
1
Class {
2
        #name : #BitBucketApi,
3
        #superclass : #Object,
4
        #instVars : [
5
                'endpoint',
6
                'basePath',
7
                'client',
8
                'bearerToken',
9
                'apiToken',
10
                'username'
11
        ],
12
        #category : #'BitBucketHealth-Model-Importer'
13
}
14

15
{ #category : #'api - pull-requests' }
NEW
16
BitBucketApi >> activitiesOfPullRequest: pullRequestId inRepo: repositorySlug ofProject: projectKey [
×
NEW
17

×
NEW
18
        ^ self allValuesOfPath:
×
NEW
19
                  self basePath , '/projects/' , projectKey , '/repos/'
×
NEW
20
                  , repositorySlug , '/pull-requests/' , pullRequestId printString
×
NEW
21
                  , '/activities'
×
NEW
22
]
×
23

24
{ #category : #'private - building' }
NEW
25
BitBucketApi >> allValuesOfPath: path [
×
NEW
26

×
NEW
27
        | results values |
×
NEW
28
        self prepareZnClient.
×
NEW
29
        self client path: path.
×
NEW
30
        values := OrderedCollection new.
×
NEW
31

×
NEW
32
        [
×
NEW
33
        results := self client get.
×
NEW
34
        results := (NeoJSONReader on: results readStream) next.
×
NEW
35
        values addAll: (results at: #values).
×
NEW
36
        results
×
NEW
37
                at: #nextPageStart
×
NEW
38
                ifPresent: [
×
NEW
39
                client queryAt: #start put: (results at: #nextPageStart) ].
×
NEW
40
        results at: #isLastPage ] whileFalse.
×
NEW
41

×
NEW
42
        ^ values
×
NEW
43
]
×
44

45
{ #category : #accessing }
NEW
46
BitBucketApi >> apiToken [
×
NEW
47

×
NEW
48
        ^ apiToken
×
NEW
49
]
×
50

51
{ #category : #accessing }
NEW
52
BitBucketApi >> apiToken: anObject [
×
NEW
53

×
NEW
54
        apiToken := anObject
×
NEW
55
]
×
56

57
{ #category : #accessing }
NEW
58
BitBucketApi >> basePath [
×
NEW
59

×
NEW
60
        ^ basePath
×
NEW
61
]
×
62

63
{ #category : #accessing }
NEW
64
BitBucketApi >> basePath: anObject [
×
NEW
65

×
NEW
66
        basePath := anObject
×
NEW
67
]
×
68

69
{ #category : #accessing }
NEW
70
BitBucketApi >> bearerToken [
×
NEW
71

×
NEW
72
        ^ bearerToken
×
NEW
73
]
×
74

75
{ #category : #accessing }
NEW
76
BitBucketApi >> bearerToken: anObject [
×
NEW
77

×
NEW
78
        bearerToken := anObject
×
NEW
79
]
×
80

81
{ #category : #accessing }
NEW
82
BitBucketApi >> client [
×
NEW
83

×
NEW
84
        ^ client
×
NEW
85
]
×
86

87
{ #category : #accessing }
NEW
88
BitBucketApi >> client: anObject [
×
NEW
89

×
NEW
90
        client := anObject
×
NEW
91
]
×
92

93
{ #category : #'api - pull-requests' }
NEW
94
BitBucketApi >> commitsOfPullRequest: pullRequestId ofRepo: repoSlug inProject: projectKey [
×
NEW
95
        ^ self allValuesOfPath: self basePath, '/projects/', projectKey, '/repos/', repoSlug, '/pull-requests/', pullRequestId printString, '/commits'.
×
NEW
96
        
×
NEW
97
]
×
98

99
{ #category : #'api - commits' }
NEW
100
BitBucketApi >> commitsOfRepo: repositorySlug inProject: projectKey since: since until: until [
×
NEW
101
        "/rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/commits"
×
NEW
102

×
NEW
103
        | results lastDate lastCommitterTimestamp commits |
×
NEW
104
        self prepareZnClient.
×
NEW
105
        self client path:
×
NEW
106
                self basePath , '/projects/' , projectKey , '/repos/'
×
NEW
107
                , repositorySlug , '/commits'.
×
NEW
108
        self client queryAt: 'merges' put: 'exclude'.
×
NEW
109

×
NEW
110
        commits := OrderedCollection new.
×
NEW
111

×
NEW
112
        [
×
NEW
113
        results := self client get.
×
NEW
114
        results := (NeoJSONReader on: results readStream) next.
×
NEW
115
        commits addAll: (results at: #values).
×
NEW
116
        results
×
NEW
117
                at: #nextPageStart
×
NEW
118
                ifPresent: [
×
NEW
119
                client queryAt: #start put: (results at: #nextPageStart) ].
×
NEW
120

×
NEW
121
        (results at: #isLastPage)
×
NEW
122
                ifTrue: [ false ]
×
NEW
123
                ifFalse: [
×
NEW
124
                        lastCommitterTimestamp := commits last at: #authorTimestamp.
×
NEW
125
                        lastDate := DateAndTime fromUnixTime: lastCommitterTimestamp / 1000.
×
NEW
126
                        since asDate <= lastDate ] ] whileTrue.
×
NEW
127

×
NEW
128
        ^ commits select: [ :commit |
×
NEW
129
                  | commitDate |
×
NEW
130
                  commitDate := DateAndTime fromUnixTime:
×
NEW
131
                                        (commit at: #authorTimestamp) / 1000.
×
NEW
132
                  commitDate >= since asDateAndTime and:
×
NEW
133
                          commitDate <= until asDateAndTime ]
×
NEW
134
]
×
135

136
{ #category : #'api - commits' }
NEW
137
BitBucketApi >> diffsOfCommit: commitID inRepo: repositorySlug inProject: projectKey [
×
NEW
138

×
NEW
139
        | results |
×
NEW
140
        self prepareZnClient.
×
NEW
141

×
NEW
142
        self client path:
×
NEW
143
                self basePath , '/projects/' , projectKey , '/repos/'
×
NEW
144
                , repositorySlug , '/commits/' , commitID , '/diff'.
×
NEW
145

×
NEW
146
        results := self client get.
×
NEW
147

×
NEW
148
        ^ (NeoJSONReader on: results readStream) next
×
NEW
149
]
×
150

151
{ #category : #accessing }
NEW
152
BitBucketApi >> endpoint [
×
NEW
153

×
NEW
154
        ^ endpoint
×
NEW
155
]
×
156

157
{ #category : #accessing }
NEW
158
BitBucketApi >> endpoint: anObject [
×
NEW
159

×
NEW
160
        endpoint := anObject
×
NEW
161
]
×
162

163
{ #category : #initialization }
NEW
164
BitBucketApi >> initialize [
×
NEW
165

×
NEW
166
        self client: (ZnClient new
×
NEW
167
                         accept: ZnMimeType applicationJson;
×
NEW
168
                         yourself).
×
NEW
169
                        
×
NEW
170
        self basePath: 'rest/api/1.0'
×
NEW
171
]
×
172

173
{ #category : #'private - building' }
NEW
174
BitBucketApi >> prepareZnClient [
×
NEW
175

×
NEW
176
        client := ZnClient new
×
NEW
177
                          accept: ZnMimeType applicationJson;
×
NEW
178
                          yourself.
×
NEW
179

×
NEW
180
        client host: self endpoint.
×
NEW
181
        client http.
×
NEW
182

×
NEW
183
        self bearerToken ifNotNil: [ :token |
×
NEW
184
                client headerAt: #Authorization put: 'Bearer ' , token ].
×
NEW
185
        self apiToken ifNotNil: [ :anApiKey |
×
NEW
186
                client headerAt: #Authorization put: 'Basic '
×
NEW
187
                        , (self username , ':' , self apiToken) utf8Encoded base64Encoded ].
×
NEW
188
]
×
189

190
{ #category : #'api - projects' }
NEW
191
BitBucketApi >> projects [
×
NEW
192
        "/rest/api/1.0/projects"
×
NEW
193

×
NEW
194
        ^ self allValuesOfPath: self basePath , '/projects'.
×
NEW
195
]
×
196

197
{ #category : #'api - pull-requests' }
NEW
198
BitBucketApi >> pullRequestsOfRepo: repositorySlug inProject: projectKey since: since until: until [
×
NEW
199

×
NEW
200
        | pullRequests results lastCommitterTimestamp lastDate |
×
NEW
201
        self prepareZnClient.
×
NEW
202
        self client path:
×
NEW
203
                self basePath , '/projects/' , projectKey , '/repos/'
×
NEW
204
                , repositorySlug , '/pull-requests'.
×
NEW
205

×
NEW
206
        self client queryAt: 'state' put: 'all'.
×
NEW
207

×
NEW
208
        pullRequests := OrderedCollection new.
×
NEW
209

×
NEW
210
        [
×
NEW
211
        results := self client get.
×
NEW
212
        results := (NeoJSONReader on: results readStream) next.
×
NEW
213
        pullRequests addAll: (results at: #values).
×
NEW
214
        results
×
NEW
215
                at: #nextPageStart
×
NEW
216
                ifPresent: [
×
NEW
217
                client queryAt: #start put: (results at: #nextPageStart) ].
×
NEW
218

×
NEW
219
        (results at: #isLastPage)
×
NEW
220
                ifTrue: [ false ]
×
NEW
221
                ifFalse: [
×
NEW
222
                        lastCommitterTimestamp := pullRequests last at: #createdDate.
×
NEW
223
                        lastDate := DateAndTime fromUnixTime: lastCommitterTimestamp / 1000.
×
NEW
224
                        since asDate <= lastDate ] ] whileTrue.
×
NEW
225

×
NEW
226
        ^ pullRequests select: [ :commit |
×
NEW
227
                  | commitDate |
×
NEW
228
                  commitDate := DateAndTime fromUnixTime:
×
NEW
229
                                        (commit at: #createdDate) / 1000.
×
NEW
230
                  commitDate >= since asDate and: commitDate <= until asDate ]
×
NEW
231
]
×
232

233
{ #category : #'api - projects' }
NEW
234
BitBucketApi >> repositoriesOfProject: projectKey [
×
NEW
235
        ^self allValuesOfPath: self basePath, '/projects/', projectKey, '/repos'.
×
NEW
236
]
×
237

238
{ #category : #'api - user' }
NEW
239
BitBucketApi >> user: accountId [
×
NEW
240
        "https://developer.atlassian.com/cloud/bitbucket/rest/api-group-users/#api-user-get"
×
NEW
241

×
NEW
242
        self prepareZnClient.
×
NEW
243
        
×
NEW
244
        self client path: self basePath, '/user/' , accountId printString.
×
NEW
245
        ^ self client get
×
NEW
246
]
×
247

248
{ #category : #accessing }
NEW
249
BitBucketApi >> username [
×
NEW
250

×
NEW
251
        ^ username
×
NEW
252
]
×
253

254
{ #category : #accessing }
NEW
255
BitBucketApi >> username: anObject [
×
NEW
256

×
NEW
257
        username := anObject
×
NEW
258
]
×
259

260
{ #category : #'api - user' }
NEW
261
BitBucketApi >> usersByUsername: usernameString [
×
NEW
262

×
NEW
263
        | users |
×
NEW
264
        self prepareZnClient.
×
NEW
265
        self client path: self basePath , '/admin/users'.
×
NEW
266
        self client queryAt: 'filter' put: usernameString.
×
NEW
267

×
NEW
268
        users := self client get.
×
NEW
269
        users := (NeoJSONReader on: users readStream) next.
×
NEW
270

×
NEW
271
        ^ (users at: #values)
×
NEW
272
]
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc