Skip to content

Commit 8e30606

Browse files
committed
Add $params to files from pull request
1 parent 4a2a77b commit 8e30606

File tree

2 files changed

+35
-14
lines changed

2 files changed

+35
-14
lines changed

lib/Github/Api/PullRequest.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,14 @@ public function commits($username, $repository, $id)
9090
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id).'/commits');
9191
}
9292

93-
public function files($username, $repository, $id)
93+
public function files($username, $repository, $id, array $params = [])
9494
{
95-
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id).'/files');
95+
$parameters = array_merge([
96+
'page' => 1,
97+
'per_page' => 30,
98+
], $params);
99+
100+
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id).'/files', $parameters);
96101
}
97102

98103
/**

test/Github/Tests/Api/PullRequestTest.php

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,28 @@ public function shouldShowFilesFromPullRequest()
9797
$api = $this->getApiMock();
9898
$api->expects($this->once())
9999
->method('get')
100-
->with('/repos/ezsystems/ezpublish/pulls/15/files')
100+
->with('/repos/ezsystems/ezpublish/pulls/15/files', ['page' => 1, 'per_page' => 30])
101101
->will($this->returnValue($expectedArray));
102102

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)