From d66c81e4606f230c9cb829f3e00e537238ee1c6a Mon Sep 17 00:00:00 2001 From: Bob Eagan Date: Fri, 7 Apr 2017 16:24:53 -0700 Subject: [PATCH 1/6] The Merge methods API is now official see: https://developer.github.com/changes/2017-04-07-end-merge-methods-api-preview/ this removes the apiVersion (that wasn't being used anyway..) also adds support for rebase mergeMethod per https://developer.github.com/v3/pulls/#merge-a-pull-request-merge-button Since this previously looked for the value to be bool, this is a breaking change --- lib/Github/Api/PullRequest.php | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/lib/Github/Api/PullRequest.php b/lib/Github/Api/PullRequest.php index a47509197c3..3f05e340608 100644 --- a/lib/Github/Api/PullRequest.php +++ b/lib/Github/Api/PullRequest.php @@ -22,16 +22,11 @@ class PullRequest extends AbstractApi * * @link https://developer.github.com/v3/pulls/#custom-media-types * @param string|null $bodyType - * @param string|null $apiVersion * * @return self */ - public function configure($bodyType = null, $apiVersion = null) + public function configure($bodyType = null) { - if (!in_array($apiVersion, array('polaris-preview'))) { - $apiVersion = $this->client->getApiVersion(); - } - if (!in_array($bodyType, array('text', 'html', 'full', 'diff', 'patch'))) { $bodyType = 'raw'; } @@ -159,8 +154,8 @@ public function merged($username, $repository, $id) public function merge($username, $repository, $id, $message, $sha, $mergeMethod = 'merge', $title = null) { - if (is_bool($mergeMethod)) { - $mergeMethod = $mergeMethod ? 'squash' : 'merge'; + if (!in_array($mergeMethod, array('squash', 'rebase'))) { + $mergeMethod = 'merge'; } $params = array( From 75c8f6cbf9a25d0ac8a7fff0142f44be3918f3c4 Mon Sep 17 00:00:00 2001 From: Bob Eagan Date: Fri, 7 Apr 2017 16:30:21 -0700 Subject: [PATCH 2/6] retain weird bool support for this value --- lib/Github/Api/PullRequest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/Github/Api/PullRequest.php b/lib/Github/Api/PullRequest.php index 3f05e340608..dc6b64bfa73 100644 --- a/lib/Github/Api/PullRequest.php +++ b/lib/Github/Api/PullRequest.php @@ -154,6 +154,10 @@ public function merged($username, $repository, $id) public function merge($username, $repository, $id, $message, $sha, $mergeMethod = 'merge', $title = null) { + if (is_bool($mergeMethod)) { + $mergeMethod = $mergeMethod ? 'squash' : 'merge'; + } + if (!in_array($mergeMethod, array('squash', 'rebase'))) { $mergeMethod = 'merge'; } From 504517323dc74913f3396f270838b60c16a87228 Mon Sep 17 00:00:00 2001 From: Bob Eagan Date: Fri, 14 Apr 2017 10:54:59 -0700 Subject: [PATCH 3/6] let github throw errors instead --- lib/Github/Api/PullRequest.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/Github/Api/PullRequest.php b/lib/Github/Api/PullRequest.php index dc6b64bfa73..889491f9146 100644 --- a/lib/Github/Api/PullRequest.php +++ b/lib/Github/Api/PullRequest.php @@ -158,10 +158,6 @@ public function merge($username, $repository, $id, $message, $sha, $mergeMethod $mergeMethod = $mergeMethod ? 'squash' : 'merge'; } - if (!in_array($mergeMethod, array('squash', 'rebase'))) { - $mergeMethod = 'merge'; - } - $params = array( 'commit_message' => $message, 'sha' => $sha, From 38bd1a46307202649310b01f58d49537aeca86a7 Mon Sep 17 00:00:00 2001 From: Bob Eagan Date: Fri, 14 Apr 2017 15:08:18 -0700 Subject: [PATCH 4/6] add back in $apiVersion to make it easier to handle preview versions in the future there are no preview versions now so checking against an empty array also had to fix the acceptHeaderValue to correctly use the variable --- lib/Github/Api/PullRequest.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/Github/Api/PullRequest.php b/lib/Github/Api/PullRequest.php index 889491f9146..f62b13c307a 100644 --- a/lib/Github/Api/PullRequest.php +++ b/lib/Github/Api/PullRequest.php @@ -22,11 +22,16 @@ class PullRequest extends AbstractApi * * @link https://developer.github.com/v3/pulls/#custom-media-types * @param string|null $bodyType + * @param string|null $apiVersion * * @return self */ - public function configure($bodyType = null) + public function configure($bodyType = null, $apiVersion = null) { + if (!in_array($apiVersion, array())) { + $apiVersion = $this->client->getApiVersion(); + } + if (!in_array($bodyType, array('text', 'html', 'full', 'diff', 'patch'))) { $bodyType = 'raw'; } @@ -35,7 +40,7 @@ public function configure($bodyType = null) $bodyType .= '+json'; } - $this->acceptHeaderValue = sprintf('application/vnd.github.%s.%s', $this->client->getApiVersion(), $bodyType); + $this->acceptHeaderValue = sprintf('application/vnd.github.%s.%s', $apiVersion, $bodyType); return $this; } From af435f61ed40e04fdaf956f66f77c1348bb9acd3 Mon Sep 17 00:00:00 2001 From: Bob Eagan Date: Fri, 14 Apr 2017 15:56:24 -0700 Subject: [PATCH 5/6] throw invalidargumentexception when trying to use invalid merge method --- lib/Github/Api/PullRequest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/Github/Api/PullRequest.php b/lib/Github/Api/PullRequest.php index f62b13c307a..28e5bf68f0b 100644 --- a/lib/Github/Api/PullRequest.php +++ b/lib/Github/Api/PullRequest.php @@ -163,6 +163,10 @@ public function merge($username, $repository, $id, $message, $sha, $mergeMethod $mergeMethod = $mergeMethod ? 'squash' : 'merge'; } + if (!in_array($mergeMethod, array('merge', 'squash', 'rebase'), true)) { + throw new InvalidArgumentException(sprintf('"$mergeMethod" must be one of ["merge", "squash", "rebase"] ("%s" given).', $mergeMethod)); + } + $params = array( 'commit_message' => $message, 'sha' => $sha, From 574a92705f006a7e7f6043225954ccae5f34ad2f Mon Sep 17 00:00:00 2001 From: Bob Eagan Date: Fri, 14 Apr 2017 16:09:27 -0700 Subject: [PATCH 6/6] add missing use --- lib/Github/Api/PullRequest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Github/Api/PullRequest.php b/lib/Github/Api/PullRequest.php index 28e5bf68f0b..b4099eaf43d 100644 --- a/lib/Github/Api/PullRequest.php +++ b/lib/Github/Api/PullRequest.php @@ -5,6 +5,7 @@ use Github\Api\PullRequest\Comments; use Github\Api\PullRequest\Review; use Github\Api\PullRequest\ReviewRequest; +use Github\Exception\InvalidArgumentException; use Github\Exception\MissingArgumentException; /**