print error more descriptive

This commit is contained in:
Petr Korolev 2015-05-18 09:26:36 +03:00
parent c67cbb31f2
commit 866c9f95d3

View File

@ -23,7 +23,7 @@ module GitHubChangelogGenerator
@logger.formatter = proc do |_severity, _datetime, _progname, msg| @logger.formatter = proc do |_severity, _datetime, _progname, msg|
"#{msg}\n" "#{msg}\n"
end end
github_options = { per_page: PER_PAGE_NUMBER } github_options = {per_page: PER_PAGE_NUMBER}
github_options[:oauth_token] = @github_token unless @github_token.nil? github_options[:oauth_token] = @github_token unless @github_token.nil?
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?
@ -60,30 +60,39 @@ module GitHubChangelogGenerator
tags = [] tags = []
begin begin
response = @github.repos.tags @options[:user], @options[:project] github_fetch_tags(tags)
page_i = 0 rescue Github::Error::Unauthorized => e
count_pages = response.count_pages @logger.error e.body.red
response.each_page do |page| @logger.error "Error: wrong github token provided".red
page_i += PER_PAGE_NUMBER rescue Github::Error::Forbidden => e
print "Fetching tags... #{page_i}/#{count_pages * PER_PAGE_NUMBER}\r" @logger.warn e.body.red
tags.concat(page) unless @options[:token].nil?
@logger.warn GH_RATE_LIMIT_EXCEEDED_MSG.yellow
end end
print " \r"
if tags.count == 0
@logger.warn "Warning: Can't find any tags in repo.\
Make sure, that you push tags to remote repo via 'git push --tags'".yellow
elsif @options[:verbose]
@logger.info "Found #{tags.count} tags"
end
rescue
@logger.warn GH_RATE_LIMIT_EXCEEDED_MSG.yellow
end end
tags tags
end end
def github_fetch_tags(tags)
response = @github.repos.tags @options[:user], @options[:project]
page_i = 0
count_pages = response.count_pages
response.each_page do |page|
page_i += PER_PAGE_NUMBER
print "Fetching tags... #{page_i}/#{count_pages * PER_PAGE_NUMBER}\r"
tags.concat(page)
end
print " \r"
if tags.count == 0
@logger.warn "Warning: Can't find any tags in repo.\
Make sure, that you push tags to remote repo via 'git push --tags'".yellow
elsif @options[:verbose]
@logger.info "Found #{tags.count} tags"
end
end
# This method fetch all closed issues and separate them to pull requests and pure issues # This method fetch all closed issues and separate them to pull requests and pure issues
# (pull request is kind of issue in term of GitHub) # (pull request is kind of issue in term of GitHub)
# @return [Tuple] with issues and pull requests # @return [Tuple] with issues and pull requests
@ -108,6 +117,8 @@ Make sure, that you push tags to remote repo via 'git push --tags'".yellow
break if @options[:max_issues] && issues.length >= @options[:max_issues] break if @options[:max_issues] && issues.length >= @options[:max_issues]
end end
rescue rescue
puts e.message
puts e.backtrace.inspect
@logger.warn GH_RATE_LIMIT_EXCEEDED_MSG.yellow @logger.warn GH_RATE_LIMIT_EXCEEDED_MSG.yellow
end end