gr2m / octokit-plugin-create-pull-request

Octokit plugin to create a pull request with multiple file changes
MIT License
104 stars 28 forks source link

File Size Limit? #119

Closed wilbooorn closed 1 year ago

wilbooorn commented 1 year ago

Hi there - is there a limit to the size of a file that can be sent? I'm trying to use the plugin to open a PR to change a ~1500 line YAML file, and I'm getting a socket hang-up every time. When I update the request to only send about 25% of the file, it succeeds (which is what leads me to believe the file size may be the issue). It always fails on the /trees call. See the error below, unfortunately I don't have any other useful error info. Any tips/ideas would be greatly appreciated!

RequestError [HttpError]: request to https://github.xxx.co/api/v3/repos/xxx/xxx/git/trees failed, reason: socket hang up
    at /Users/robin.wilborn/DSS/Dev/responder-file/node_modules/@octokit/request/dist-node/index.js:99:11
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async createTree (/Users/robin.wilborn/DSS/Dev/responder-file/node_modules/octokit-plugin-create-pull-request/dist-node/index.js:138:7)
    at async composeCreatePullRequest (/Users/robin.wilborn/DSS/Dev/responder-file/node_modules/octokit-plugin-create-pull-request/dist-node/index.js:244:35)
    at async createReportingPull (/Users/robin.wilborn/DSS/Dev/responder-file/app/serve/build/handlers/github.js:46:26)
    at async Promise.all (index 0)
    at async saveConfigController (/Users/robin.wilborn/DSS/Dev/responder-file/app/serve/build/handlers/saveConfig.js:21:32) {
  status: 500,

Octokit code:

import { Octokit as BaseOctokit } from '@octokit/core';
import { createPullRequest } from 'octokit-plugin-create-pull-request';

const Octokit = BaseOctokit.plugin(createPullRequest);

const octokitClient = new Octokit({
  auth: TOKEN,
  baseUrl: GITHUB_BASE_URL,
});

export const createReportingPull = async (configFile: string) => {
  try {
    const response = await octokitClient.createPullRequest({
      body: 'Pull request body',
      changes: [
        {
          files: {
            'directory/config.yml': configFile,
          },
          commit: 'update config',
        },
      ],
      head: `config-update-${Date.now().toString()}`,
      owner: 'xxx', // Using actual value here
      repo: 'xxx', // Using actual value here
      title: 'Config Update',
    });

    return !!response;
  } catch (e) {
    console.log(e);
    return false;
  }
};
gr2m commented 1 year ago

I'm pretty sure there is some limit, but none is documented here: https://docs.github.com/en/rest/git/trees?apiVersion=2022-11-28#create-a-tree

The use of GITHUB_BASE_URL suggests you use a GitHub Enterprise Server version? These often times permit you to customize limits like this.

I can't really help until you have a script that reliably replicates the problem

wilbooorn commented 1 year ago

Hey @gr2m thanks for the reply! I ended up doing all the steps to create a PR manually (basically doing everything this plugin does under the hood), and I was able to get it to work. Still not sure what the issue was, but I guess my problem is solved 😅 Thanks again!