Skip to content

Add --since-tag #257

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 2 commits into from
Aug 4, 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
21 changes: 20 additions & 1 deletion lib/github_changelog_generator/generator/generator_tags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,29 @@ def detect_link_tag_time(newer_tag)
#
# @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]
Expand Down
5 changes: 4 additions & 1 deletion lib/github_changelog_generator/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,12 @@ def self.setup_parser(options)
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
Expand Down
16 changes: 16 additions & 0 deletions spec/unit/generator/generator_tags_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,22 @@ def tags_mash_from_strings(tags_strings)
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 }
Expand Down