Skip to content

Commit

Permalink
implement #filter_excluded_tags_regex with regex exclude_tags
Browse files Browse the repository at this point in the history
  • Loading branch information
testerindevelopment committed Mar 24, 2016
1 parent 1bae4ea commit dd149d7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
23 changes: 19 additions & 4 deletions lib/github_changelog_generator/generator/generator_tags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,13 @@ def filter_between_tags(all_tags)
# @param [Array] all_tags all tags
# @return [Array] filtered tags according :exclude_tags option
def filter_excluded_tags(all_tags)
return all_tags unless @options[:exclude_tags]

apply_exclude_tags(all_tags)
if @options[:exclude_tags]
apply_exclude_tags(all_tags)
elsif @options[:exclude_tags_regex]
apply_exclude_tags_regex(all_tags)
else
all_tags
end
end

private
Expand All @@ -146,9 +150,20 @@ def apply_exclude_tags(all_tags)
end
end

def apply_exclude_tags_regex(all_tags)
filter_tags_with_regex(all_tags)
end

def filter_tags_with_regex(all_tags)
warn_if_nonmatching_regex(all_tags)
all_tags.reject { |tag| @options[:exclude_tags] =~ tag.name }

if @options[:exclude_tags]
all_tags.reject { |tag| @options[:exclude_tags] =~ tag.name }
elsif @options[:exclude_tags_regex]
regex = Regexp.new(@options[:exclude_tags_regex])
all_tags.reject { |tag| regex =~ tag.name }
end

end

def filter_exact_tags(all_tags)
Expand Down
10 changes: 10 additions & 0 deletions spec/unit/generator/generator_tags_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ def tags_mash_from_strings(tags_strings)
end
end

describe "#filter_excluded_tags_regex" do
subject { generator.filter_excluded_tags(tags_mash_from_strings(%w(v1.2.3+12 v1.2.3))) }

context "with regex exclude_tags" do
let(:generator) { GitHubChangelogGenerator::Generator.new(exclude_tags_regex: '.*\+\d{1,}') }
it { is_expected.to be_a Array }
it { is_expected.to match_array(tags_mash_from_strings(%w(v1.2.3))) }
end
end

describe "#filter_excluded_tags" do
subject { generator.filter_excluded_tags(tags_mash_from_strings(%w(1 2 3))) }

Expand Down

0 comments on commit dd149d7

Please sign in to comment.