Skip to content

Commit

Permalink
feat(BitbucketBranches): get all branches (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
knowbased authored Jan 24, 2025
1 parent 190ff80 commit 0bde510
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/BitbucketPharoAPI-Tests/BitbucketBranchesTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,45 @@ Class {
#package : 'BitbucketPharoAPI-Tests'
}

{ #category : 'tests' }
BitbucketBranchesTest >> testAllWithParamsInRepositoryOfProject [

"Given"

| hostUrl client bitbucketApi projectKey repositorySlug endpoint response result bitbucketBranches params |
hostUrl := 'www.url.com'.
client := Mock new.

bitbucketApi := BitbucketApi new
bearerToken: 'token';
host: hostUrl;
client: client.

bitbucketBranches := BitbucketBranches new bitbucketApi: bitbucketApi.

projectKey := 'OOO'.
repositorySlug := 'my project'.

params := {
#filterText -> 'text'
} asDictionary.

endpoint := '/projects/' , projectKey , '/repos/' , repositorySlug
, '/branches'.

response := { (#message -> 'message') } asDictionary.

(bitbucketBranches stub getAll: endpoint withParams: params)
willReturn: response.

"When"
result := bitbucketBranches
allWithParams: params inRepository: repositorySlug ofProject: projectKey.

"Then"
self assert: result equals: response
]

{ #category : 'tests' }
BitbucketBranchesTest >> testCreateWithStartPointInRepositoryOfProject [

Expand Down
35 changes: 35 additions & 0 deletions src/BitbucketPharoAPI-Tests/BitbucketRessourceTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,41 @@ Class {
#package : 'BitbucketPharoAPI-Tests'
}

{ #category : 'tests' }
BitbucketRessourceTest >> testGetAllWithParams [
"Given"

| hostUrl client endpoint params objectId object bitbucketApi bitbucketRessource result response |
hostUrl := 'https://www.url.com'.
client := ZnClient new.

bitbucketApi := BitbucketApi new
bearerToken: 'token';
host: hostUrl;
client: client.

endpoint := '/endpoint'.
params := { ('param' -> 'value') } asDictionary.

objectId := 1.
object := { (#id -> objectId) } asDictionary.

bitbucketRessource := BitbucketRessource new bitbucketApi:
bitbucketApi.


response := { #values -> { object }. #isLastPage -> true } asDictionary.
client stub get willReturn: (NeoJSONWriter toString: response).


"When"
result := bitbucketRessource getAll: endpoint withParams: params.

"Then"
self assert: result size equals: 1.
self assert: result first equals: object
]

{ #category : 'tests' }
BitbucketRessourceTest >> testGetWithParams [

Expand Down
11 changes: 11 additions & 0 deletions src/BitbucketPharoAPI/BitbucketBranches.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ Class {
#package : 'BitbucketPharoAPI'
}

{ #category : 'api - get' }
BitbucketBranches >> allWithParams: paramsDict inRepository: repositorySlug ofProject: projectKey [
"GET /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/branches?base&details&filterText&orderBy"

| endpoint |
endpoint := '/projects/' , projectKey , '/repos/' , repositorySlug
, '/branches'.

^ self getAll: endpoint withParams: paramsDict
]

{ #category : 'api - post' }
BitbucketBranches >> create: branchName withStartPoint: startPoint inRepository: repositorySlug ofProject: projectKey [
"POST /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/branches"
Expand Down
25 changes: 25 additions & 0 deletions src/BitbucketPharoAPI/BitbucketRessource.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,31 @@ BitbucketRessource >> get: path withParams: paramsDict [
^ response
]

{ #category : 'api' }
BitbucketRessource >> getAll: endpoint withParams: paramsDict [

| values results |
bitbucketApi prepareClient.
bitbucketApi client path: bitbucketApi basePath , endpoint.

paramsDict keysAndValuesDo: [ :key :value |
bitbucketApi client queryAt: key put: value ].

values := OrderedCollection new.

[
results := bitbucketApi client get.
results := (NeoJSONReader on: results readStream) next.
values addAll: (results at: #values).
results at: #nextPageStart ifPresent: [
bitbucketApi client
queryAt: #start
put: (results at: #nextPageStart) ].
results at: #isLastPage ] whileFalse.

^ values
]

{ #category : 'api' }
BitbucketRessource >> postJson: endpoint withData: data [

Expand Down

0 comments on commit 0bde510

Please sign in to comment.