From d6c26ef4a90c8dc7fa86760ab9ac48384c8253e0 Mon Sep 17 00:00:00 2001 From: Tom Duffield Date: Sat, 19 Nov 2016 17:23:52 -0600 Subject: [PATCH] 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 --- .../generator/generator_tags.rb | 15 +++++++++++---- spec/unit/generator/generator_tags_spec.rb | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/github_changelog_generator/generator/generator_tags.rb b/lib/github_changelog_generator/generator/generator_tags.rb index 24ede5d..08d237b 100644 --- a/lib/github_changelog_generator/generator/generator_tags.rb +++ b/lib/github_changelog_generator/generator/generator_tags.rb @@ -25,9 +25,16 @@ module GitHubChangelogGenerator # PRs to include in this section will be >= [Left Tag Date] and <= [Right Tag Date] def build_tag_section_mapping(filtered_tags, all_tags) tag_mapping = {} - filtered_tags.each do |tag| - older_tag_idx = all_tags.index(tag) + 1 - older_tag = all_tags[older_tag_idx] + for i in 0..(filtered_tags.length - 1) + tag = filtered_tags[i] + + # 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] end tag_mapping @@ -113,7 +120,7 @@ module GitHubChangelogGenerator if all_tags.map { |t| t["name"] }.include? tag idx = all_tags.index { |t| t["name"] == tag } filtered_tags = if idx > 0 - all_tags[0..idx - 1] + all_tags[0..idx] else [] end diff --git a/spec/unit/generator/generator_tags_spec.rb b/spec/unit/generator/generator_tags_spec.rb index 219ff53..7ca342a 100644 --- a/spec/unit/generator/generator_tags_spec.rb +++ b/spec/unit/generator/generator_tags_spec.rb @@ -232,7 +232,7 @@ describe GitHubChangelogGenerator::Generator do context "with valid since tag" do let(:generator) { GitHubChangelogGenerator::Generator.new(since_tag: "2") } 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 context "with invalid since tag" do