Skip to content

Commit 2e852b6

Browse files
committed
Merged in pierredup/bitbucket-api/master (pull request gentlero#4)
Add method to get all pull requests
2 parents 48f9ae0 + 3c1b28a commit 2e852b6

File tree

3 files changed

+55
-2
lines changed

3 files changed

+55
-2
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
require_once __DIR__.'/../../vendor/autoload.php';
4+
5+
$pullRequests = new Bitbucket\API\Repositories\PullRequests;
6+
7+
// Your Bitbucket credentials
8+
$bb_user = 'username';
9+
$bb_pass = 'password';
10+
11+
/**
12+
* $accountname The team or individual account owning the repository.
13+
* repo_slub The repository identifier.
14+
*/
15+
$accountname = 'company';
16+
$repo_slug = 'sandbox';
17+
18+
// login
19+
$pullRequests->setCredentials( new Bitbucket\API\Authentication\Basic($bb_user, $bb_pass) );
20+
21+
# get list of pull requests
22+
print_r($pullRequests->all($accountname, $repo_slug));

lib/Bitbucket/API/Repositories/PullRequests.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,21 @@ public function comments()
3333
{
3434
return $this->childFactory('Repositories\\PullRequests\\Comments');
3535
}
36+
37+
/**
38+
* Get a list of pull requests
39+
*
40+
* @access public
41+
* @param string $account The team or individual account owning the repository.
42+
* @param string $repo The repository identifier.
43+
* @return mixed
44+
*/
45+
public function all($account, $repo)
46+
{
47+
$this->httpClient->setApiVersion('2.0');
48+
49+
return $this->requestGet(
50+
sprintf('repositories/%s/%s/pullrequests', $account, $repo)
51+
);
52+
}
3653
}

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@
1010
*/
1111
class PullRequestsTest extends Tests\TestCase
1212
{
13-
public function testDummy()
14-
{}
13+
public function testGetAllPullRequests()
14+
{
15+
$endpoint = 'repositories/gentle/eof/pullrequests';
16+
$expectedResult = json_encode('dummy');
17+
18+
$pullRequests = $this->getApiMock('Bitbucket\API\Repositories\PullRequests');
19+
$pullRequests->expects($this->once())
20+
->method('requestGet')
21+
->with($endpoint)
22+
->will( $this->returnValue($expectedResult) );
23+
24+
/** @var $pullRequests \Bitbucket\API\Repositories\PullRequests */
25+
$actual = $pullRequests->all('gentle', 'eof');
26+
27+
$this->assertEquals($expectedResult, $actual);
28+
}
1529
}

0 commit comments

Comments
 (0)