diff --git a/.travis.yml b/.travis.yml index 5c4c831..fb6d844 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/gemfiles/Gemfile.jruby-9.1.5.0 b/gemfiles/Gemfile.jruby-9.1 similarity index 100% rename from gemfiles/Gemfile.jruby-9.1.5.0 rename to gemfiles/Gemfile.jruby-9.1 diff --git a/github_changelog_generator.gemspec b/github_changelog_generator.gemspec index 617e47b..abef4e7 100644 --- a/github_changelog_generator.gemspec +++ b/github_changelog_generator.gemspec @@ -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"]) diff --git a/lib/github_changelog_generator/octo_fetcher.rb b/lib/github_changelog_generator/octo_fetcher.rb index 2e68f51..219f4c8 100644 --- a/lib/github_changelog_generator/octo_fetcher.rb +++ b/lib/github_changelog_generator/octo_fetcher.rb @@ -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")