From 021d9242aad023869af9f242dc076e9967f9df70 Mon Sep 17 00:00:00 2001 From: Sullivan SENECHAL Date: Sat, 28 May 2016 14:10:13 +0200 Subject: [PATCH] Add merge by squash option Refs: - https://developer.github.com/v3/pulls/#merge-a-pull-request-merge-button - https://developer.github.com/changes/2016-04-01-squash-api-preview/ --- lib/Github/Api/PullRequest.php | 16 ++++++++++++---- test/Github/Tests/Api/PullRequestTest.php | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/Github/Api/PullRequest.php b/lib/Github/Api/PullRequest.php index e0bb27bfee0..6e3028faf53 100644 --- a/lib/Github/Api/PullRequest.php +++ b/lib/Github/Api/PullRequest.php @@ -115,10 +115,18 @@ 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) + public function merge($username, $repository, $id, $message, $sha, $squash = false, $title = null) { - return $this->put('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id).'/merge', array( - 'commit_message' => $message, 'sha' => $sha - )); + $params = array( + 'commit_message' => $message, + 'sha' => $sha, + 'squash' => $squash, + ); + + if (is_string($title)) { + $params['commit_title'] = $title; + } + + return $this->put('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id).'/merge', $params); } } diff --git a/test/Github/Tests/Api/PullRequestTest.php b/test/Github/Tests/Api/PullRequestTest.php index e9b8f2dba2f..cf18f9e3b82 100644 --- a/test/Github/Tests/Api/PullRequestTest.php +++ b/test/Github/Tests/Api/PullRequestTest.php @@ -143,7 +143,7 @@ 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))) + ->with('repos/ezsystems/ezpublish/pulls/15/merge', array('commit_message' => 'Merged something', 'sha' => str_repeat('A', 40), 'squash' => false)) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->merge('ezsystems', 'ezpublish', 15, 'Merged something', str_repeat('A', 40)));