octokit / request-action

A GitHub Action to send arbitrary requests to GitHub's REST API
https://github.com/marketplace/actions/GitHub-API-Request
MIT License
368 stars 48 forks source link

Fix support for requesting a custom media type #176

Closed timrogers closed 2 years ago

timrogers commented 2 years ago

This action supports passing a custom mediaType, but this doesn't actually work. The action receives a string, but octokit/endpoint.js [expects][1] to be passed an object with format and/or previews keys.

Trying to pass a mediaType value as suggested in the action.yml leads to a Cannot read property 'map' of undefined error which comes from [endpoint.js's merge function][2] which is assuming that the passed mediaType will be an object with properties.

This fixes the issue by taking the value passed in as mediaType and sending it to endpoint.js as mediaType.format.

There are other potential approaches we could take to this, for example:

Fixes https://github.com/octokit/request-action/issues/175.

[1]: https://github.com/octokit/endpoint.js#endpointroute-options-or-endpointoptions [2]: https://github.com/octokit/endpoint.js/blob/8266fc12765e94cb966d5104a375631b4efb0dbf/src/merge.ts#L35-L37

gr2m commented 2 years ago

You can pass mediaType like this

          mediaType: | # The | is significant!
            format: raw

I'd suggest we add an example to the README instead of doing the code change?

timrogers commented 2 years ago

You can pass mediaType like this

          mediaType: | # The | is significant!
            format: raw

I'd suggest we add an example to the README instead of doing the code change?

Interesting! I didn't know you could pass an object using that format. Let's update the README as you suggest.

gr2m commented 1 year ago

I didn't know you could pass an object using that format

it only works because of the way we read out the parameters in this action, it's not a built-in GitHub Actions feature.