octokit / rest.js

GitHub REST API client for JavaScript
https://octokit.github.io/rest.js
MIT License
548 stars 63 forks source link

[BUG]: Creating deployments fail with "Request body length does not match content-length header" on renamed repos #405

Open NiklasMerz opened 8 months ago

NiklasMerz commented 8 months ago

What happened?

I updated my very old octokit and nodejs version to the most recent ones and creating deployments now fails.

The repo got renamed and the action was using the old name.

Some code:

let options = {
  auto_merge: false,
  owner: 'myorga',
  repo: 'myproject',
  ref: 'develop',
  environment: 'testing'
}

async function createDeployment(options) {
    options.task = 'deploy';
    options.required_contexts = [];
    let result = await octokit.rest.repos.createDeployment(options)
    const id = result.data.id;
    console.log(id);
    fs.writeFileSync(process.env.HOME + '/deployment_action', id);

    console.log(result.status == 201 ? 'Done': 'Error');
    if(result.status != 201) {
        console.error(result);
        process.exit(1);
    }
}

Versions

octokit-rest.js/20.0.2 octokit-core.js/5.1.0 Node.js/18.19.0 (linux; x64)',

Relevant log output

/node_modules/@octokit/request/dist-node/index.js:156
    throw new import_request_error.RequestError(message, 500, {
          ^

RequestError [HttpError]: Request body length does not match content-length header
    at /node_modules/@octokit/request/dist-node/index.js:156:11
    at async createDeployment (/usr/bin/deployment.js:13:18) {
  status: 500,
  request: {
    method: 'POST',
    url: 'https://api.github.com/repos/pragmaticindustries/ukonn-wizard/deployments',
    headers: {
      accept: 'application/vnd.github.v3+json',
      'user-agent': 'octokit-rest.js/20.0.2 octokit-core.js/5.1.0 Node.js/18.19.0 (linux; x64)',
      authorization: 'token [REDACTED]',
      'content-type': 'application/json; charset=utf-8'
    },
    body: '{"auto_merge":false,"ref":"develop","environment":"testing","task":"deploy","required_contexts":[]}',
    request: { hook: [Function: bound bound register] }
  }
}

Code of Conduct

github-actions[bot] commented 8 months ago

👋 Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labled with Status: Up for grabs. You & others like you are the reason all of this works! So thank you & happy coding! 🚀

NiklasMerz commented 8 months ago

After finding this issue https://github.com/semantic-release/github/issues/746 I realized we renamed the repo and the workflow used the old name. Strange error but this fixes it.

wolfy1339 commented 8 months ago

Maybe this warrants a mention in the docs? Or maybe there is a fix that we can do on our side to avoid the error