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

moosetechnology / GitProjectHealth / 11498155021

24 Oct 2024 11:15AM UTC coverage: 59.724% (+0.8%) from 58.906%
11498155021

push

github

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

Develop

713 of 970 new or added lines in 22 files covered. (73.51%)

15 existing lines in 5 files now uncovered.

9449 of 15821 relevant lines covered (59.72%)

0.6 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 inRepoProjectId: repositorySlug ofProjectGroupId: projectKey [
×
17

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

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

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

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

×
42
        ^ values
×
43
]
×
44

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

×
48
        ^ apiToken
×
49
]
×
50

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

×
54
        apiToken := anObject
×
55
]
×
56

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

×
60
        ^ basePath
×
61
]
×
62

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

×
66
        basePath := anObject
×
67
]
×
68

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

×
72
        ^ bearerToken
×
73
]
×
74

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

×
78
        bearerToken := anObject
×
79
]
×
80

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

×
84
        ^ client
×
85
]
×
86

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

×
90
        client := anObject
×
91
]
×
92

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

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

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

×
110
        commits := OrderedCollection new.
×
111

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

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

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

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

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

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

×
146
        results := self client get.
×
147

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

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

×
154
        ^ endpoint
×
155
]
×
156

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

×
160
        endpoint := anObject
×
161
]
×
162

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

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

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

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

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

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

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

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

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

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

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

×
208
        pullRequests := OrderedCollection new.
×
209

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

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

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

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

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

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

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

×
251
        ^ username
×
252
]
×
253

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

×
257
        username := anObject
×
258
]
×
259

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

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

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

×
271
        ^ (users at: #values)
×
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