ruby-on-rails - GitHub API : Cannot reliably add files to repository

标签 ruby-on-rails github github-api octokit

我在使用 Octokit Ruby 的 GitHub API 中遇到了一个非常奇怪的错误图书馆。只有有时 API 请求将新文件添加到存储库失败,并显示以下消息:

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'

以下是我尝试将整个文件夹的内容上传到 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

如果发生错误,它将在第一次尝试上传文件时执行。


编辑:

我发现只有当第一个上传的文件是.xml文件时才会出现这个错误。

另外我经常得到...

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

... 用于其他文件,但也用于相同的存储库。


我做错了什么?

最佳答案

确保文件夹中没有同名文件。 在这种情况下,您正在编辑文件而不是创建文件。

关于ruby-on-rails - GitHub API : Cannot reliably add files to repository,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49364692/

相关文章:

ruby-on-rails - Rails Rpec InvalidCrossOriginRequest

github - Github Action ,摇晃。 git log的pretty = format标志不起作用

git - 导出 github 存储库

javascript - cURL 和 jQuery AJAX 之间的 GitHub API 结果不同

json - Angular 4 从 github api 获取数据

github-api - 如何使用 Github v3 API 找到存储库的默认分支

ruby-on-rails - rails : Check has_many in View

ruby-on-rails - 在haml中使用Rails助手,传递散列会导致语法错误

javascript - 在 Rails 应用程序中隐藏标签云

git - 如何为 github 存储库设置 CIAbot