我正在尝试使用githubapi为github仓库创建webhook,因为我正在使用Github_api gem
我写了创建钩子的帖子请求

github = Github.new
github.repos.hooks.create 'user-name', 'repo-name',
name:  "web",
active: true,
events: ['push','pull-request'],
config: {
url: "http://localhost:3000/payload",
content_type: "json"
}


但我得到以下错误

Github::Error::NotFound: POST https://api.github.com/repos/user-name/repo-name/hooks: 404 Not Found
from /home/kamal-ubuntu/.rvm/gems/ruby-2.1.5/gems/github_api-0.12.2/lib/github_api/response/raise_error.rb:14:in `on_complete'
from /home/kamal-ubuntu/.rvm/gems/ruby-2.1.5/gems/faraday-0.9.0/lib/faraday/response.rb:9:in `block in call'
from /home/kamal-ubuntu/.rvm/gems/ruby-2.1.5/gems/faraday-0.9.0/lib/faraday/response.rb:57:in `on_complete'
from /home/kamal-ubuntu/.rvm/gems/ruby-2.1.5/gems/faraday-0.9.0/lib/faraday/response.rb:8:in `call'
from /home/kamal-ubuntu/.rvm/gems/ruby-2.1.5/gems/faraday-0.9.0/lib/faraday/response.rb:8:in `call'
from /home/kamal-ubuntu/.rvm/gems/ruby-2.1.5/gems/faraday-0.9.0/lib/faraday/response.rb:8:in `call'
from /home/kamal-ubuntu/.rvm/gems/ruby-2.1.5/gems/faraday-0.9.0/lib/faraday/request/url_encoded.rb:15:in `call'
from /home/kamal-ubuntu/.rvm/gems/ruby-2.1.5/gems/faraday-0.9.0/lib/faraday/request/multipart.rb:14:in `call'
from /home/kamal-ubuntu/.rvm/gems/ruby-2.1.5/gems/github_api-0.12.2/lib/github_api/request/jsonize.rb:23:in `call'
from /home/kamal-ubuntu/.rvm/gems/ruby-2.1.5/gems/faraday-0.9.0/lib/faraday/rack_builder.rb:139:in `build_response'
from /home/kamal-ubuntu/.rvm/gems/ruby-2.1.5/gems/faraday-0.9.0/lib/faraday/connection.rb:377:in `run_request'
from /home/kamal-ubuntu/.rvm/gems/ruby-2.1.5/gems/faraday-0.9.0/lib/faraday/connection.rb:177:in `post'
from /home/kamal-ubuntu/.rvm/gems/ruby-2.1.5/gems/github_api-0.12.2/lib/github_api/request.rb:68:in `call'
from /home/kamal-ubuntu/.rvm/gems/ruby-2.1.5/gems/github_api-0.12.2/lib/github_api/request/verbs.rb:35:in `post_request'
from /home/kamal-ubuntu/.rvm/gems/ruby-2.1.5/gems/github_api-0.12.2/lib/github_api/client/repos/hooks.rb:122:in `create'
from /home/kamal-ubuntu/.rvm/gems/ruby-2.1.5/gems/github_api-0.12.2/lib/github_api/api.rb:224:in `block in execute'

最佳答案

对GitHub api的所有请求都应得到授权。


Typically, we send a 404 error when your client isn’t properly authenticated. You might expect to see a 403 Forbidden in these cases. However, since we don’t want to provide any information about private repositories, the API returns a 404 error instead.


根据documentation,您应该首先配置客户端:

github = Github.new basic_auth: 'login:password'

10-04 14:28