【问题标题】:How to fetch single repository from octokit gem?如何从 octokit gem 获取单个存储库?
【发布时间】:2016-03-07 07:07:54
【问题描述】:

我是红宝石的初学者 我正在尝试从“octokit gem”中获取数据 我需要使用它的 id 的单个存储库的信息,

我尝试了一个简单的代码,但它列出了我的所有存储库

require 'octokit'


=> true
2.2.4 :003 > user = Octokit.user 'parth1634'
 => {:login=>"parth1634", :id=>8487101, :avatar_url=>"https://avatars.githubusercontent.com/u/8487101?v=3", :gravatar_id=>"", :url=>"https://api.github.com/users/parth1634", :html_url=>"https://github.com/parth1634", :followers_url=>"https://api.github.com/users/parth1634/followers", :following_url=>"https://api.github.com/users/parth1634/following{/other_user}", :gists_url=>"https://api.github.com/users/parth1634/gists{/gist_id}", :starred_url=>"https://api.github.com/users/parth1634/starred{/owner}{/repo}", :subscriptions_url=>"https://api.github.com/users/parth1634/subscriptions", :organizations_url=>"https://api.github.com/users/parth1634/orgs", :repos_url=>"https://api.github.com/users/parth1634/repos", :events_url=>"https://api.github.com/users/parth1634/events{/privacy}", :received_events_url=>"https://api.github.com/users/parth1634/received_events", :type=>"User", :site_admin=>false, :name=>"Parth Patel", :company=>"BoTree Technologies.Pvt.Ltd", :blog=>"https://parthpatelsblog.wordpress.com/", :location=>"Visnagar, Gujarat.", :email=>"parth1634@gmail.com", :hireable=>nil, :bio=>nil, :public_repos=>10, :public_gists=>1, :followers=>3, :following=>6, :created_at=>2014-08-19 05:23:02 UTC, :updated_at=>2016-03-02 04:22:46 UTC}
2.2.4 :004 > repos = user.rels[:repos].get.data

【问题讨论】:

    标签: ruby-on-rails ruby ruby-on-rails-4 rubygems octokit


    【解决方案1】:

    看起来您当前的代码返回了您拥有的 11 个存储库的数据。如果您只想返回您指定 :id 的一个数据的数据,请执行以下操作:

    repos = user.rels[:repos].get.data.select {|r| r[:id] == 35797521 }
    

    替换为您要查找的实际 id!

    【讨论】:

      猜你喜欢
      • 2019-10-17
      • 2016-07-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-05
      • 2011-11-19
      • 1970-01-01
      • 2019-09-30
      • 2011-04-08
      相关资源
      最近更新 更多