-
-
Notifications
You must be signed in to change notification settings - Fork 600
Add configure() support for issues #532
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
Changes from 2 commits
962beba
8380ce4
a45ce63
debf2b3
07cb9e4
f210737
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,13 +3,31 @@ | |
namespace Github\Api\Gist; | ||
|
||
use Github\Api\AbstractApi; | ||
use Github\Api\AcceptHeaderTrait; | ||
|
||
/** | ||
* @link https://developer.github.com/v3/gists/comments/ | ||
* @author Kayla Daniels <[email protected]> | ||
*/ | ||
class Comments extends AbstractApi | ||
{ | ||
use AcceptHeaderTrait; | ||
|
||
/** | ||
* Configure the body type. | ||
* | ||
* @link https://developer.github.com/v3/gists/comments/#custom-media-types | ||
* @param string|null $bodyType | ||
*/ | ||
public function configure($bodyType = null) | ||
{ | ||
if (!in_array($bodyType, array('text', 'html', 'full'))) { | ||
$bodyType = 'raw'; | ||
} | ||
|
||
$this->acceptHeaderValue = sprintf('application/vnd.github.%s.%s+json', $this->client->getApiVersion(), $bodyType); | ||
} | ||
|
||
/** | ||
* Get all comments for a gist. | ||
* | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,31 @@ | |
*/ | ||
class PullRequest extends AbstractApi | ||
{ | ||
use AcceptHeaderTrait; | ||
|
||
/** | ||
* Configure the body type. | ||
* | ||
* @link https://developer.github.com/v3/pulls/#custom-media-types | ||
* @param string|null $bodyType | ||
*/ | ||
public function configure($apiVersion = null, $bodyType = null) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tell me more about the api version here. That is just to enable preview features, right? You cannot change to an older version of the API. Also why have you chosen this order of parameters? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct, this was to allow for setting the preview version of https://developer.github.com/v3/pulls/#merge-a-pull-request-merge-button Looking now, the order doesn't make much sense as I did it, I'm guessing that I probably started on the PullRequest/Comments (since that is what I was looking to set a preview version for and then came back through later when I figured I would update all of the places that allow changing the bodyType of message responses. I'll update this to flip the order around (and also to add the missing |
||
{ | ||
if (!in_array($apiVersion, array('polaris-preview'))) { | ||
$apiVersion = $this->client->getApiVersion(); | ||
} | ||
|
||
if (!in_array($bodyType, array('text', 'html', 'full', 'diff', 'patch'))) { | ||
$bodyType = 'raw'; | ||
} | ||
|
||
if (!in_array($bodyType, array('diff', 'patch'))) { | ||
$bodyType .= '+json'; | ||
} | ||
|
||
$this->acceptHeaderValue = sprintf('application/vnd.github.%s.%s', $this->client->getApiVersion(), $bodyType); | ||
} | ||
|
||
/** | ||
* Get a listing of a project's pull requests by the username, repository and (optionally) state. | ||
* | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,26 +15,19 @@ class Comments extends AbstractApi | |
{ | ||
use AcceptHeaderTrait; | ||
|
||
/** | ||
* Configure the body type. | ||
* | ||
* @link https://developer.github.com/v3/repos/comments/#custom-media-types | ||
* @param string|null $bodyType | ||
*/ | ||
public function configure($bodyType = null) | ||
{ | ||
switch ($bodyType) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! |
||
case 'raw': | ||
$header = sprintf('Accept: application/vnd.github.%s.raw+json', $this->client->getApiVersion()); | ||
break; | ||
|
||
case 'text': | ||
$header = sprintf('Accept: application/vnd.github.%s.text+json', $this->client->getApiVersion()); | ||
break; | ||
|
||
case 'html': | ||
$header = sprintf('Accept: application/vnd.github.%s.html+json', $this->client->getApiVersion()); | ||
break; | ||
|
||
default: | ||
$header = sprintf('Accept: application/vnd.github.%s.full+json', $this->client->getApiVersion()); | ||
if (!in_array($bodyType, array('text', 'html', 'full'))) { | ||
$bodyType = 'raw'; | ||
} | ||
|
||
$this->acceptHeaderValue = $header; | ||
$this->acceptHeaderValue = sprintf('application/vnd.github.%s.%s+json', $this->client->getApiVersion(), $bodyType); | ||
} | ||
|
||
public function all($username, $repository, $sha = null) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You cannot change the default behavior. That is breaking BC
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I mentioned in the initial PR message and also further down in the last comment I left, I was recognizing that this was a breaking change but that as it was currently implemented here (and in Repository/Comments) the option that you have defaulting currently does not align with the default behavior that is described in the GitHub API documentation.
I would suggest aligning with the documentation, noting the breaking change in the release and bumping a major version.
If you aren't interested in doing that, then I would rather go through and change all of the places where I set the default value to
raw
and switch them tofull
but then I would suggest that information gets included somewhere that the default behavior of this library does not match the default behavior of the documentation, to avoid any potential for confusion of users of the library.Let me know your preference and I'll update accordingly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I saw your comments.
I think the best solution is to accept that we made a mistake before by keep the default body type to
full
for the comments API. In general we should align with the docs.Making a new major release just for this fix is not a good solution. What we should do is to create a new issue suggesting this change and add that issue in a 3.0 milestone.
So in short: Just change this back to
full
and I'll be happy to merge.