Gitlab的API(GET / projects /:id / repository / tree)抛出404页面未找到

时间:2013-06-13 07:38:15

标签: git gitlab

根据GitLabs API文档通过restful api调用获取存储库树我应该执行以下操作,这段摘录来自可以找到的文档here,它说

  

列出存储库树

     

获取项目中的存储库文件和目录列表。

     

GET / projects /:id / repository / tree参数:

     

id(必填) - 项目的ID

     

path(可选) - 存储库中的路径。用于争夺子目录

     

ref_name(可选) - 存储库分支或标记的名称,如果没有给出默认分支

但是当我打电话给上面的网络服务时,它会返回

  

404您要查找的页面不存在。

我打电话给http://myserverurl/api/v3/projects/:id/repository/tree?private_token=myprivatetoken然后我得到404,当然我在这里传递了项目的id,这是一个像4,5,6等的整数。

所有其他API的工作正常,除了这个,我在这里缺少什么?

这些是production.log文件

中的错误日志
Started GET
"/api/v3/projects/:id/repository/tree?private_token=mytoken&id=4" for
at 2013-06-13 12:48:36 +0530 ActionController::RoutingError (No route
matches [GET] "/api/v3/projects/:id/repository/tree"):
vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.13/lib/action_dispatch/middleware/debug_exceptions.rb:21:in
`call'
vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.13/lib/action_dispatch/middleware/show_exceptions.rb:56:in
`call'
vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/rack/logger.rb:32:in
`call_app'
vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/rack/logger.rb:16:in
`block in call'
vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/tagged_logging.rb:22:in
`tagged'
vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/rack/logger.rb:16:in
`call'
vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.13/lib/action_dispatch/middleware/request_id.rb:22:in
`call'
vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/methodoverride.rb:21:in
`call'
vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/runtime.rb:17:in
`call' vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/lock.rb:15:in
`call'
vendor/bundle/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:136:in
`forward'
vendor/bundle/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:245:in
`fetch'
vendor/bundle/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:185:in
`lookup'
vendor/bundle/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:66:in
`call!'
vendor/bundle/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:51:in
`call'
vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/engine.rb:479:in
`call'
vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/application.rb:223:in
`call'
vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/railtie/configurable.rb:30:in
`method_missing'
vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/builder.rb:134:in
`call'
vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/urlmap.rb:64:in
`block in call'
vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/urlmap.rb:49:in
`each'
vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/urlmap.rb:49:in
`call'
vendor/bundle/ruby/1.9.1/gems/puma-2.0.1/lib/puma/configuration.rb:66:in
`call'
vendor/bundle/ruby/1.9.1/gems/puma-2.0.1/lib/puma/server.rb:364:in
`handle_request'
vendor/bundle/ruby/1.9.1/gems/puma-2.0.1/lib/puma/server.rb:243:in
`process_client'
vendor/bundle/ruby/1.9.1/gems/puma-2.0.1/lib/puma/server.rb:142:in
`block in run'
vendor/bundle/ruby/1.9.1/gems/puma-2.0.1/lib/puma/thread_pool.rb:92:in
`call'
vendor/bundle/ruby/1.9.1/gems/puma-2.0.1/lib/puma/thread_pool.rb:92:in
`block in spawn_thread'

2 个答案:

答案 0 :(得分:4)

Gitlab API page ""Status Code" section提及:

404 Not Found
  

无法访问资源,例如无法找到资源的ID

因此id不正确(如果其他API调用成功则不应该这样)。

或“tree”还不够,但应提供路径(除非项目树为空)。

或者存在某种权限问题,这会在服务器上阻止API访问该存储库的内容。

但是如果任何路径的问题仍然存在,那么将该案例添加到list of GitLab issues是值得的。

正如OP提到的那样,这也是表明API在代码中不可用

答案 1 :(得分:2)

这是我的问题,我没有意识到这个api仅在1965/2013的主分支上可用,当我将我的分支从stable转为master时它解决了上述问题,切换分支I用过

  

sudo -u git -H git checkout master

然后我必须做

  

sudo bundle install

在master分支上安装一些额外的gem,然后我使用nginxgitlab重新启动sudo service nginx restartsudo service gitlab start,最后这似乎解决了我遇到的所有api问题。