Skip to content

Commit f7d26bc

Browse files
committed
Provide default message on PR decline.
When a PR is declined without a `message` parameter, add an empty message to the payload. Fix & close #43
1 parent 5583d0e commit f7d26bc

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

lib/Bitbucket/API/Repositories/PullRequests.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,10 @@ public function accept($account, $repo, $id, $params = array())
309309
*/
310310
public function decline($account, $repo, $id, $params = array())
311311
{
312+
if (false === array_key_exists('message', $params)) {
313+
$params['message'] = '';
314+
}
315+
312316
return $this->getClient()->setApiVersion('2.0')->post(
313317
sprintf('repositories/%s/%s/pullrequests/%d/decline', $account, $repo, $id),
314318
json_encode($params),

test/Bitbucket/Tests/API/Repositories/PullRequestsTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Bitbucket\Tests\API as Tests;
66
use Bitbucket\API;
7+
use Buzz\Message\RequestInterface;
78

89
/**
910
* Class PullRequestsTest
@@ -318,4 +319,25 @@ public function testDeclineAPullRequest()
318319

319320
$pull->decline('gentle', 'eof', 1, $params);
320321
}
322+
323+
/**
324+
* @ticket 43
325+
*/
326+
public function testDeclineAPullRequestWithoutAMessage()
327+
{
328+
$endpoint = 'repositories/gentle/eof/pullrequests/1/decline';
329+
$params = array(
330+
'message' => ''
331+
);
332+
333+
$client = $this->getHttpClientMock();
334+
$client->expects($this->once())
335+
->method('post')
336+
->with($endpoint, json_encode($params));
337+
338+
/** @var \Bitbucket\API\Repositories\PullRequests $pull */
339+
$pull = $this->getClassMock('Bitbucket\API\Repositories\PullRequests', $client);
340+
341+
$pull->decline('gentle', 'eof', 1, array());
342+
}
321343
}

0 commit comments

Comments
 (0)