Skip to content

Commit

Permalink
Fix: always return an Array from #commits_in_branch (#957)
Browse files Browse the repository at this point in the history
This commit also refactors the name of a method to reflect that it is a
predicate method.

Also: a YARD annotation, using the built-in 'void' type.

Fixes #954
  • Loading branch information
olleolleolle committed Apr 28, 2021
1 parent 96e7f20 commit c596513
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
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

0 comments on commit c596513

Please sign in to comment.