【问题标题】:How to find out number of commits to a GitHub repo using Octokit?如何使用 Octokit 找出对 GitHub 存储库的提交次数?
【发布时间】:2014-11-14 19:30:57
【问题描述】:

我在 GitHub 上有一个私人存储库,通过查看 Commits Graph,我可以估计今年迄今为止的提交数量约为 611。但是,我无法使用 Octokit gem 获得相同的数字。我不确定我的结果是速率受限还是页面受限,或两者兼而有之。

require 'octokit'

client = Octokit::Client.new(login: 'myuser', password: 'mypassword', auto_traversal: true)
commits = client.list_commits('my-repo')

puts commits.size # 30 but should be 611

commits.each do |c|
  puts "#{c.commit.committer.date}\t#{c.commit.message}\n"
end

另外,auto_traversal 似乎没有任何效果。

【问题讨论】:

    标签: ruby github octokit


    【解决方案1】:

    我不确定octokit 是怎么回事,不过,我切换到github_api gem 并且它有效:

    require 'github_api'
    
    
    github    = Github.new login: 'myuser', password: 'mypassword', auto_pagination: true
    commits   = github.repos.commits.all('myrepo-owner', 'myrepo-name')
    ytd_range = (Time.new(2014, 1, 1)..Time.now)
    
    ytd_commits = commits.select do |c|
      ytd_range.cover?(Time.parse(c.commit.committer.date))
    end
    
    puts ytd_commits.size # 614
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-04
      • 1970-01-01
      • 2019-10-17
      • 2017-10-05
      • 1970-01-01
      相关资源
      最近更新 更多