4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

GitHub API で メンバーごとにPullRequest回数をカウント

Last updated at Posted at 2014-12-26

Pull Request をメンバごとにカウントするため、
GitHub APIを使ってみた。


require 'net/http'
require 'uri'
require 'json'
 
uri = URI.parse('http://XXXXXXXX/api/v3/repositories')
json = Net::HTTP.get(uri)
result = JSON.parse(json)
 
puts 'repos, created_at, html_url, user.login'
pullreq = {}
 
result.each{|var|
  repos = var['full_name']
  page = 1
 
  begin
    reposUri = URI.parse("http://XXXXXXXX/api/v3/repos/#{repos}/pulls?state=all&per_page=100&page=#{page}")
    reposJson = Net::HTTP.get(reposUri)
    reposResult = JSON.parse(reposJson)
 
    reposResult.each{|reposVar|
      if reposVar['created_at'] > '2014-09'
        puts "#{repos}, #{reposVar['created_at']}, #{reposVar['html_url']}, #{reposVar['user']['login']}"
        pullreq["#{reposVar['user']['login']}"] = 0 unless pullreq.key?("#{reposVar['user']['login']}")
        pullreq["#{reposVar['user']['login']}"] += 1
      else
        break
      end
    }
    page += 1
  end while page <= 10
}
 
puts ''
 
pullreq.sort{ |(k1,v1),(k2,v2)| v2<=>v1 }
       .each{ |k,v| puts "#{k}:#{v}" }

参考

all public repositories

参考:list-all-public-repositories

list-pull-requests

参考:list-pull-requests

感想

  • GUIにてプルリクMAX(Num)を確認してとりあえず「page <= 10」とした。
4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?