Skip to content

Update PullRequest::merge for polaris #466

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 1 commit into from
Nov 9, 2016
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
8 changes: 6 additions & 2 deletions lib/Github/Api/PullRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,16 @@ public function merged($username, $repository, $id)
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id).'/merge');
}

public function merge($username, $repository, $id, $message, $sha, $squash = false, $title = null)
public function merge($username, $repository, $id, $message, $sha, $mergeMethod = 'merge', $title = null)
{
if (is_bool($mergeMethod)) {
$mergeMethod = $mergeMethod ? 'squash' : 'merge';
}

$params = array(
'commit_message' => $message,
'sha' => $sha,
'squash' => $squash,
'merge_method' => $mergeMethod,
);

if (is_string($title)) {
Expand Down
34 changes: 33 additions & 1 deletion test/Github/Tests/Api/PullRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,44 @@ public function shouldMergePullRequest()
$api = $this->getApiMock();
$api->expects($this->once())
->method('put')
->with('/repos/ezsystems/ezpublish/pulls/15/merge', array('commit_message' => 'Merged something', 'sha' => str_repeat('A', 40), 'squash' => false))
->with('/repos/ezsystems/ezpublish/pulls/15/merge', array('commit_message' => 'Merged something', 'sha' => str_repeat('A', 40), 'merge_method' => 'merge'))
->will($this->returnValue($expectedArray));

$this->assertEquals($expectedArray, $api->merge('ezsystems', 'ezpublish', 15, 'Merged something', str_repeat('A', 40)));
}

/**
* @test
*/
public function shouldMergePullRequestWithSquashAsBool()
{
$expectedArray = array('some' => 'response');

$api = $this->getApiMock();
$api->expects($this->once())
->method('put')
->with('/repos/ezsystems/ezpublish/pulls/15/merge', array('commit_message' => 'Merged something', 'sha' => str_repeat('A', 40), 'merge_method' => 'squash'))
->will($this->returnValue($expectedArray));

$this->assertEquals($expectedArray, $api->merge('ezsystems', 'ezpublish', 15, 'Merged something', str_repeat('A', 40), true));
}

/**
* @test
*/
public function shouldMergePullRequestWithMergeMethod()
{
$expectedArray = array('some' => 'response');

$api = $this->getApiMock();
$api->expects($this->once())
->method('put')
->with('/repos/ezsystems/ezpublish/pulls/15/merge', array('commit_message' => 'Merged something', 'sha' => str_repeat('A', 40), 'merge_method' => 'rebase'))
->will($this->returnValue($expectedArray));

$this->assertEquals($expectedArray, $api->merge('ezsystems', 'ezpublish', 15, 'Merged something', str_repeat('A', 40), 'rebase'));
}

/**
* @test
*/
Expand Down