Skip to content

Commit

Permalink
feat(BitbucketPullRequests): create a pull request (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
knowbased authored Jan 23, 2025
1 parent b7c7456 commit 4188905
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/BitbucketPharoAPI-Tests/BitbucketPullRequestsTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,49 @@ Class {
#package : 'BitbucketPharoAPI-Tests'
}

{ #category : 'tests' }
BitbucketPullRequestsTest >> testCreateFromRefToRefInRepositoryOfProject [

| hostUrl result client endpoint response bitbucketApi bitbucketPullRequests projectKey repositorySlug fromRef toRef title data |
"Given"
hostUrl := 'www.url.com'.
client := Mock new.

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

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

fromRef := 'test'.
toRef := 'dev'.
title := 'a title'.

data := {
(#title -> title).
(#fromRef -> { (#id -> fromRef) } asDictionary).
(#toRef -> { (#id -> toRef) } asDictionary) } asDictionary.

endpoint := '/projects/' , projectKey , '/repos/' , repositorySlug
, '/pull-requests'.

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

(bitbucketPullRequests stub
postJson: endpoint
withData: data) willReturn: response.

"When"
result := bitbucketPullRequests
create: title fromRef: fromRef toRef: toRef inRepository: repositorySlug ofProject: projectKey.
"Then"
self assert: result equals: response
]

{ #category : 'tests' }
BitbucketPullRequestsTest >> testDiffOfInRepositoryOfProject [

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

{ #category : 'api - post' }
BitbucketPullRequests >> create: title fromRef: fromRefId toRef: toRefId inRepository: repositorySlug ofProject: projectKey [
"POST /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/pull-requests"

| endpoint data |
endpoint := '/projects/', projectKey, '/repos/', repositorySlug, '/pull-requests'.

data := {
#title -> title.
#fromRef -> { #id -> fromRefId } asDictionary.
#toRef -> { #id -> toRefId } asDictionary.
} asDictionary.

^ self postJson: endpoint withData: data.
]

{ #category : 'api - get' }
BitbucketPullRequests >> diffOf: pullRequestId inRepository: repositorySlug ofProject: projectKey [
"/rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/pull-requests/{pullRequestId}/diff"
Expand Down

0 comments on commit 4188905

Please sign in to comment.