implement #filter_excluded_tags_regex with regex exclude_tags
This commit is contained in:
		
							parent
							
								
									1bae4ea204
								
							
						
					
					
						commit
						dd149d7ad9
					
				@ -131,9 +131,13 @@ module GitHubChangelogGenerator
 | 
				
			|||||||
    # @param [Array] all_tags all tags
 | 
					    # @param [Array] all_tags all tags
 | 
				
			||||||
    # @return [Array] filtered tags according :exclude_tags option
 | 
					    # @return [Array] filtered tags according :exclude_tags option
 | 
				
			||||||
    def filter_excluded_tags(all_tags)
 | 
					    def filter_excluded_tags(all_tags)
 | 
				
			||||||
      return all_tags unless @options[:exclude_tags]
 | 
					      if @options[:exclude_tags]
 | 
				
			||||||
 | 
					 | 
				
			||||||
        apply_exclude_tags(all_tags)
 | 
					        apply_exclude_tags(all_tags)
 | 
				
			||||||
 | 
					      elsif @options[:exclude_tags_regex]
 | 
				
			||||||
 | 
					        apply_exclude_tags_regex(all_tags)
 | 
				
			||||||
 | 
					      else
 | 
				
			||||||
 | 
					        all_tags
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private
 | 
					    private
 | 
				
			||||||
@ -146,9 +150,20 @@ module GitHubChangelogGenerator
 | 
				
			|||||||
      end
 | 
					      end
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def apply_exclude_tags_regex(all_tags)
 | 
				
			||||||
 | 
					      filter_tags_with_regex(all_tags)
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def filter_tags_with_regex(all_tags)
 | 
					    def filter_tags_with_regex(all_tags)
 | 
				
			||||||
      warn_if_nonmatching_regex(all_tags)
 | 
					      warn_if_nonmatching_regex(all_tags)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      if @options[:exclude_tags]
 | 
				
			||||||
        all_tags.reject { |tag| @options[:exclude_tags] =~ tag.name }
 | 
					        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
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def filter_exact_tags(all_tags)
 | 
					    def filter_exact_tags(all_tags)
 | 
				
			||||||
 | 
				
			|||||||
@ -73,6 +73,16 @@ describe GitHubChangelogGenerator::Generator do
 | 
				
			|||||||
    end
 | 
					    end
 | 
				
			||||||
  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
 | 
					  describe "#filter_excluded_tags" do
 | 
				
			||||||
    subject { generator.filter_excluded_tags(tags_mash_from_strings(%w(1 2 3))) }
 | 
					    subject { generator.filter_excluded_tags(tags_mash_from_strings(%w(1 2 3))) }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user