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 diff --git a/lib/github_changelog_generator/generator/generator_fetcher.rb b/lib/github_changelog_generator/generator/generator_fetcher.rb index 63a9fc06..68466248 100644 --- a/lib/github_changelog_generator/generator/generator_fetcher.rb +++ b/lib/github_changelog_generator/generator/generator_fetcher.rb @@ -55,6 +55,24 @@ 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 @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 + 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 +91,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"]) }) - 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 +99,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/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/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..79b784b3 100644 --- a/lib/github_changelog_generator/task.rb +++ b/lib/github_changelog_generator/task.rb @@ -19,7 +19,8 @@ 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| attr_accessor o.to_sym