diff --git a/lib/github_changelog_generator/generator/generator_tags.rb b/lib/github_changelog_generator/generator/generator_tags.rb index 123c155..81c4466 100644 --- a/lib/github_changelog_generator/generator/generator_tags.rb +++ b/lib/github_changelog_generator/generator/generator_tags.rb @@ -56,10 +56,29 @@ module GitHubChangelogGenerator # # @return [Array] def get_filtered_tags(all_tags) - filtered_tags = filter_between_tags(all_tags) + filtered_tags = filter_since_tag(all_tags) + filtered_tags = filter_between_tags(filtered_tags) filter_excluded_tags(filtered_tags) end + def filter_since_tag(all_tags) + filtered_tags = all_tags + tag = @options[:since_tag] + if tag + if all_tags.map(&:name).include? tag + idx = all_tags.index { |t| t.name == tag } + if idx > 0 + filtered_tags = all_tags[0..idx - 1] + else + filtered_tags = [] + end + else + Helper.log.warn "Warning: can't find tag #{tag}, specified with --since-tag option." + end + end + filtered_tags + end + def filter_between_tags(all_tags) filtered_tags = all_tags if @options[:between_tags] diff --git a/lib/github_changelog_generator/parser.rb b/lib/github_changelog_generator/parser.rb index f06d452..ff1b6f9 100644 --- a/lib/github_changelog_generator/parser.rb +++ b/lib/github_changelog_generator/parser.rb @@ -110,9 +110,12 @@ module GitHubChangelogGenerator opts.on("--between-tags x,y,z", Array, "Change log will be filled only between specified tags") do |list| options[:between_tags] = list end - opts.on("--exclude-tags x,y,z", Array, "Change log will be exclude specified tags") do |list| + opts.on("--exclude-tags x,y,z", Array, "Change log will exclude specified tags") do |list| options[:exclude_tags] = list end + opts.on("--since-tag x", "Change log will start after specified tag") do |v| + options[:since_tag] = v + end opts.on("--max-issues [NUMBER]", Integer, "Max number of issues to fetch from GitHub. Default is unlimited") do |max| options[:max_issues] = max end diff --git a/spec/unit/generator/generator_tags_spec.rb b/spec/unit/generator/generator_tags_spec.rb index 5dd00c2..ec69c05 100644 --- a/spec/unit/generator/generator_tags_spec.rb +++ b/spec/unit/generator/generator_tags_spec.rb @@ -89,6 +89,22 @@ describe GitHubChangelogGenerator::Generator do end end + describe "#filter_since_tag" do + subject { generator.filter_since_tag(tags_mash_from_strings(%w(1 2 3))) } + + 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_mash_from_strings(%w(1))) } + end + + context "with invalid since tag" do + let(:generator) { GitHubChangelogGenerator::Generator.new(since_tag: %w(invalid tags)) } + it { is_expected.to be_a Array } + it { is_expected.to match_array(tags_mash_from_strings(%w(1 2 3))) } + end + end + describe "#get_time_of_tag" do current_time = Time.now before(:all) { @generator = GitHubChangelogGenerator::Generator.new }