From d122e00a1ac5017e70ae382e9c616712e8a91976 Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Thu, 10 Nov 2016 19:32:24 +0100 Subject: [PATCH 1/6] OctoFetcher#iterate_pages: extract method --- .../octo_fetcher.rb | 36 +++++++++++-------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/lib/github_changelog_generator/octo_fetcher.rb b/lib/github_changelog_generator/octo_fetcher.rb index 2e68f51..6001e57 100644 --- a/lib/github_changelog_generator/octo_fetcher.rb +++ b/lib/github_changelog_generator/octo_fetcher.rb @@ -249,33 +249,39 @@ Make sure, that you push tags to remote repo via 'git push --tags'" # # @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 - 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 From 88b23ba79064abb114c60a9686bc463038526351 Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Thu, 10 Nov 2016 19:32:42 +0100 Subject: [PATCH 2/6] Bump OctoKit dep --- github_changelog_generator.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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"]) From d4dfc9912754c5d04198df798de26408560336ac Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Thu, 10 Nov 2016 20:37:46 +0100 Subject: [PATCH 3/6] OctoFetcher: Moved repositories fail explicitly --- lib/github_changelog_generator/octo_fetcher.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/github_changelog_generator/octo_fetcher.rb b/lib/github_changelog_generator/octo_fetcher.rb index 6001e57..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,6 +244,8 @@ 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 # @@ -261,6 +263,9 @@ Make sure, that you push tags to remote repo via 'git push --tags'" 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) @@ -291,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") From 4d4e8ef5a46fb3964aa65c83f1780446a59b91ae Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Thu, 10 Nov 2016 20:48:23 +0100 Subject: [PATCH 4/6] Travis: Use jruby-9.1.6.0 and 2.4.0-preview3 --- .travis.yml | 4 ++-- gemfiles/{Gemfile.jruby-9.1.5.0 => Gemfile.jruby-9.1.6.0} | 0 2 files changed, 2 insertions(+), 2 deletions(-) rename gemfiles/{Gemfile.jruby-9.1.5.0 => Gemfile.jruby-9.1.6.0} (100%) diff --git a/.travis.yml b/.travis.yml index 5c4c831..64cd863 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,9 +17,9 @@ 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 env: diff --git a/gemfiles/Gemfile.jruby-9.1.5.0 b/gemfiles/Gemfile.jruby-9.1.6.0 similarity index 100% rename from gemfiles/Gemfile.jruby-9.1.5.0 rename to gemfiles/Gemfile.jruby-9.1.6.0 From 52d14f4b0a405696b3e52e2d94ce8d904af7590c Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Thu, 10 Nov 2016 21:08:14 +0100 Subject: [PATCH 5/6] Travis: gemfile pointing right --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 64cd863..d734ef4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,7 +21,7 @@ matrix: gemfile: gemfiles/Gemfile.2_4_0 - rvm: jruby-9.1.6.0 jdk: oraclejdk8 - gemfile: gemfiles/Gemfile.jruby-9.1.5.0 + gemfile: gemfiles/Gemfile.jruby-9.1.6.0 env: - JRUBY_OPTS=--debug From b2a29d7279e17bc80df417b5c79053f16a170ddb Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Thu, 10 Nov 2016 21:09:19 +0100 Subject: [PATCH 6/6] Travis: Use a Gemfile name that won't outdate --- .travis.yml | 2 +- gemfiles/{Gemfile.jruby-9.1.6.0 => Gemfile.jruby-9.1} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename gemfiles/{Gemfile.jruby-9.1.6.0 => Gemfile.jruby-9.1} (100%) diff --git a/.travis.yml b/.travis.yml index d734ef4..fb6d844 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,7 +21,7 @@ matrix: gemfile: gemfiles/Gemfile.2_4_0 - rvm: jruby-9.1.6.0 jdk: oraclejdk8 - gemfile: gemfiles/Gemfile.jruby-9.1.6.0 + gemfile: gemfiles/Gemfile.jruby-9.1 env: - JRUBY_OPTS=--debug diff --git a/gemfiles/Gemfile.jruby-9.1.6.0 b/gemfiles/Gemfile.jruby-9.1 similarity index 100% rename from gemfiles/Gemfile.jruby-9.1.6.0 rename to gemfiles/Gemfile.jruby-9.1