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:
commit
92137ba0b2
|
@ -17,11 +17,11 @@ matrix:
|
|||
gemfile: gemfiles/Gemfile.2_1
|
||||
- rvm: 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
|
||||
- rvm: jruby-9.1.5.0
|
||||
- rvm: jruby-9.1.6.0
|
||||
jdk: oraclejdk8
|
||||
gemfile: gemfiles/Gemfile.jruby-9.1.5.0
|
||||
gemfile: gemfiles/Gemfile.jruby-9.1
|
||||
env:
|
||||
- JRUBY_OPTS=--debug
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
|
|||
|
||||
spec.add_runtime_dependency "rake", ">= 10.0"
|
||||
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("activesupport")
|
||||
spec.add_runtime_dependency("retriable", ["~> 2.1"])
|
||||
|
|
|
@ -103,7 +103,7 @@ module GitHubChangelogGenerator
|
|||
print_empty_line
|
||||
|
||||
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'"
|
||||
else
|
||||
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
|
||||
|
||||
MovedPermanentlyError = Class.new(RuntimeError)
|
||||
|
||||
# Iterates through all pages until there are no more :next pages to follow
|
||||
# yields the result per page
|
||||
#
|
||||
# @param [Octokit::Client] client
|
||||
# @param [String] method (eg. 'tags')
|
||||
#
|
||||
# @yield [Sawyer::Resource] An OctoKit-provided response (which can be empty)
|
||||
#
|
||||
# @return [Integer] total number of pages
|
||||
def iterate_pages(client, method, *args)
|
||||
if args.size == 1 && args.first.is_a?(Hash)
|
||||
request_options = args.delete_at(0)
|
||||
elsif args.size > 1 && args.last.is_a?(Hash)
|
||||
request_options = args.delete_at(args.length - 1)
|
||||
end
|
||||
request_opts = extract_request_args(args)
|
||||
args.push(@request_options.merge(request_opts))
|
||||
|
||||
args.push(@request_options.merge(request_options))
|
||||
number_of_pages = 1
|
||||
|
||||
pages = 1
|
||||
|
||||
check_github_response do
|
||||
client.send(method, user_project, *args)
|
||||
end
|
||||
check_github_response { client.send(method, user_project, *args) }
|
||||
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?
|
||||
pages += 1
|
||||
number_of_pages += 1
|
||||
|
||||
last_response = check_github_response { next_one.get }
|
||||
yield last_response.data
|
||||
yield(last_response.data)
|
||||
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
|
||||
|
||||
# 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
|
||||
yield
|
||||
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
|
||||
Helper.log.error("#{e.class}: #{e.message}")
|
||||
sys_abort("Exceeded retry limit")
|
||||
|
|
Loading…
Reference in New Issue
Block a user