Skip to content

Commit 81f8de8

Browse files
Philip Nelsonvimishor
authored andcommitted
Use API 2.0 for PR comments create/update/delete
Merged in 53Phil/bitbucket-api/pr-comments-v2 (pull request #44)
2 parents 3cd11fe + 5dfcc38 commit 81f8de8

File tree

2 files changed

+36
-27
lines changed

2 files changed

+36
-27
lines changed

lib/Bitbucket/API/Repositories/PullRequests/Comments.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,10 @@ public function get($account, $repo, $requestID, $commentID)
6666
*/
6767
public function create($account, $repo, $requestID, $content)
6868
{
69-
return $this->requestPost(
69+
return $this->getClient()->setApiVersion('2.0')->post(
7070
sprintf('repositories/%s/%s/pullrequests/%d/comments', $account, $repo, $requestID),
71-
array('content' => $content)
71+
json_encode(array('content' => array('raw' => $content))),
72+
array('Content-Type' => 'application/json')
7273
);
7374
}
7475

@@ -85,9 +86,10 @@ public function create($account, $repo, $requestID, $content)
8586
*/
8687
public function update($account, $repo, $requestID, $commentID, $content)
8788
{
88-
return $this->requestPut(
89+
return $this->getClient()->setApiVersion('2.0')->put(
8990
sprintf('repositories/%s/%s/pullrequests/%d/comments/%d', $account, $repo, $requestID, $commentID),
90-
array('content' => $content)
91+
json_encode(array('content' => array('raw' => $content))),
92+
array('Content-Type' => 'application/json')
9193
);
9294
}
9395

@@ -103,7 +105,7 @@ public function update($account, $repo, $requestID, $commentID, $content)
103105
*/
104106
public function delete($account, $repo, $requestID, $commentID)
105107
{
106-
return $this->requestDelete(
108+
return $this->getClient()->setApiVersion('2.0')->delete(
107109
sprintf('repositories/%s/%s/pullrequests/%d/comments/%d', $account, $repo, $requestID, $commentID)
108110
);
109111
}

test/Bitbucket/Tests/API/Repositories/PullRequests/CommentsTest.php

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -46,43 +46,50 @@ public function testGetSingleComment()
4646
public function testCreateCommentSuccess()
4747
{
4848
$endpoint = 'repositories/gentle/eof/pullrequests/1/comments';
49-
$params = array(
50-
'content' => 'dummy comment'
51-
);
49+
$expectedResult = $this->fakeResponse(array('dummy'));
5250

53-
$comment = $this->getApiMock('Bitbucket\API\Repositories\PullRequests\Comments');
54-
$comment->expects($this->once())
55-
->method('requestPost')
56-
->with($endpoint, $params);
51+
$client = $this->getHttpClientMock();
52+
$client->expects($this->once())
53+
->method('post')
54+
->with($endpoint)
55+
->will($this->returnValue($expectedResult));
5756

58-
/** @var $comment \Bitbucket\API\Repositories\PullRequests\Comments */
59-
$comment->create('gentle', 'eof', 1, 'dummy comment');
57+
/** @var \Bitbucket\API\Repositories\PullRequests\Comments $comments */
58+
$comments = $this->getClassMock('Bitbucket\API\Repositories\PullRequests\Comments', $client);
59+
$actual = $comments->create('gentle', 'eof', 1, 'test');
60+
61+
$this->assertEquals($expectedResult, $actual);
6062
}
6163

6264
public function testUpdateCommentSuccess()
6365
{
6466
$endpoint = 'repositories/gentle/eof/pullrequests/1/comments/3';
65-
$params = array('content' => 'dummy');
67+
$expectedResult = array('content' => 'dummy');
68+
69+
$client = $this->getHttpClientMock();
70+
$client->expects($this->once())
71+
->method('put')
72+
->with($endpoint)
73+
->will($this->returnValue($expectedResult));
6674

67-
$comment = $this->getApiMock('Bitbucket\API\Repositories\PullRequests\Comments');
68-
$comment->expects($this->once())
69-
->method('requestPut')
70-
->with($endpoint, $params);
75+
/** @var \Bitbucket\API\Repositories\PullRequests\Comments $comments */
76+
$comments = $this->getClassMock('Bitbucket\API\Repositories\PullRequests\Comments', $client);
77+
$actual = $comments->update('gentle', 'eof', 1, 3, 'dummy');
7178

72-
/** @var $comment \Bitbucket\API\Repositories\PullRequests\Comments */
73-
$comment->update('gentle', 'eof', 1, 3, 'dummy');
79+
$this->assertEquals($expectedResult, $actual);
7480
}
7581

7682
public function testDeleteCommentSuccess()
7783
{
78-
$endpoint = 'repositories/gentle/eof/pullrequests/1/comments/2';
84+
$endpoint = 'repositories/gentle/eof/pullrequests/1/comments/2';
7985

80-
$comment = $this->getApiMock('Bitbucket\API\Repositories\PullRequests\Comments');
81-
$comment->expects($this->once())
82-
->method('requestDelete')
86+
$client = $this->getHttpClientMock();
87+
$client->expects($this->once())
88+
->method('delete')
8389
->with($endpoint);
8490

85-
/** @var $comment \Bitbucket\API\Repositories\PullRequests\Comments */
86-
$comment->delete('gentle', 'eof', 1, 2);
91+
/** @var \Bitbucket\API\Repositories\PullRequests\Comments $comments */
92+
$comments = $this->getClassMock('Bitbucket\API\Repositories\PullRequests\Comments', $client);
93+
$comments->delete('gentle', 'eof', 1, 2);
8794
}
8895
}

0 commit comments

Comments
 (0)