Merge pull request #449 from skywinder/fix/can-not-convert-sawyer-resource-to-array-448

OctoFetcher: Moved repositories fail explicitly
This commit is contained in:
Olle Jonsson 2016-11-11 00:44:09 +01:00 committed by GitHub
commit 92137ba0b2
4 changed files with 34 additions and 21 deletions

View File

@ -17,11 +17,11 @@ matrix:
gemfile: gemfiles/Gemfile.2_1 gemfile: gemfiles/Gemfile.2_1
- rvm: 2.3.1 - rvm: 2.3.1
gemfile: gemfiles/Gemfile.2_3_1 gemfile: gemfiles/Gemfile.2_3_1
- rvm: 2.4.0-preview2 - rvm: 2.4.0-preview3
gemfile: gemfiles/Gemfile.2_4_0 gemfile: gemfiles/Gemfile.2_4_0
- rvm: jruby-9.1.5.0 - rvm: jruby-9.1.6.0
jdk: oraclejdk8 jdk: oraclejdk8
gemfile: gemfiles/Gemfile.jruby-9.1.5.0 gemfile: gemfiles/Gemfile.jruby-9.1
env: env:
- JRUBY_OPTS=--debug - JRUBY_OPTS=--debug

View File

@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
spec.add_runtime_dependency "rake", ">= 10.0" spec.add_runtime_dependency "rake", ">= 10.0"
spec.add_runtime_dependency "rainbow", ">= 2.1" spec.add_runtime_dependency "rainbow", ">= 2.1"
spec.add_runtime_dependency("octokit", ["~> 4.0"]) spec.add_runtime_dependency("octokit", ["~> 4.6"])
spec.add_runtime_dependency("faraday-http-cache") spec.add_runtime_dependency("faraday-http-cache")
spec.add_runtime_dependency("activesupport") spec.add_runtime_dependency("activesupport")
spec.add_runtime_dependency("retriable", ["~> 2.1"]) spec.add_runtime_dependency("retriable", ["~> 2.1"])

View File

@ -103,7 +103,7 @@ module GitHubChangelogGenerator
print_empty_line print_empty_line
if tags.count == 0 if tags.count == 0
Helper.log.warn "Warning: Can't find any tags in repo.\ Helper.log.warn "Warning: Can't find any tags in repo. \
Make sure, that you push tags to remote repo via 'git push --tags'" Make sure, that you push tags to remote repo via 'git push --tags'"
else else
Helper.log.info "Found #{tags.count} tags" Helper.log.info "Found #{tags.count} tags"
@ -244,38 +244,49 @@ Make sure, that you push tags to remote repo via 'git push --tags'"
end end
end end
MovedPermanentlyError = Class.new(RuntimeError)
# Iterates through all pages until there are no more :next pages to follow # Iterates through all pages until there are no more :next pages to follow
# yields the result per page # yields the result per page
# #
# @param [Octokit::Client] client # @param [Octokit::Client] client
# @param [String] method (eg. 'tags') # @param [String] method (eg. 'tags')
#
# @yield [Sawyer::Resource] An OctoKit-provided response (which can be empty)
#
# @return [Integer] total number of pages # @return [Integer] total number of pages
def iterate_pages(client, method, *args) def iterate_pages(client, method, *args)
if args.size == 1 && args.first.is_a?(Hash) request_opts = extract_request_args(args)
request_options = args.delete_at(0) args.push(@request_options.merge(request_opts))
elsif args.size > 1 && args.last.is_a?(Hash)
request_options = args.delete_at(args.length - 1)
end
args.push(@request_options.merge(request_options)) number_of_pages = 1
pages = 1 check_github_response { client.send(method, user_project, *args) }
check_github_response do
client.send(method, user_project, *args)
end
last_response = client.last_response last_response = client.last_response
if last_response.status == 301
raise MovedPermanentlyError, last_response.data[:url]
end
yield last_response.data yield(last_response.data)
until (next_one = last_response.rels[:next]).nil? until (next_one = last_response.rels[:next]).nil?
pages += 1 number_of_pages += 1
last_response = check_github_response { next_one.get } last_response = check_github_response { next_one.get }
yield last_response.data yield(last_response.data)
end end
pages number_of_pages
end
def extract_request_args(args)
if args.size == 1 && args.first.is_a?(Hash)
args.delete_at(0)
elsif args.size > 1 && args.last.is_a?(Hash)
args.delete_at(args.length - 1)
else
{}
end
end end
# This is wrapper with rescue block # This is wrapper with rescue block
@ -285,7 +296,9 @@ Make sure, that you push tags to remote repo via 'git push --tags'"
Retriable.retriable(retry_options) do Retriable.retriable(retry_options) do
yield yield
end end
rescue MovedPermanentlyError => e
Helper.log.error("#{e.class}: #{e.message}")
sys_abort("The repository has moved, please update your configuration")
rescue Octokit::Forbidden => e rescue Octokit::Forbidden => e
Helper.log.error("#{e.class}: #{e.message}") Helper.log.error("#{e.class}: #{e.message}")
sys_abort("Exceeded retry limit") sys_abort("Exceeded retry limit")