fixed some bugs and how errors were rescued

This commit is contained in:
Andrew Waage 2016-05-18 15:35:38 -07:00 committed by Olle Jonsson
parent d7b88a521a
commit df510ef183

View File

@ -31,6 +31,7 @@ module GitHubChangelogGenerator
@client = client_type.new(@github_options) @client = client_type.new(@github_options)
end end
# Fetch all tags from repo # Fetch all tags from repo
# #
# @return [Array] array of tags # @return [Array] array of tags
@ -46,7 +47,10 @@ module GitHubChangelogGenerator
# @return [Integer] number of pages for this API call in total # @return [Integer] number of pages for this API call in total
def calculate_pages(client, method, request_options) def calculate_pages(client, method, request_options)
# Makes the first API call so that we can call last_response # Makes the first API call so that we can call last_response
check_github_response do
client.send(method, user_project, @request_options.merge(request_options)) client.send(method, user_project, @request_options.merge(request_options))
end
last_response = client.last_response last_response = client.last_response
if last_pg = last_response.rels[:last] if last_pg = last_response.rels[:last]
@ -92,10 +96,9 @@ Make sure, that you push tags to remote repo via 'git push --tags'".yellow
:state => "closed", :state => "closed",
:filter => "all", :filter => "all",
:labels => nil, :labels => nil,
:since => @since,
} }
options[:since] = @since unless @since.nil?
begin
page_i = 0 page_i = 0
count_pages = calculate_pages(@client, 'issues', options) count_pages = calculate_pages(@client, 'issues', options)
@ -108,10 +111,6 @@ Make sure, that you push tags to remote repo via 'git push --tags'".yellow
print_empty_line print_empty_line
Helper.log.info "Received issues: #{issues.count}" Helper.log.info "Received issues: #{issues.count}"
rescue
Helper.log.warn GH_RATE_LIMIT_EXCEEDED_MSG.yellow
end
# separate arrays of issues and pull requests: # separate arrays of issues and pull requests:
issues.partition do |x| issues.partition do |x|
x[:pull_request].nil? x[:pull_request].nil?
@ -129,7 +128,6 @@ Make sure, that you push tags to remote repo via 'git push --tags'".yellow
options[:base] = @options[:release_branch] options[:base] = @options[:release_branch]
end end
begin
page_i = 0 page_i = 0
count_pages = calculate_pages(@client, 'pull_requests', options) count_pages = calculate_pages(@client, 'pull_requests', options)
@ -140,11 +138,8 @@ Make sure, that you push tags to remote repo via 'git push --tags'".yellow
pull_requests.concat(new_pr) pull_requests.concat(new_pr)
end end
print_empty_line print_empty_line
rescue
Helper.log.warn GH_RATE_LIMIT_EXCEEDED_MSG.yellow
end
Helper.log.info "Fetching merged dates: #{pull_requests.count}" Helper.log.info "Pull Request count: #{pull_requests.count}"
pull_requests pull_requests
end end
@ -159,14 +154,10 @@ Make sure, that you push tags to remote repo via 'git push --tags'".yellow
issues.each_slice(MAX_THREAD_NUMBER) do |issues_slice| issues.each_slice(MAX_THREAD_NUMBER) do |issues_slice|
issues_slice.each do |issue| issues_slice.each do |issue|
threads << Thread.new do threads << Thread.new do
begin
issue[:events] = [] issue[:events] = []
iterate_pages(@client, 'issue_events', issue['number'], {}) do |new_event| iterate_pages(@client, 'issue_events', issue['number'], {}) do |new_event|
issue[:events].concat(new_event) issue[:events].concat(new_event)
end end
rescue
Helper.log.warn GH_RATE_LIMIT_EXCEEDED_MSG.yellow
end
print_in_same_line("Fetching events for issues and PR: #{i + 1}/#{issues.count}") print_in_same_line("Fetching events for issues and PR: #{i + 1}/#{issues.count}")
i += 1 i += 1
end end
@ -186,20 +177,19 @@ Make sure, that you push tags to remote repo via 'git push --tags'".yellow
# @param [Hash] tag # @param [Hash] tag
# @return [Time] time of specified tag # @return [Time] time of specified tag
def fetch_date_of_tag(tag) def fetch_date_of_tag(tag)
begin commit_data = check_github_response { @client.commit(user_project, tag['commit']['sha']) }
commit_data = @client.commit(user_project, tag['commit']['sha'])
commit_data[:commit][:committer][:date] commit_data[:commit][:committer][:date]
rescue
Helper.log.warn GH_RATE_LIMIT_EXCEEDED_MSG.yellow
end
end end
# Fetch commit for specified event # Fetch commit for specified event
# #
# @return [Hash] # @return [Hash]
def fetch_commit(event) def fetch_commit(event)
check_github_response do
@client.commit(user_project, event[:commit_id]) @client.commit(user_project, event[:commit_id])
end end
end
private private
@ -219,7 +209,10 @@ Make sure, that you push tags to remote repo via 'git push --tags'".yellow
args.push(@request_options.merge(request_options)) args.push(@request_options.merge(request_options))
pages = 1 pages = 1
check_github_response do
client.send(method, user_project, *args) client.send(method, user_project, *args)
end
last_response = client.last_response last_response = client.last_response
yield last_response.data yield last_response.data
@ -227,7 +220,7 @@ Make sure, that you push tags to remote repo via 'git push --tags'".yellow
while !(next_one = last_response.rels[:next]).nil? while !(next_one = last_response.rels[:next]).nil?
pages +=1 pages +=1
last_response = next_one.get last_response = check_github_response { next_one.get }
yield last_response.data yield last_response.data
end end