Merge branch 'feature/increase-per-page' into develop

This commit is contained in:
Petr Korolev 2014-12-15 15:33:28 +02:00
commit 950e8916d9

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
@ -345,16 +356,22 @@ module GitHubChangelogGenerator
def get_all_issues def get_all_issues
if @options[:verbose] if @options[:verbose]
puts 'Fetching closed issues..' puts "Fetching closed issues...\r"
end end
response = @github.issues.list user: @options[:user], repo: @options[:project], state: 'closed', filter: 'all', labels: nil response = @github.issues.list user: @options[:user], repo: @options[:project], state: 'closed', filter: 'all', labels: nil
issues = [] issues = []
page_i = 0
response.each_page do |page| response.each_page do |page|
print "Fetching closed issues... #{page_i}\r"
page_i += PER_PAGE_NUMBER
pull_requests.concat(page)
issues.concat(page) issues.concat(page)
end end
print "\r"
# remove pull request from issues: # remove pull request from issues:
issues.select! { |x| issues.select! { |x|
x.pull_request == nil x.pull_request == nil