Skip to content

Fix: always return an Array from #commits_in_branch #957

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

Merged
merged 1 commit into from
Apr 28, 2021
Merged
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
9 changes: 4 additions & 5 deletions lib/github_changelog_generator/generator/generator_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def associate_release_branch_prs(prs_left, total)
i = total - prs_left.count
prs_left.reject do |pr|
found = false
if pr["events"] && (event = pr["events"].find { |e| e["event"] == "merged" }) && sha_in_release_branch(event["commit_id"])
if pr["events"] && (event = pr["events"].find { |e| e["event"] == "merged" }) && sha_in_release_branch?(event["commit_id"])
found = true
i += 1
print("Associating PRs with tags: #{i}/#{total}\r") if @options[:verbose]
Expand Down Expand Up @@ -137,7 +137,7 @@ def associate_rebase_comment_prs(tags, prs_left, total)
pr["first_occurring_tag"] = oldest_tag["name"]
found = true
i += 1
elsif sha_in_release_branch(rebased_sha)
elsif sha_in_release_branch?(rebased_sha)
found = true
i += 1
else
Expand Down Expand Up @@ -195,10 +195,9 @@ def set_date_from_event(event, issue)
#
# @param [String] sha SHA to check.
# @return [Boolean] True if SHA is in the branch git history.
def sha_in_release_branch(sha)
def sha_in_release_branch?(sha)
branch = @options[:release_branch] || @fetcher.default_branch
shas_in_branch = @fetcher.commits_in_branch(branch)
shas_in_branch.include?(sha)
@fetcher.commits_in_branch(branch).include?(sha)
end
end
end
7 changes: 5 additions & 2 deletions lib/github_changelog_generator/octo_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -338,20 +338,23 @@ def default_branch
@default_branch ||= client.repository(user_project)[:default_branch]
end

# @param [Object] name
# @param [String] name
# @return [Array<String>]
def commits_in_branch(name)
@branches ||= client.branches(user_project).map { |branch| [branch[:name], branch] }.to_h

if (branch = @branches[name])
commits_in_tag(branch[:commit][:sha])
else
[]
end
end

# Fetch all SHAs occurring in or before a given tag and add them to
# "shas_in_tag"
#
# @param [Array] tags The array of tags.
# @return [Nil] No return; tags are updated in-place.
# @return void
def fetch_tag_shas(tags)
# Reverse the tags array to gain max benefit from the @commits_in_tag_cache
tags.reverse_each do |tag|
Expand Down