3

I experience a very weird error with the GitHub API using the Octokit Ruby library. Only sometimes API requests to add new files to a repository fail with the following message:

Octokit::UnprocessableEntity: PUT https://api.github.com/repos/organization/repo/contents/config.xml: 422 - Invalid request.

"sha" wasn't supplied. // See: https://developer.github.com/v3/repos/contents/#update-a-file
from C:/Dev/RailsInstaller/Ruby2.3.3/lib/ruby/gems/2.3.0/gems/octokit-4.8.0/lib/octokit/response/raise_error.rb:16:in `on_complete'

Here is how I am trying to upload the contents of an entire folder to GitHub:

Dir.glob(folder + '/**/*') do |path|
  next if File.directory?(path)
  octokit_client.create_contents 'organization/repo', path.sub("#{folder}/", ''), '', File.read(path), branch: 'master'
end

If an error occurs, it does so with the first attempt to upload a file.


Edit:

I found that the error only occurs when the first file uploaded is a .xml file.

Additionally I often get ...

Octokit::RepositoryUnavailable
PUT https://api.github.com/repos/organization/repo/contents/icon/_60x60_at1x.png: 403 - Repository access blocked

... for other files but the same repository as well.


What am I doing wrong?

heroxav
  • 1,387
  • 1
  • 22
  • 65

1 Answers1

1

Make sure you don't have a file with the same name in the folder. In this case, you are editing a file and not creating one.

Eylon Koenig
  • 13
  • 1
  • 4