Add --since-tag option

Fix #254
This commit is contained in:
Raphaël Pinson 2015-08-04 14:58:25 +02:00
parent 0190d417c2
commit 32f4df5742
3 changed files with 39 additions and 1 deletions

View File

@ -56,10 +56,29 @@ module GitHubChangelogGenerator
# #
# @return [Array] # @return [Array]
def get_filtered_tags(all_tags) 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) filter_excluded_tags(filtered_tags)
end 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) def filter_between_tags(all_tags)
filtered_tags = all_tags filtered_tags = all_tags
if @options[:between_tags] if @options[:between_tags]

View File

@ -113,6 +113,9 @@ module GitHubChangelogGenerator
opts.on("--exclude-tags x,y,z", Array, "Change log will 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 options[:exclude_tags] = list
end 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| 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

View File

@ -89,6 +89,22 @@ describe GitHubChangelogGenerator::Generator do
end end
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 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 }