Skip to content

Commit 63325b7

Browse files
slaughter550Nyholm
authored andcommitted
Add support for fetching statuses (#565)
* Add support for fetching statuses * fix style ci * Add docs, add test, linter cleanup * Merge in master * Update language * Fix test
1 parent ae43b27 commit 63325b7

File tree

2 files changed

+57
-16
lines changed

2 files changed

+57
-16
lines changed

lib/Github/Api/PullRequest.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
/**
1111
* API for accessing Pull Requests from your Git/Github repositories.
1212
*
13-
* @link http://developer.github.com/v3/pulls/
13+
* @see http://developer.github.com/v3/pulls/
14+
*
1415
* @author Joseph Bielawski <[email protected]>
1516
*/
1617
class PullRequest extends AbstractApi
@@ -60,7 +61,7 @@ public function all($username, $repository, array $params = array())
6061
{
6162
$parameters = array_merge(array(
6263
'page' => 1,
63-
'per_page' => 30
64+
'per_page' => 30,
6465
), $params);
6566

6667
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls', $parameters);
@@ -92,6 +93,24 @@ public function files($username, $repository, $id)
9293
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id).'/files');
9394
}
9495

96+
/**
97+
* All statuses which are the statuses of its head branch.
98+
*
99+
* @see http://developer.github.com/v3/pulls/
100+
*
101+
* @param string $username the username
102+
* @param string $repository the repository
103+
* @param string $id the ID of the pull request for which statuses are retrieved
104+
*
105+
* @return array array of statuses for the project
106+
*/
107+
public function status($username, $repository, $id)
108+
{
109+
$link = $this->show($username, $repository, $id)['_links']['statuses']['href'];
110+
111+
return $this->get($link);
112+
}
113+
95114
public function comments()
96115
{
97116
return new Comments($this->client);

test/Github/Tests/Api/PullRequestTest.php

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,28 @@ public function shouldShowFilesFromPullRequest()
101101
$this->assertEquals($expectedArray, $api->files('ezsystems', 'ezpublish', '15'));
102102
}
103103

104+
/**
105+
* @test
106+
*/
107+
public function shouldShowStatusesFromPullRequest()
108+
{
109+
$expectedArray = array(array('id' => 'id', 'sha' => '123123'));
110+
$expectedArray['_links']['statuses']['href'] = '/repos/ezsystems/ezpublish/pulls/15/statuses';
111+
112+
$api = $this->getApiMock();
113+
$api->expects($this->at(0))
114+
->method('get')
115+
->with('/repos/ezsystems/ezpublish/pulls/15')
116+
->will($this->returnValue($expectedArray));
117+
118+
$api->expects($this->at(1))
119+
->method('get')
120+
->with('/repos/ezsystems/ezpublish/pulls/15/statuses')
121+
->will($this->returnValue($expectedArray));
122+
123+
$this->assertEquals($expectedArray, $api->status('ezsystems', 'ezpublish', '15'));
124+
}
125+
104126
/**
105127
* @test
106128
*/
@@ -187,10 +209,10 @@ public function shouldMergePullRequestWithMergeMethod()
187209
public function shouldCreatePullRequestUsingTitle()
188210
{
189211
$data = array(
190-
'base' => 'master',
191-
'head' => 'virtualtestbranch',
212+
'base' => 'master',
213+
'head' => 'virtualtestbranch',
192214
'title' => 'TITLE: Testing pull-request creation from PHP Github API',
193-
'body' => 'BODY: Testing pull-request creation from PHP Github API'
215+
'body' => 'BODY: Testing pull-request creation from PHP Github API',
194216
);
195217

196218
$api = $this->getApiMock();
@@ -207,9 +229,9 @@ public function shouldCreatePullRequestUsingTitle()
207229
public function shouldCreatePullRequestUsingIssueId()
208230
{
209231
$data = array(
210-
'base' => 'master',
211-
'head' => 'virtualtestbranch',
212-
'issue' => 25
232+
'base' => 'master',
233+
'head' => 'virtualtestbranch',
234+
'issue' => 25,
213235
);
214236

215237
$api = $this->getApiMock();
@@ -227,9 +249,9 @@ public function shouldCreatePullRequestUsingIssueId()
227249
public function shouldNotCreatePullRequestWithoutBase()
228250
{
229251
$data = array(
230-
'head' => 'virtualtestbranch',
252+
'head' => 'virtualtestbranch',
231253
'title' => 'TITLE: Testing pull-request creation from PHP Github API',
232-
'body' => 'BODY: Testing pull-request creation from PHP Github API'
254+
'body' => 'BODY: Testing pull-request creation from PHP Github API',
233255
);
234256

235257
$api = $this->getApiMock();
@@ -246,9 +268,9 @@ public function shouldNotCreatePullRequestWithoutBase()
246268
public function shouldNotCreatePullRequestWithoutHead()
247269
{
248270
$data = array(
249-
'base' => 'master',
271+
'base' => 'master',
250272
'title' => 'TITLE: Testing pull-request creation from PHP Github API',
251-
'body' => 'BODY: Testing pull-request creation from PHP Github API'
273+
'body' => 'BODY: Testing pull-request creation from PHP Github API',
252274
);
253275

254276
$api = $this->getApiMock();
@@ -265,8 +287,8 @@ public function shouldNotCreatePullRequestWithoutHead()
265287
public function shouldNotCreatePullRequestUsingTitleButWithoutBody()
266288
{
267289
$data = array(
268-
'base' => 'master',
269-
'head' => 'virtualtestbranch',
290+
'base' => 'master',
291+
'head' => 'virtualtestbranch',
270292
'title' => 'TITLE: Testing pull-request creation from PHP Github API',
271293
);
272294

@@ -284,8 +306,8 @@ public function shouldNotCreatePullRequestUsingTitleButWithoutBody()
284306
public function shouldNotCreatePullRequestWithoutIssueIdOrTitle()
285307
{
286308
$data = array(
287-
'base' => 'master',
288-
'head' => 'virtualtestbranch',
309+
'base' => 'master',
310+
'head' => 'virtualtestbranch',
289311
);
290312

291313
$api = $this->getApiMock();

0 commit comments

Comments
 (0)