From d1386449254cbaa47dee60814a7124141b416264 Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Mon, 24 Aug 2015 16:47:37 +0300 Subject: [PATCH 1/2] add docs --- lib/github_changelog_generator/generator/generator_tags.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/github_changelog_generator/generator/generator_tags.rb b/lib/github_changelog_generator/generator/generator_tags.rb index bdc078d..93f4e19 100644 --- a/lib/github_changelog_generator/generator/generator_tags.rb +++ b/lib/github_changelog_generator/generator/generator_tags.rb @@ -52,6 +52,7 @@ module GitHubChangelogGenerator [newer_tag_link, newer_tag_name, newer_tag_time] end + # @return [Object] try to find newest tag using #Reader and :base option if specified otherwise returns nil def detect_since_tag if @options[:base] && File.file?(@options[:base]) reader = GitHubChangelogGenerator::Reader.new @@ -69,6 +70,8 @@ module GitHubChangelogGenerator filter_excluded_tags(filtered_tags) end + # @param [Array] all_tags all tags + # @return [Array] filtered tags according :since_tag option def filter_since_tag(all_tags) filtered_tags = all_tags tag = @options[:since_tag] @@ -88,6 +91,8 @@ module GitHubChangelogGenerator filtered_tags end + # @param [Array] all_tags all tags + # @return [Array] filtered tags according :between_tags option def filter_between_tags(all_tags) filtered_tags = all_tags if @options[:between_tags] @@ -101,6 +106,8 @@ module GitHubChangelogGenerator filtered_tags end + # @param [Array] all_tags all tags + # @return [Array] filtered tags according :exclude_tags option def filter_excluded_tags(all_tags) filtered_tags = all_tags if @options[:exclude_tags] From 4261c3494e57952d13bf78673d583bcc8ddffb93 Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Mon, 24 Aug 2015 17:29:07 +0300 Subject: [PATCH 2/2] Add due-tag option and tests --- .../generator/generator_tags.rb | 21 ++++++ lib/github_changelog_generator/parser.rb | 3 + spec/unit/generator/generator_tags_spec.rb | 70 ++++++++++++++++--- 3 files changed, 85 insertions(+), 9 deletions(-) diff --git a/lib/github_changelog_generator/generator/generator_tags.rb b/lib/github_changelog_generator/generator/generator_tags.rb index 93f4e19..2cc28c8 100644 --- a/lib/github_changelog_generator/generator/generator_tags.rb +++ b/lib/github_changelog_generator/generator/generator_tags.rb @@ -91,6 +91,27 @@ module GitHubChangelogGenerator filtered_tags end + # @param [Array] all_tags all tags + # @return [Array] filtered tags according :due_tag option + def filter_due_tag(all_tags) + filtered_tags = all_tags + tag = @options[:due_tag] + if tag + if (all_tags.count > 0) && (all_tags.map(&:name).include? tag) + idx = all_tags.index { |t| t.name == tag } + last_index = all_tags.count - 1 + if idx > 0 && idx < last_index + filtered_tags = all_tags[idx + 1..last_index] + else + filtered_tags = [] + end + else + Helper.log.warn "Warning: can't find tag #{tag}, specified with --due-tag option." + end + end + filtered_tags + end + # @param [Array] all_tags all tags # @return [Array] filtered tags according :between_tags option def filter_between_tags(all_tags) diff --git a/lib/github_changelog_generator/parser.rb b/lib/github_changelog_generator/parser.rb index 0154864..13b6a48 100644 --- a/lib/github_changelog_generator/parser.rb +++ b/lib/github_changelog_generator/parser.rb @@ -119,6 +119,9 @@ module GitHubChangelogGenerator opts.on("--since-tag x", "Change log will start after specified tag") do |v| options[:since_tag] = v end + opts.on("--due-tag x", "Change log will end before specified tag") do |v| + options[:due_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 ec69c05..932e673 100644 --- a/spec/unit/generator/generator_tags_spec.rb +++ b/spec/unit/generator/generator_tags_spec.rb @@ -90,18 +90,70 @@ describe GitHubChangelogGenerator::Generator do end describe "#filter_since_tag" do - subject { generator.filter_since_tag(tags_mash_from_strings(%w(1 2 3))) } + context "with filled array" 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))) } + 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: "Invalid tag") } + it { is_expected.to be_a Array } + it { is_expected.to match_array(tags_mash_from_strings(%w(1 2 3))) } + end 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))) } + context "with empty array" do + subject { generator.filter_since_tag(tags_mash_from_strings(%w())) } + + 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())) } + end + + context "with invalid since tag" do + let(:generator) { GitHubChangelogGenerator::Generator.new(since_tag: "Invalid tag") } + it { is_expected.to be_a Array } + it { is_expected.to match_array(tags_mash_from_strings(%w())) } + end + end + end + + describe "#filter_due_tag" do + context "with filled array" do + subject { generator.filter_due_tag(tags_mash_from_strings(%w(1 2 3))) } + + context "with valid due tag" do + let(:generator) { GitHubChangelogGenerator::Generator.new(due_tag: "2") } + it { is_expected.to be_a Array } + it { is_expected.to match_array(tags_mash_from_strings(%w(3))) } + end + + context "with invalid due tag" do + let(:generator) { GitHubChangelogGenerator::Generator.new(due_tag: "Invalid tag") } + it { is_expected.to be_a Array } + it { is_expected.to match_array(tags_mash_from_strings(%w(1 2 3))) } + end + end + + context "with empty array" do + subject { generator.filter_due_tag(tags_mash_from_strings(%w())) } + + context "with valid due tag" do + let(:generator) { GitHubChangelogGenerator::Generator.new(due_tag: "2") } + it { is_expected.to be_a Array } + it { is_expected.to match_array(tags_mash_from_strings(%w())) } + end + + context "with invalid due tag" do + let(:generator) { GitHubChangelogGenerator::Generator.new(due_tag: "Invalid tag") } + it { is_expected.to be_a Array } + it { is_expected.to match_array(tags_mash_from_strings(%w())) } + end end end