Skip to content

Commit 3b5ac57

Browse files
committed
implemented PullRequests::accept (API 2.0)
1 parent 3717439 commit 3b5ac57

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

docs/repositories/pullrequests.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ If pull request ID is omitted, the entire repository's pull request activity is
8484
$pull->activity($account_name, $repo_slug, 1);
8585
```
8686

87+
### Accept and merge a pull request:
88+
```php
89+
$pull->accept($account_name, $repo_slug, 1, array(
90+
'message' => 'This message will be used for merge commit.'
91+
));
92+
```
93+
8794
----
8895

8996
#### Related:

lib/Bitbucket/API/Repositories/PullRequests.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,4 +236,22 @@ public function activity($account, $repo, $id = 0)
236236

237237
return $this->getClient()->setApiVersion('2.0')->get($endpoint);
238238
}
239+
240+
/**
241+
* Accept and merge a pull request
242+
*
243+
* @access public
244+
* @param string $account The team or individual account owning the repository.
245+
* @param string $repo The repository identifier.
246+
* @param int $id (Optional) ID of the pull request
247+
* @param array $params Additional parameters.
248+
* @return MessageInterface
249+
*/
250+
public function accept($account, $repo, $id, $params = array())
251+
{
252+
return $this->getClient()->setApiVersion('2.0')->post(
253+
sprintf('repositories/%s/%s/pullrequests/%d/merge', $account, $repo, $id),
254+
$params
255+
);
256+
}
239257
}

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,4 +254,23 @@ public function testGetRepositoryPullRequestActivity()
254254

255255
$this->assertEquals($expectedResult, $actual);
256256
}
257+
258+
public function testAcceptAndMergeAPullRequest()
259+
{
260+
$endpoint = 'repositories/gentle/eof/pullrequests/1/merge';
261+
$params = array(
262+
'message' => 'Lacks documentation.',
263+
'close_source_branch' => false
264+
);
265+
266+
$client = $this->getHttpClientMock();
267+
$client->expects($this->once())
268+
->method('post')
269+
->with($endpoint, $params);
270+
271+
/** @var \Bitbucket\API\Repositories\PullRequests $pull */
272+
$pull = $this->getClassMock('Bitbucket\API\Repositories\PullRequests', $client);
273+
274+
$pull->accept('gentle', 'eof', 1, $params);
275+
}
257276
}

0 commit comments

Comments
 (0)