Generate mapping that will match expectations

This change neccesitated changing the behavior or the
`filter_since_tag`. Since we want our compare links to include the since
tag, we need to keep that tag in the filtered list. Instead, we detect
that the tag is the since tag and filter it out. This will prevent the
since_tag header from being duplicated when pulling from a base.

The same goes for the first tag listed in between_tags. We don't want an
empty section header for this.

Signed-off-by: Tom Duffield <tom@chef.io>
This commit is contained in:
Tom Duffield 2016-11-19 17:23:52 -06:00 committed by Hunter Haugen
parent c718930fb1
commit d6c26ef4a9
No known key found for this signature in database
GPG Key ID: EF99694AA599DDAD
2 changed files with 12 additions and 5 deletions

View File

@ -25,9 +25,16 @@ module GitHubChangelogGenerator
# PRs to include in this section will be >= [Left Tag Date] and <= [Right Tag Date] # PRs to include in this section will be >= [Left Tag Date] and <= [Right Tag Date]
def build_tag_section_mapping(filtered_tags, all_tags) def build_tag_section_mapping(filtered_tags, all_tags)
tag_mapping = {} tag_mapping = {}
filtered_tags.each do |tag| for i in 0..(filtered_tags.length - 1)
older_tag_idx = all_tags.index(tag) + 1 tag = filtered_tags[i]
older_tag = all_tags[older_tag_idx]
# Don't create section header for the "since" tag
next if @since_tag && tag["name"] == @since_tag
# Don't create a section header for the first tag in between_tags
next if options[:between_tags] && tag == filtered_tags.last
older_tag = filtered_tags[i + 1]
tag_mapping[tag] = [older_tag, tag] tag_mapping[tag] = [older_tag, tag]
end end
tag_mapping tag_mapping
@ -113,7 +120,7 @@ module GitHubChangelogGenerator
if all_tags.map { |t| t["name"] }.include? tag if all_tags.map { |t| t["name"] }.include? tag
idx = all_tags.index { |t| t["name"] == tag } idx = all_tags.index { |t| t["name"] == tag }
filtered_tags = if idx > 0 filtered_tags = if idx > 0
all_tags[0..idx - 1] all_tags[0..idx]
else else
[] []
end end

View File

@ -232,7 +232,7 @@ describe GitHubChangelogGenerator::Generator do
context "with valid since tag" do context "with valid since tag" do
let(:generator) { GitHubChangelogGenerator::Generator.new(since_tag: "2") } let(:generator) { GitHubChangelogGenerator::Generator.new(since_tag: "2") }
it { is_expected.to be_a Array } it { is_expected.to be_a Array }
it { is_expected.to match_array(tags_from_strings(%w[1])) } it { is_expected.to match_array(tags_from_strings(%w[1 2])) }
end end
context "with invalid since tag" do context "with invalid since tag" do