Skip to content

Allow generator to continue even if any errors encountered in fetch comparison #736

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/github_changelog_generator/argv_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 21 additions & 8 deletions lib/github_changelog_generator/generator/generator_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#
Expand All @@ -73,22 +91,17 @@ 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.
no_events_pr = associate_rebase_comment_prs(tags, [pr], 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
Expand Down
3 changes: 3 additions & 0 deletions lib/github_changelog_generator/octo_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions lib/github_changelog_generator/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class Options < SimpleDelegator
user
usernames_as_github_logins
verbose
continue_with_errors
]

# @param values [Hash]
Expand Down
3 changes: 2 additions & 1 deletion lib/github_changelog_generator/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down