Add due-tag option and tests
This commit is contained in:
parent
d138644925
commit
4261c3494e
|
@ -91,6 +91,27 @@ module GitHubChangelogGenerator
|
||||||
filtered_tags
|
filtered_tags
|
||||||
end
|
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
|
# @param [Array] all_tags all tags
|
||||||
# @return [Array] filtered tags according :between_tags option
|
# @return [Array] filtered tags according :between_tags option
|
||||||
def filter_between_tags(all_tags)
|
def filter_between_tags(all_tags)
|
||||||
|
|
|
@ -119,6 +119,9 @@ module GitHubChangelogGenerator
|
||||||
opts.on("--since-tag x", "Change log will start after specified tag") do |v|
|
opts.on("--since-tag x", "Change log will start after specified tag") do |v|
|
||||||
options[:since_tag] = v
|
options[:since_tag] = v
|
||||||
end
|
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|
|
opts.on("--max-issues [NUMBER]", Integer, "Max number of issues to fetch from GitHub. Default is unlimited") do |max|
|
||||||
options[:max_issues] = max
|
options[:max_issues] = max
|
||||||
end
|
end
|
||||||
|
|
|
@ -90,6 +90,7 @@ describe GitHubChangelogGenerator::Generator do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#filter_since_tag" do
|
describe "#filter_since_tag" do
|
||||||
|
context "with filled array" do
|
||||||
subject { generator.filter_since_tag(tags_mash_from_strings(%w(1 2 3))) }
|
subject { generator.filter_since_tag(tags_mash_from_strings(%w(1 2 3))) }
|
||||||
|
|
||||||
context "with valid since tag" do
|
context "with valid since tag" do
|
||||||
|
@ -99,12 +100,63 @@ describe GitHubChangelogGenerator::Generator do
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with invalid since tag" do
|
context "with invalid since tag" do
|
||||||
let(:generator) { GitHubChangelogGenerator::Generator.new(since_tag: %w(invalid tags)) }
|
let(:generator) { GitHubChangelogGenerator::Generator.new(since_tag: "Invalid tag") }
|
||||||
it { is_expected.to be_a Array }
|
it { is_expected.to be_a Array }
|
||||||
it { is_expected.to match_array(tags_mash_from_strings(%w(1 2 3))) }
|
it { is_expected.to match_array(tags_mash_from_strings(%w(1 2 3))) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
describe "#get_time_of_tag" do
|
describe "#get_time_of_tag" do
|
||||||
current_time = Time.now
|
current_time = Time.now
|
||||||
before(:all) { @generator = GitHubChangelogGenerator::Generator.new }
|
before(:all) { @generator = GitHubChangelogGenerator::Generator.new }
|
||||||
|
|
Loading…
Reference in New Issue
Block a user