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 507b89c665
commit 3cf2802d9a

View File

@ -31,6 +31,7 @@ module GitHubChangelogGenerator
@client = client_type.new(@github_options)
end
# Fetch all tags from repo
#
# @return [Array] array of tags
@ -46,7 +47,10 @@ module GitHubChangelogGenerator
# @return [Integer] number of pages for this API call in total
def calculate_pages(client, method, request_options)
# 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))
end
last_response = client.last_response
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",
:filter => "all",
:labels => nil,
:since => @since,
}
options[:since] = @since unless @since.nil?
begin
page_i = 0
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
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:
issues.partition do |x|
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]
end
begin
page_i = 0
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)
end
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
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_slice.each do |issue|
threads << Thread.new do
begin
issue[:events] = []
iterate_pages(@client, 'issue_events', issue['number'], {}) do |new_event|
issue[:events].concat(new_event)
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}")
i += 1
end
@ -186,20 +177,19 @@ Make sure, that you push tags to remote repo via 'git push --tags'".yellow
# @param [Hash] tag
# @return [Time] time of specified tag
def fetch_date_of_tag(tag)
begin
commit_data = @client.commit(user_project, tag['commit']['sha'])
commit_data = check_github_response { @client.commit(user_project, tag['commit']['sha']) }
commit_data[:commit][:committer][:date]
rescue
Helper.log.warn GH_RATE_LIMIT_EXCEEDED_MSG.yellow
end
end
# Fetch commit for specified event
#
# @return [Hash]
def fetch_commit(event)
check_github_response do
@client.commit(user_project, event[:commit_id])
end
end
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))
pages = 1
check_github_response do
client.send(method, user_project, *args)
end
last_response = client.last_response
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?
pages +=1
last_response = next_one.get
last_response = check_github_response { next_one.get }
yield last_response.data
end