Skip to content

Add $params to files from pull request #813

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions lib/Github/Api/PullRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,12 @@ public function configure($bodyType = null, $apiVersion = null)
*
* @param string $username the username
* @param string $repository the repository
* @param array $params a list of extra parameters.
* @param array $parameters a list of extra parameters.
*
* @return array array of pull requests for the project
*/
public function all($username, $repository, array $params = [])
public function all($username, $repository, array $parameters = [])
{
$parameters = array_merge([
'page' => 1,
'per_page' => 30,
], $params);

return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls', $parameters);
}

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

public function files($username, $repository, $id)
public function files($username, $repository, $id, array $parameters = [])
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id).'/files');
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id).'/files', $parameters);
}

/**
Expand Down
42 changes: 29 additions & 13 deletions test/Github/Tests/Api/PullRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function shouldGetOpenPullRequests()
$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('/repos/ezsystems/ezpublish/pulls', ['state' => 'open', 'per_page' => 30, 'page' => 1])
->with('/repos/ezsystems/ezpublish/pulls', ['state' => 'open'])
->will($this->returnValue($expectedArray));

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

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

/**
* @test
*/
public function shouldShowFilesFromPullRequestForPage()
{
$expectedArray = [['id' => 'id', 'sha' => '123123']];

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('/repos/ezsystems/ezpublish/pulls/15/files', ['page' => 2, 'per_page' => 30])
->willReturn($expectedArray);

$this->assertSame($expectedArray, $api->files('ezsystems', 'ezpublish', '15', ['page' => 2, 'per_page' => 30]));
}

/**
* @test
*/
Expand Down Expand Up @@ -211,10 +227,10 @@ public function shouldMergePullRequestWithMergeMethod()
public function shouldCreatePullRequestUsingTitle()
{
$data = [
'base' => 'master',
'head' => 'virtualtestbranch',
'base' => 'master',
'head' => 'virtualtestbranch',
'title' => 'TITLE: Testing pull-request creation from PHP Github API',
'body' => 'BODY: Testing pull-request creation from PHP Github API',
'body' => 'BODY: Testing pull-request creation from PHP Github API',
];

$api = $this->getApiMock();
Expand All @@ -231,8 +247,8 @@ public function shouldCreatePullRequestUsingTitle()
public function shouldCreatePullRequestUsingIssueId()
{
$data = [
'base' => 'master',
'head' => 'virtualtestbranch',
'base' => 'master',
'head' => 'virtualtestbranch',
'issue' => 25,
];

Expand All @@ -251,9 +267,9 @@ public function shouldNotCreatePullRequestWithoutBase()
{
$this->expectException(MissingArgumentException::class);
$data = [
'head' => 'virtualtestbranch',
'head' => 'virtualtestbranch',
'title' => 'TITLE: Testing pull-request creation from PHP Github API',
'body' => 'BODY: Testing pull-request creation from PHP Github API',
'body' => 'BODY: Testing pull-request creation from PHP Github API',
];

$api = $this->getApiMock();
Expand All @@ -270,9 +286,9 @@ public function shouldNotCreatePullRequestWithoutHead()
{
$this->expectException(MissingArgumentException::class);
$data = [
'base' => 'master',
'base' => 'master',
'title' => 'TITLE: Testing pull-request creation from PHP Github API',
'body' => 'BODY: Testing pull-request creation from PHP Github API',
'body' => 'BODY: Testing pull-request creation from PHP Github API',
];

$api = $this->getApiMock();
Expand All @@ -289,8 +305,8 @@ public function shouldNotCreatePullRequestUsingTitleButWithoutBody()
{
$this->expectException(MissingArgumentException::class);
$data = [
'base' => 'master',
'head' => 'virtualtestbranch',
'base' => 'master',
'head' => 'virtualtestbranch',
'title' => 'TITLE: Testing pull-request creation from PHP Github API',
];

Expand Down