diff --git a/lib/github_changelog_generator/generator/generator.rb b/lib/github_changelog_generator/generator/generator.rb index 04eefad..a3944b8 100644 --- a/lib/github_changelog_generator/generator/generator.rb +++ b/lib/github_changelog_generator/generator/generator.rb @@ -11,7 +11,7 @@ module GitHubChangelogGenerator end class Generator - attr_accessor :options, :filtered_tags, :github, :tag_section_mapping + attr_accessor :options, :filtered_tags, :github, :tag_section_mapping, :sorted_tags # A Generator responsible for all logic, related with change log generation from ready-to-parse issues # diff --git a/lib/github_changelog_generator/generator/generator_generation.rb b/lib/github_changelog_generator/generator/generator_generation.rb index c939b7a..4b18fd7 100644 --- a/lib/github_changelog_generator/generator/generator_generation.rb +++ b/lib/github_changelog_generator/generator/generator_generation.rb @@ -126,8 +126,9 @@ module GitHubChangelogGenerator def generate_unreleased_section log = "" if options[:unreleased] - unreleased_log = generate_log_between_tags(filtered_tags[0], nil) - log += unreleased_log if unreleased_log + start_tag = filtered_tags[0] || sorted_tags.last + unreleased_log = generate_log_between_tags(start_tag, nil) + log += unreleased_log if unreleased_log end log end diff --git a/lib/github_changelog_generator/generator/generator_processor.rb b/lib/github_changelog_generator/generator/generator_processor.rb index 5bbc11a..cf25dc5 100644 --- a/lib/github_changelog_generator/generator/generator_processor.rb +++ b/lib/github_changelog_generator/generator/generator_processor.rb @@ -72,6 +72,8 @@ module GitHubChangelogGenerator # in case if not tags specified - return unchanged array return issues if older_tag.nil? && newer_tag.nil? + older_tag = ensure_older_tag(older_tag, newer_tag) + newer_tag_time = newer_tag && get_time_of_tag(newer_tag) older_tag_time = older_tag && get_time_of_tag(older_tag) @@ -92,6 +94,12 @@ module GitHubChangelogGenerator end end + def ensure_older_tag(older_tag, newer_tag) + return older_tag if older_tag + idx = sorted_tags.index { |t| t["name"] == newer_tag["name"] } + sorted_tags[idx - 1] + end + def tag_older_new_tag?(newer_tag_time, time) tag_in_range_new = if newer_tag_time.nil? true diff --git a/lib/github_changelog_generator/generator/generator_tags.rb b/lib/github_changelog_generator/generator/generator_tags.rb index de721d6..01480b5 100644 --- a/lib/github_changelog_generator/generator/generator_tags.rb +++ b/lib/github_changelog_generator/generator/generator_tags.rb @@ -10,8 +10,8 @@ module GitHubChangelogGenerator included_tags = filter_excluded_tags(all_tags) fetch_tags_dates(all_tags) # Creates a Hash @tag_times_hash - sorted_tags = sort_tags_by_date(included_tags) - @filtered_tags = get_filtered_tags(included_tags) + @sorted_tags = sort_tags_by_date(included_tags) + @filtered_tags = get_filtered_tags(included_tags) @tag_section_mapping = build_tag_section_mapping(@filtered_tags, sorted_tags)