Skip to content

Add --due-tag option #265

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions lib/github_changelog_generator/generator/generator_tags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def detect_link_tag_time(newer_tag)
[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
Expand All @@ -69,6 +70,8 @@ def get_filtered_tags(all_tags)
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]
Expand All @@ -88,6 +91,29 @@ def filter_since_tag(all_tags)
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)
filtered_tags = all_tags
if @options[:between_tags]
Expand All @@ -101,6 +127,8 @@ def filter_between_tags(all_tags)
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]
Expand Down
3 changes: 3 additions & 0 deletions lib/github_changelog_generator/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ def self.setup_parser(options)
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
Expand Down
70 changes: 61 additions & 9 deletions spec/unit/generator/generator_tags_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,70 @@ def tags_mash_from_strings(tags_strings)
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

Expand Down