Merge branch 'master' into develop
This commit is contained in:
		
						commit
						4f64cdb7d5
					
				@ -4,33 +4,34 @@ module GitHubChangelogGenerator
 | 
			
		||||
      @options = options
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def file
 | 
			
		||||
      File.expand_path(@options[:params_file] || ".github_changelog_generator")
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def file?
 | 
			
		||||
      File.exist?(file)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def file_open
 | 
			
		||||
      File.open(file)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def parse!
 | 
			
		||||
      return unless file?
 | 
			
		||||
      file_open.each do |line|
 | 
			
		||||
        begin
 | 
			
		||||
          key, value = line.split("=")
 | 
			
		||||
          key_sym = key.sub("-", "_").to_sym
 | 
			
		||||
          value = value.gsub(/[\n\r]+/, "")
 | 
			
		||||
          value = true if value =~ (/^(true|t|yes|y|1)$/i)
 | 
			
		||||
          value = false if value =~ (/^(false|f|no|n|0)$/i)
 | 
			
		||||
          @options[key_sym] = value
 | 
			
		||||
        rescue
 | 
			
		||||
          raise "File #{file} is incorrect in line \"#{line.gsub(/[\n\r]+/, '')}\""
 | 
			
		||||
        end
 | 
			
		||||
      end
 | 
			
		||||
      @options
 | 
			
		||||
      return unless File.exist?(file)
 | 
			
		||||
 | 
			
		||||
      File.readlines(file).each { |line| parse_line!(line) }
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    private
 | 
			
		||||
 | 
			
		||||
    def file
 | 
			
		||||
      @file ||= File.expand_path(@options[:params_file] || ".github_changelog_generator")
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def parse_line!(line)
 | 
			
		||||
      key_sym, value = extract_pair(line)
 | 
			
		||||
      value = true if value =~ (/^(true|t|yes|y|1)$/i)
 | 
			
		||||
      value = false if value =~ (/^(false|f|no|n|0)$/i)
 | 
			
		||||
      @options[key_sym] = value
 | 
			
		||||
    rescue
 | 
			
		||||
      raise "Config file #{file} is incorrect in line \"#{line.gsub(/[\n\r]+/, '')}\""
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    # Returns a the setting as a symbol and its string value sans newlines.
 | 
			
		||||
    #
 | 
			
		||||
    # @param line [String] unparsed line from config file
 | 
			
		||||
    # @return [Array<Symbol, String>]
 | 
			
		||||
    def extract_pair(line)
 | 
			
		||||
      key, value = line.split("=", 2)
 | 
			
		||||
      [key.sub("-", "_").to_sym, value.gsub(/[\n\r]+/, "")]
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
@ -16,7 +16,7 @@ module GitHubChangelogGenerator
 | 
			
		||||
                  bug_labels enhancement_labels
 | 
			
		||||
                  between_tags exclude_tags since_tag max_issues
 | 
			
		||||
                  github_site github_endpoint simple_list
 | 
			
		||||
                  future_release verbose release_url )
 | 
			
		||||
                  future_release verbose release_url base )
 | 
			
		||||
 | 
			
		||||
    OPTIONS.each do |o|
 | 
			
		||||
      attr_accessor o.to_sym
 | 
			
		||||
 | 
			
		||||
@ -1,2 +1,3 @@
 | 
			
		||||
unreleased_label=staging
 | 
			
		||||
unreleased=false
 | 
			
		||||
header==== Changelog ===
 | 
			
		||||
 | 
			
		||||
@ -10,23 +10,32 @@ describe GitHubChangelogGenerator::ParserFile do
 | 
			
		||||
    context "when file is empty" do
 | 
			
		||||
      let(:options) { { params_file: "spec/files/github_changelog_params_empty" } }
 | 
			
		||||
      let(:parse) { GitHubChangelogGenerator::ParserFile.new(options) }
 | 
			
		||||
      subject { parse.parse! }
 | 
			
		||||
      it { is_expected.to be_a(Hash) }
 | 
			
		||||
      it { is_expected.to eq(options) }
 | 
			
		||||
 | 
			
		||||
      it "does not change the options" do
 | 
			
		||||
        expect { parse.parse! }.to_not change { options }
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    context "when file is incorrect" do
 | 
			
		||||
      let(:options) { { params_file: "spec/files/github_changelog_params_incorrect" } }
 | 
			
		||||
      let(:options_before_change) { options.dup }
 | 
			
		||||
      let(:parse) { GitHubChangelogGenerator::ParserFile.new(options) }
 | 
			
		||||
      it { expect { fail.raise! }.to raise_error RuntimeError }
 | 
			
		||||
      it { expect { parse.parse! }.to raise_error }
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    context "when override default values" do
 | 
			
		||||
      let(:options) { { params_file: "spec/files/github_changelog_params_override" }.merge(GitHubChangelogGenerator::Parser.get_default_options) }
 | 
			
		||||
      let(:default_options) { GitHubChangelogGenerator::Parser.get_default_options }
 | 
			
		||||
      let(:options) { { params_file: "spec/files/github_changelog_params_override" }.merge(default_options) }
 | 
			
		||||
      let(:options_before_change) { options.dup }
 | 
			
		||||
      let(:parse) { GitHubChangelogGenerator::ParserFile.new(options) }
 | 
			
		||||
      subject { parse.parse! }
 | 
			
		||||
      it { is_expected.to be_a(Hash) }
 | 
			
		||||
      it { is_expected.to eq(options.merge(unreleased_label: "staging", unreleased: false)) }
 | 
			
		||||
 | 
			
		||||
      it "changes the options" do
 | 
			
		||||
        expect { parse.parse! }.to change { options }
 | 
			
		||||
          .from(options_before_change)
 | 
			
		||||
          .to(options_before_change.merge(unreleased_label: "staging",
 | 
			
		||||
                                          unreleased: false,
 | 
			
		||||
                                          header: "=== Changelog ==="))
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user