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