Skip to content
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

Unable to retrieve pull request diff #93

Closed
morozov opened this issue Nov 25, 2013 · 4 comments
Closed

Unable to retrieve pull request diff #93

morozov opened this issue Nov 25, 2013 · 4 comments

Comments

@morozov
Copy link
Contributor

morozov commented Nov 25, 2013

The following code snippet is supposed to produce the pull reques diff. It used to work a while ago but now it doesnt.

$client = new Github\Client();
$client->authenticate(
    'put-your-token-here',
    null,
    Github\Client::AUTH_URL_TOKEN
);

/** @var Github\Api\PullRequest $api */
$api = $client->api('pull_request');
$client->setHeaders(array(
    sprintf(
        'Accept: application/vnd.github.%s.diff',
        $client->getOption('api_version')
    )
));

$diff = $api->show('KnpLabs', 'php-github-api', '92');

echo gettype($diff);
// expected: string
// actual: array

The point is that here default Accept header is appepended with custom but not overridden, thus both of them are sent.

Default User-Agent and Accept headers should be sent only if other values are not specified.

@cursedcoder
Copy link
Contributor

The library provides you github api v3, you can check actual documentation here http://developer.github.com/v3/pulls/#get-a-single-pull-request

I just checked code snippet you have provided and the output is exactly the same as mentioned in v3 docs.

Can't really help on that because github no longer supports older versions AFAIK.
But of course you can try your code snippet with older versions of library.

@morozov
Copy link
Contributor Author

morozov commented Nov 27, 2013

GitHub API v3 also supports custom media types for pull requests.

Please try running the following:

curl https://api.github.com/repos/KnpLabs/php-github-api/pulls/92 \
  -H "Accept: application/vnd.github.v3.diff"

@cursedcoder
Copy link
Contributor

@morozov you have to specify header key instead of plain text:

$client->setHeaders(array(
    'Accept' => sprintf('application/vnd.github.%s.diff', $client->getOption('api_version'))
));

@morozov
Copy link
Contributor Author

morozov commented Nov 29, 2013

👍 Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants