Increase per-page number of request + improve verbose mode (related with #33)

This commit is contained in:
Petr Korolev 2014-12-15 15:19:56 +02:00
parent 69dd5eadc2
commit c697c6be4a

View File

@ -14,6 +14,8 @@ module GitHubChangelogGenerator
attr_accessor :options, :all_tags, :github attr_accessor :options, :all_tags, :github
PER_PAGE_NUMBER = 100
def initialize def initialize
@options = Parser.parse_options @options = Parser.parse_options
@ -27,9 +29,10 @@ module GitHubChangelogGenerator
github_token github_token
if @github_token.nil? if @github_token.nil?
@github = Github.new @github = Github.new per_page: PER_PAGE_NUMBER
else else
@github = Github.new oauth_token: @github_token @github = Github.new oauth_token: @github_token,
per_page: PER_PAGE_NUMBER
end end
@generator = Generator.new(@options) @generator = Generator.new(@options)
@ -58,16 +61,21 @@ module GitHubChangelogGenerator
def get_all_closed_pull_requests def get_all_closed_pull_requests
if @options[:verbose] if @options[:verbose]
puts 'Fetching pull requests..' print "Fetching pull requests...\r"
end end
response = @github.pull_requests.list @options[:user], @options[:project], :state => 'closed' response = @github.pull_requests.list @options[:user], @options[:project], :state => 'closed'
pull_requests = [] pull_requests = []
page_i = 0
response.each_page do |page| response.each_page do |page|
print "Fetching pull requests... #{page_i}\r"
page_i += PER_PAGE_NUMBER
pull_requests.concat(page) pull_requests.concat(page)
end end
print "\r"
if @options[:verbose] if @options[:verbose]
puts "Received closed pull requests: #{pull_requests.count}" puts "Received closed pull requests: #{pull_requests.count}"
end end
@ -184,16 +192,19 @@ module GitHubChangelogGenerator
def get_all_tags def get_all_tags
if @options[:verbose] if @options[:verbose]
puts 'Fetching all tags..' print "Fetching tags...\r"
end end
response = @github.repos.tags @options[:user], @options[:project] response = @github.repos.tags @options[:user], @options[:project]
tags = [] tags = []
page_i = 0
response.each_page do |page| response.each_page do |page|
print "Fetching tags... #{page_i}\r"
page_i += PER_PAGE_NUMBER
tags.concat(page) tags.concat(page)
end end
print "\r"
if @options[:verbose] if @options[:verbose]
puts "Found #{tags.count} tags" puts "Found #{tags.count} tags"
end end