Skip to content

Commit b82ed17

Browse files
authored
Merge pull request #813 from kubawerlos/pull-requests-add-params
Add $params to files from pull request
2 parents 4a2a77b + b718781 commit b82ed17

File tree

2 files changed

+33
-22
lines changed

2 files changed

+33
-22
lines changed

lib/Github/Api/PullRequest.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,12 @@ public function configure($bodyType = null, $apiVersion = null)
5555
*
5656
* @param string $username the username
5757
* @param string $repository the repository
58-
* @param array $params a list of extra parameters.
58+
* @param array $parameters a list of extra parameters.
5959
*
6060
* @return array array of pull requests for the project
6161
*/
62-
public function all($username, $repository, array $params = [])
62+
public function all($username, $repository, array $parameters = [])
6363
{
64-
$parameters = array_merge([
65-
'page' => 1,
66-
'per_page' => 30,
67-
], $params);
68-
6964
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls', $parameters);
7065
}
7166

@@ -90,9 +85,9 @@ public function commits($username, $repository, $id)
9085
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id).'/commits');
9186
}
9287

93-
public function files($username, $repository, $id)
88+
public function files($username, $repository, $id, array $parameters = [])
9489
{
95-
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id).'/files');
90+
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id).'/files', $parameters);
9691
}
9792

9893
/**

test/Github/Tests/Api/PullRequestTest.php

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function shouldGetOpenPullRequests()
3232
$api = $this->getApiMock();
3333
$api->expects($this->once())
3434
->method('get')
35-
->with('/repos/ezsystems/ezpublish/pulls', ['state' => 'open', 'per_page' => 30, 'page' => 1])
35+
->with('/repos/ezsystems/ezpublish/pulls', ['state' => 'open'])
3636
->will($this->returnValue($expectedArray));
3737

3838
$this->assertEquals($expectedArray, $api->all('ezsystems', 'ezpublish', ['state' => 'open']));
@@ -48,7 +48,7 @@ public function shouldGetClosedPullRequests()
4848
$api = $this->getApiMock();
4949
$api->expects($this->once())
5050
->method('get')
51-
->with('/repos/ezsystems/ezpublish/pulls', ['state' => 'closed', 'per_page' => 30, 'page' => 1])
51+
->with('/repos/ezsystems/ezpublish/pulls', ['state' => 'closed'])
5252
->will($this->returnValue($expectedArray));
5353

5454
$this->assertEquals($expectedArray, $api->all('ezsystems', 'ezpublish', ['state' => 'closed']));
@@ -103,6 +103,22 @@ public function shouldShowFilesFromPullRequest()
103103
$this->assertEquals($expectedArray, $api->files('ezsystems', 'ezpublish', '15'));
104104
}
105105

106+
/**
107+
* @test
108+
*/
109+
public function shouldShowFilesFromPullRequestForPage()
110+
{
111+
$expectedArray = [['id' => 'id', 'sha' => '123123']];
112+
113+
$api = $this->getApiMock();
114+
$api->expects($this->once())
115+
->method('get')
116+
->with('/repos/ezsystems/ezpublish/pulls/15/files', ['page' => 2, 'per_page' => 30])
117+
->willReturn($expectedArray);
118+
119+
$this->assertSame($expectedArray, $api->files('ezsystems', 'ezpublish', '15', ['page' => 2, 'per_page' => 30]));
120+
}
121+
106122
/**
107123
* @test
108124
*/
@@ -211,10 +227,10 @@ public function shouldMergePullRequestWithMergeMethod()
211227
public function shouldCreatePullRequestUsingTitle()
212228
{
213229
$data = [
214-
'base' => 'master',
215-
'head' => 'virtualtestbranch',
230+
'base' => 'master',
231+
'head' => 'virtualtestbranch',
216232
'title' => 'TITLE: Testing pull-request creation from PHP Github API',
217-
'body' => 'BODY: Testing pull-request creation from PHP Github API',
233+
'body' => 'BODY: Testing pull-request creation from PHP Github API',
218234
];
219235

220236
$api = $this->getApiMock();
@@ -231,8 +247,8 @@ public function shouldCreatePullRequestUsingTitle()
231247
public function shouldCreatePullRequestUsingIssueId()
232248
{
233249
$data = [
234-
'base' => 'master',
235-
'head' => 'virtualtestbranch',
250+
'base' => 'master',
251+
'head' => 'virtualtestbranch',
236252
'issue' => 25,
237253
];
238254

@@ -251,9 +267,9 @@ public function shouldNotCreatePullRequestWithoutBase()
251267
{
252268
$this->expectException(MissingArgumentException::class);
253269
$data = [
254-
'head' => 'virtualtestbranch',
270+
'head' => 'virtualtestbranch',
255271
'title' => 'TITLE: Testing pull-request creation from PHP Github API',
256-
'body' => 'BODY: Testing pull-request creation from PHP Github API',
272+
'body' => 'BODY: Testing pull-request creation from PHP Github API',
257273
];
258274

259275
$api = $this->getApiMock();
@@ -270,9 +286,9 @@ public function shouldNotCreatePullRequestWithoutHead()
270286
{
271287
$this->expectException(MissingArgumentException::class);
272288
$data = [
273-
'base' => 'master',
289+
'base' => 'master',
274290
'title' => 'TITLE: Testing pull-request creation from PHP Github API',
275-
'body' => 'BODY: Testing pull-request creation from PHP Github API',
291+
'body' => 'BODY: Testing pull-request creation from PHP Github API',
276292
];
277293

278294
$api = $this->getApiMock();
@@ -289,8 +305,8 @@ public function shouldNotCreatePullRequestUsingTitleButWithoutBody()
289305
{
290306
$this->expectException(MissingArgumentException::class);
291307
$data = [
292-
'base' => 'master',
293-
'head' => 'virtualtestbranch',
308+
'base' => 'master',
309+
'head' => 'virtualtestbranch',
294310
'title' => 'TITLE: Testing pull-request creation from PHP Github API',
295311
];
296312

0 commit comments

Comments
 (0)