From 1c289366b284f867b6d9247d6720d603cb4c3689 Mon Sep 17 00:00:00 2001 From: Daniel Carabas Date: Thu, 19 Sep 2019 16:19:20 +0300 Subject: [PATCH 1/6] Allow generator to continue even if any errors encountered in fetch comparison --- .../generator/generator_fetcher.rb | 2 +- lib/github_changelog_generator/octo_fetcher.rb | 3 +++ spec/unit/octo_fetcher_spec.rb | 15 +++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/github_changelog_generator/generator/generator_fetcher.rb b/lib/github_changelog_generator/generator/generator_fetcher.rb index 63a9fc06..b66bcda2 100644 --- a/lib/github_changelog_generator/generator/generator_fetcher.rb +++ b/lib/github_changelog_generator/generator/generator_fetcher.rb @@ -73,7 +73,7 @@ def associate_tagged_prs(tags, prs, total) # https://developer.github.com/v3/pulls/#list-pull-requests if pr["events"] && (event = pr["events"].find { |e| e["event"] == "merged" }) # Iterate tags.reverse (oldest to newest) to find first tag of each PR. - if (oldest_tag = tags.reverse.find { |tag| tag["shas_in_tag"].include?(event["commit_id"]) }) + if (oldest_tag = tags.reverse.find { |tag| tag["shas_in_tag"].include?(event["commit_id"]) unless tag["shas_in_tag"].nil? }) pr["first_occurring_tag"] = oldest_tag["name"] found = true i += 1 diff --git a/lib/github_changelog_generator/octo_fetcher.rb b/lib/github_changelog_generator/octo_fetcher.rb index 4a1b25c9..323ea9dc 100644 --- a/lib/github_changelog_generator/octo_fetcher.rb +++ b/lib/github_changelog_generator/octo_fetcher.rb @@ -474,6 +474,9 @@ def check_github_response fail_with_message(e, "Exceeded retry limit") rescue Octokit::Unauthorized => e fail_with_message(e, "Error: wrong GitHub token") + rescue StandardError => e + Helper.log.error("#{e.class}: #{e.message}") + nil end # Presents the exception, and the aborts with the message. diff --git a/spec/unit/octo_fetcher_spec.rb b/spec/unit/octo_fetcher_spec.rb index 0f981815..25295a49 100644 --- a/spec/unit/octo_fetcher_spec.rb +++ b/spec/unit/octo_fetcher_spec.rb @@ -587,4 +587,19 @@ end end end + + describe "#fetch_compare" do + context "with nil compare_data" do + it "not raises error" do + allow(fetcher).to receive(:check_github_response) + expect { fetcher.fetch_compare("a", "b") }.not_to raise_error + end + end + context "with diverged compare_data" do + it "raises error" do + allow(fetcher).to receive(:check_github_response).and_return("status" => "diverged") + expect { fetcher.fetch_compare("a", "b") }.to raise_error(StandardError, /are not related/) + end + end + end end From d3a54118b4dab965e5c5068f3191abb2092b7bc3 Mon Sep 17 00:00:00 2001 From: Daniel Carabas Date: Thu, 5 Mar 2020 11:42:16 +0200 Subject: [PATCH 2/6] Add continue_with_errors option --- lib/github_changelog_generator/options.rb | 1 + lib/github_changelog_generator/task.rb | 1 + 2 files changed, 2 insertions(+) diff --git a/lib/github_changelog_generator/options.rb b/lib/github_changelog_generator/options.rb index b77503fa..c228976a 100644 --- a/lib/github_changelog_generator/options.rb +++ b/lib/github_changelog_generator/options.rb @@ -76,6 +76,7 @@ class Options < SimpleDelegator user usernames_as_github_logins verbose + continue_with_errors ] # @param values [Hash] diff --git a/lib/github_changelog_generator/task.rb b/lib/github_changelog_generator/task.rb index 33a5999d..2ccf090e 100644 --- a/lib/github_changelog_generator/task.rb +++ b/lib/github_changelog_generator/task.rb @@ -20,6 +20,7 @@ class RakeTask < ::Rake::TaskLib github_site github_endpoint simple_list future_release release_branch verbose release_url base configure_sections add_sections http_cache] + base configure_sections add_sections continue_with_errors] OPTIONS.each do |o| attr_accessor o.to_sym From b71bcf3c0eb43f3b9eb8a65289da6ee00946e0e1 Mon Sep 17 00:00:00 2001 From: Daniel Carabas Date: Thu, 5 Mar 2020 12:51:14 +0200 Subject: [PATCH 3/6] Fix rubocop issues --- .../generator/generator_fetcher.rb | 24 ++++++++++++------- lib/github_changelog_generator/task.rb | 2 +- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/lib/github_changelog_generator/generator/generator_fetcher.rb b/lib/github_changelog_generator/generator/generator_fetcher.rb index b66bcda2..c5cf2398 100644 --- a/lib/github_changelog_generator/generator/generator_fetcher.rb +++ b/lib/github_changelog_generator/generator/generator_fetcher.rb @@ -55,6 +55,19 @@ def add_first_occurring_tag_to_prs(tags, prs) Helper.log.info "Associating PRs with tags: #{total}/#{total}" end + # Used in associate_tagged_prs to attach the oldest tag to the pr + # @param [Array] tags The tags sorted by time, newest to olderst. + # @param [Hash] pull_request The pull request that receives the associated tag. + # @param [Hash] event The last merged event information from the pull_request. + # @return [Boolean] Returns true if tag is associated, false otherwise. + def add_tag_to_pr(tags, pull_request, event) + if (oldest_tag = tags.reverse.find { |tag| tag["shas_in_tag"].include?(event["commit_id"]) unless tag["shas_in_tag"].nil? }) + pull_request["first_occurring_tag"] = oldest_tag["name"] + return true + end + false + end + # Associate merged PRs by the merge SHA contained in each tag. If the # merge_commit_sha is not found in any tag's history, skip association. # @@ -73,12 +86,7 @@ def associate_tagged_prs(tags, prs, total) # https://developer.github.com/v3/pulls/#list-pull-requests if pr["events"] && (event = pr["events"].find { |e| e["event"] == "merged" }) # Iterate tags.reverse (oldest to newest) to find first tag of each PR. - if (oldest_tag = tags.reverse.find { |tag| tag["shas_in_tag"].include?(event["commit_id"]) unless tag["shas_in_tag"].nil? }) - pr["first_occurring_tag"] = oldest_tag["name"] - found = true - i += 1 - print("Associating PRs with tags: #{i}/#{total}\r") if @options[:verbose] - end + found = add_tag_to_pr(tags, pr, event) else # Either there were no events or no merged event. Github's api can be # weird like that apparently. Check for a rebased comment before erroring. @@ -86,9 +94,9 @@ def associate_tagged_prs(tags, prs, total) raise StandardError, "No merge sha found for PR #{pr['number']} via the GitHub API" unless no_events_pr.empty? found = true - i += 1 - print("Associating PRs with tags: #{i}/#{total}\r") if @options[:verbose] end + i += 1 + print("Associating PRs with tags: #{i}/#{total}\r") if @options[:verbose] found end end diff --git a/lib/github_changelog_generator/task.rb b/lib/github_changelog_generator/task.rb index 2ccf090e..79b784b3 100644 --- a/lib/github_changelog_generator/task.rb +++ b/lib/github_changelog_generator/task.rb @@ -19,7 +19,7 @@ class RakeTask < ::Rake::TaskLib between_tags exclude_tags exclude_tags_regex since_tag max_issues github_site github_endpoint simple_list future_release release_branch verbose release_url - base configure_sections add_sections http_cache] + base configure_sections add_sections http_cache base configure_sections add_sections continue_with_errors] OPTIONS.each do |o| From 844415c034a6eba8e355657e12b6b2a0d4fa0a2a Mon Sep 17 00:00:00 2001 From: Daniel Carabas Date: Wed, 10 Jun 2020 13:02:17 +0300 Subject: [PATCH 4/6] Remove old unit tests --- spec/unit/octo_fetcher_spec.rb | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/spec/unit/octo_fetcher_spec.rb b/spec/unit/octo_fetcher_spec.rb index 25295a49..0f981815 100644 --- a/spec/unit/octo_fetcher_spec.rb +++ b/spec/unit/octo_fetcher_spec.rb @@ -587,19 +587,4 @@ end end end - - describe "#fetch_compare" do - context "with nil compare_data" do - it "not raises error" do - allow(fetcher).to receive(:check_github_response) - expect { fetcher.fetch_compare("a", "b") }.not_to raise_error - end - end - context "with diverged compare_data" do - it "raises error" do - allow(fetcher).to receive(:check_github_response).and_return("status" => "diverged") - expect { fetcher.fetch_compare("a", "b") }.to raise_error(StandardError, /are not related/) - end - end - end end From 3504e599dfb2c20b7652783ee5c37867b15f0267 Mon Sep 17 00:00:00 2001 From: Daniel Carabas Date: Wed, 10 Jun 2020 15:24:43 +0300 Subject: [PATCH 5/6] Fix use of the continue_with_errors option after rebase --- .../generator/generator_fetcher.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/github_changelog_generator/generator/generator_fetcher.rb b/lib/github_changelog_generator/generator/generator_fetcher.rb index c5cf2398..68466248 100644 --- a/lib/github_changelog_generator/generator/generator_fetcher.rb +++ b/lib/github_changelog_generator/generator/generator_fetcher.rb @@ -61,7 +61,12 @@ def add_first_occurring_tag_to_prs(tags, prs) # @param [Hash] event The last merged event information from the pull_request. # @return [Boolean] Returns true if tag is associated, false otherwise. def add_tag_to_pr(tags, pull_request, event) - if (oldest_tag = tags.reverse.find { |tag| tag["shas_in_tag"].include?(event["commit_id"]) unless tag["shas_in_tag"].nil? }) + if @options[:continue_with_errors] + if (oldest_tag = tags.reverse.find { |tag| tag["shas_in_tag"].include?(event["commit_id"]) unless tag["shas_in_tag"].nil? }) + pull_request["first_occurring_tag"] = oldest_tag["name"] + return true + end + elsif (oldest_tag = tags.reverse.find { |tag| tag["shas_in_tag"].include?(event["commit_id"]) }) pull_request["first_occurring_tag"] = oldest_tag["name"] return true end From fb7ea37cdff79c22a662e99ac38a10c6d0a7a131 Mon Sep 17 00:00:00 2001 From: sheena Date: Mon, 26 Jul 2021 11:43:45 +0100 Subject: [PATCH 6/6] Fix use of the continue_with_errors option after rebase --- lib/github_changelog_generator/argv_parser.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/github_changelog_generator/argv_parser.rb b/lib/github_changelog_generator/argv_parser.rb index e62bae72..26cf8916 100755 --- a/lib/github_changelog_generator/argv_parser.rb +++ b/lib/github_changelog_generator/argv_parser.rb @@ -205,6 +205,9 @@ def parser opts.on("--[no-]verbose", "Run verbosely. Default is true.") do |v| options[:verbose] = v end + opts.on("--continue-with-errors", "Allow generator to continue even if any errors are encountered in the fetch comparison.") do |continue_with_errors| + options[:continue_with_errors] = continue_with_errors + end opts.on("-v", "--version", "Print version number.") do |_v| puts "Version: #{GitHubChangelogGenerator::VERSION}" exit