octokit / octokit.js

The all-batteries-included GitHub SDK for Browsers, Node.js, and Deno.
MIT License
7.03k stars 1.03k forks source link

Custom Accept header not provided to Checks API ES 2.22 #1983

Closed mcaulifn closed 3 years ago

mcaulifn commented 3 years ago

Checklist

Environment

Versions

├─┬ @octokit/auth-app@2.10.5
│ ├─┬ @octokit/request@5.4.12
│ │ ├─┬ @octokit/endpoint@6.0.10
│ ├─┬ @octokit/request-error@2.0.4
├─┬ @octokit/rest@18.0.12
│ ├─┬ @octokit/core@3.2.4
│ │ ├─┬ @octokit/auth-token@2.4.4
│ │ ├─┬ @octokit/graphql@4.5.8
│ ├─┬ @octokit/plugin-paginate-rest@2.6.2
│ ├── @octokit/plugin-request-log@1.0.2
│ └─┬ @octokit/plugin-rest-endpoint-methods@4.4.1
├─┬ @octokit/types@6.1.1
│ ├── @octokit/openapi-types@2.0.0

What happened?

ERROR   RequestError [HttpError]: If you would like to help us test the Checks API during its preview period, you must specify a custom media type in the 'Accept' header. Please see the docs for full details.

Minimal test case to reproduce the problem

Request object from error:

request: {
    method: 'GET',
    url: 'https://githubtest.expedia.biz/api/v3/repos/ActionsTest/krang-test/check-runs/834',
    headers: {
      accept: 'application/vnd.github.v3+json',
      'user-agent': 'octokit-rest.js/18.0.12 octokit-core.js/3.2.4 Node.js/12.19.0 (linux; x64)',
      authorization: 'token [REDACTED]'
    },
    request: { hook: [Function: bound bound register] }
  },

What did you expect to happen?

Octokit to insert necessary headers.

What the problem might be

Possibly introduced with https://github.com/octokit/rest.js/pull/1952. Similar to https://github.com/octokit/rest.js/issues/861

gr2m commented 3 years ago

For Enterprise Server we recommend using @octokit/core with the @octokit/plugin-enterprise-server plugin. Using it will set the appropriate headers required for the respective version.

You can also explicitly set a preview header by passing { ..., mediaType: { previews: ['antiope'] } } to the options.

If you want to support both api.github.com and supported GitHub Enterprise Server versions, you could use https://github.com/octokit/plugin-enterprise-compatibility.js, but we would need to add the feature to add the antiope preview to the respective requests. If you want to send a pull request I'd be happy to review it.

mcaulifn commented 3 years ago

By removing @octokit/types@6.1.1 and reverting to @octokit/rest@18.0.9, this same call works as expected.

I am not in a position to create a PR for that feature.

gr2m commented 3 years ago

I think adding the mediaType parameter is the better workaround compared to pinning outdated versions of @ocotkit/* libraries. But I'm glad you got it unblocked

npalm commented 3 years ago

@gr2m thanks for the hint of the media type. And fully agree, I don't like to stick to an old version.