我是Ruby的初学者我正在尝试从"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
看起来当前代码返回了您拥有的 11 个存储库的数据。如果只想返回为其指定 :id 的一个数据的数据,请执行以下操作:
repos = user.rels[:repos].get.data.select {|r| r[:id] == 35797521 }
替换为您要查找的实际 ID!