Add rescue fallback with warning message to prevent crash in case of exceed Rate Limit (temporary workaround for #71)
This commit is contained in:
parent
25ee41bc8c
commit
7704dc9ecd
|
@ -27,7 +27,11 @@ module GitHubChangelogGenerator
|
|||
github_options[:endpoint] = options[:github_endpoint] unless options[:github_endpoint].nil?
|
||||
github_options[:site] = options[:github_endpoint] unless options[:github_site].nil?
|
||||
|
||||
begin
|
||||
@github = Github.new github_options
|
||||
rescue
|
||||
puts "Warning: GitHub API rate limit exceed (5000 per hour), change log may not contain some issues.".yellow
|
||||
end
|
||||
|
||||
@generator = Generator.new(@options)
|
||||
|
||||
|
@ -88,7 +92,11 @@ module GitHubChangelogGenerator
|
|||
issue[:actual_date] = issue[:closed_at]
|
||||
else
|
||||
begin
|
||||
begin
|
||||
commit = @github.git_data.commits.get @options[:user], @options[:project], event[:commit_id]
|
||||
rescue
|
||||
puts "Warning: GitHub API rate limit exceed (5000 per hour), change log may not contain some issues.".yellow
|
||||
end
|
||||
issue[:actual_date] = commit[:author][:date]
|
||||
rescue
|
||||
puts "Warning: can't fetch commit #{event[:commit_id]} probably it referenced from another repo."
|
||||
|
@ -110,9 +118,9 @@ module GitHubChangelogGenerator
|
|||
if @options[:verbose]
|
||||
print "Fetching merged dates...\r"
|
||||
end
|
||||
response = @github.pull_requests.list @options[:user], @options[:project], :state => 'closed'
|
||||
|
||||
pull_requests = []
|
||||
begin
|
||||
response = @github.pull_requests.list @options[:user], @options[:project], :state => 'closed'
|
||||
page_i = 0
|
||||
response.each_page do |page|
|
||||
page_i += PER_PAGE_NUMBER
|
||||
|
@ -120,6 +128,12 @@ module GitHubChangelogGenerator
|
|||
print "Fetching merged dates... #{page_i}/#{count_pages * PER_PAGE_NUMBER}\r"
|
||||
pull_requests.concat(page)
|
||||
end
|
||||
rescue
|
||||
puts "Warning: GitHub API rate limit exceed (5000 per hour), change log may not contain some issues.".yellow
|
||||
end
|
||||
|
||||
|
||||
|
||||
print " \r"
|
||||
|
||||
@pull_requests.each { |pr|
|
||||
|
@ -276,7 +290,11 @@ module GitHubChangelogGenerator
|
|||
end
|
||||
|
||||
def is_megred(number)
|
||||
begin
|
||||
@github.pull_requests.merged? @options[:user], @options[:project], number
|
||||
rescue
|
||||
puts "Warning: GitHub API rate limit exceed (5000 per hour), change log may not contain some issues.".yellow
|
||||
end
|
||||
end
|
||||
|
||||
def get_all_tags
|
||||
|
@ -285,9 +303,10 @@ module GitHubChangelogGenerator
|
|||
print "Fetching tags...\r"
|
||||
end
|
||||
|
||||
response = @github.repos.tags @options[:user], @options[:project]
|
||||
|
||||
tags = []
|
||||
|
||||
begin
|
||||
response = @github.repos.tags @options[:user], @options[:project]
|
||||
page_i = 0
|
||||
count_pages = response.count_pages
|
||||
response.each_page do |page|
|
||||
|
@ -299,6 +318,11 @@ module GitHubChangelogGenerator
|
|||
if @options[:verbose]
|
||||
puts "Found #{tags.count} tags"
|
||||
end
|
||||
rescue
|
||||
puts "Warning: GitHub API rate limit exceed (5000 per hour), change log may not contain some issues.".yellow
|
||||
end
|
||||
|
||||
|
||||
|
||||
tags
|
||||
end
|
||||
|
@ -512,7 +536,11 @@ module GitHubChangelogGenerator
|
|||
return @tag_times_hash[tag_name['name']]
|
||||
end
|
||||
|
||||
begin
|
||||
github_git_data_commits_get = @github.git_data.commits.get @options[:user], @options[:project], tag_name['commit']['sha']
|
||||
rescue
|
||||
puts "Warning: GitHub API rate limit exceed (5000 per hour), change log may not contain some issues.".yellow
|
||||
end
|
||||
time_string = github_git_data_commits_get['committer']['date']
|
||||
@tag_times_hash[tag_name['name']] = Time.parse(time_string)
|
||||
end
|
||||
|
@ -558,10 +586,10 @@ module GitHubChangelogGenerator
|
|||
if @options[:verbose]
|
||||
print "Fetching closed issues...\r"
|
||||
end
|
||||
|
||||
response = @github.issues.list user: @options[:user], repo: @options[:project], state: 'closed', filter: 'all', labels: nil
|
||||
|
||||
issues = []
|
||||
|
||||
begin
|
||||
response = @github.issues.list user: @options[:user], repo: @options[:project], state: 'closed', filter: 'all', labels: nil
|
||||
page_i = 0
|
||||
count_pages = response.count_pages
|
||||
response.each_page do |page|
|
||||
|
@ -569,6 +597,11 @@ module GitHubChangelogGenerator
|
|||
print "Fetching issues... #{page_i}/#{count_pages * PER_PAGE_NUMBER}\r"
|
||||
issues.concat(page)
|
||||
end
|
||||
rescue
|
||||
puts "Warning: GitHub API rate limit exceed (5000 per hour), change log may not contain some issues.".yellow
|
||||
end
|
||||
|
||||
|
||||
|
||||
print " \r"
|
||||
|
||||
|
@ -610,7 +643,11 @@ module GitHubChangelogGenerator
|
|||
issues.each_slice(max_thread_number) { |issues_slice|
|
||||
issues_slice.each { |issue|
|
||||
threads << Thread.new {
|
||||
begin
|
||||
obj = @github.issues.events.list user: @options[:user], repo: @options[:project], issue_number: issue['number']
|
||||
rescue
|
||||
puts "Warning: GitHub API rate limit exceed (5000 per hour), change log may not contain some issues.".yellow
|
||||
end
|
||||
issue[:events] = obj.body
|
||||
print "Fetching events for issues and PR: #{i+1}/#{@issues.count + @pull_requests.count}\r"
|
||||
i +=1
|
||||
|
|
Loading…
Reference in New Issue
Block a user