0

My workflow's script with action/github-script(v6) step:

const response = await github.request('POST https://example.com', {
  headers: {
    authorization: 'Bearer xxx',
    accept: 'application/vnd.heroku+json; version=3', // I want header to be like this
    'content-type': 'application/json'
  },
  // some other options, like request body...
});
console.log(response);

When the accept and other HTTP headers are automatically overriden with:

{
  status: 400,
  reponse: {}, // not important, body complains about incorrect Accept header
  request: {
    method: 'POST',
    url: 'example.com',
    headers: {
      accept: 'application/vnd.github.-preview+json', // wtf?
      authorization: 'token [REDACTED]', // wtf? it should start with "Bearer"
      'content-type': 'application/json', // ok, as expected
      'user-agent': 'actions/github-script octokit-core.js/3.5.1 Node.js/16.13.0 (linux; x64)' // ok, but I didn't set this...
    },
  // other stuff...
}

Now the question is what am I missing? Can I make truthly custom request using github.request() api like that?

tlenex
  • 488
  • 1
  • 5
  • 13
  • For what I checked [in this function](https://github.com/actions/github-script/blob/46a476b63873db13c0e745b5ff456324742dfe00/dist/index.js#L5812), it overwrites the header using `token` instead of `bearer` depending on the condition. Regarding the `accept` header, it's always added by default to all request using the action ([example in the Post function](https://github.com/actions/github-script/blob/46a476b63873db13c0e745b5ff456324742dfe00/dist/index.js#L6185)). The `user-agent` seems to be default as well depending on the request (L10529 in the same file) – GuiFalourd Jun 30 '22 at 14:48
  • Yup I saw that too, but I didn't found any solution to enforce custom headers. It feels clunky to use `curl` bash script for this... – tlenex Jul 01 '22 at 06:07
  • I usually create my own scripts (generally using python) to perform this kind of operation. I feel more secure as an action tag can be updated without the users knowing. – GuiFalourd Jul 01 '22 at 11:21

0 Answers0