Sha256: 8c4ce1c54cc5d6df7bf26294d3aa9386ffef1dd297b11e1531ab93e7ad2a9086

Contents?: true

Size: 1.19 KB

Versions: 2

Compression:

Stored size: 1.19 KB

Contents

module CodeClimate
  module TestReporter

    def self.start
      if run?
        require "simplecov"
        ::SimpleCov.add_filter 'vendor'
        ::SimpleCov.formatter = Formatter
        ::SimpleCov.start(configuration.profile)
      end
    end

    def self.run?
      environment_variable_set? && run_on_current_branch?
    end

    def self.environment_variable_set?
      environment_variable_set = !!ENV["CODECLIMATE_REPO_TOKEN"]
      unless environment_variable_set
        logger.info("Not reporting to Code Climate because ENV['CODECLIMATE_REPO_TOKEN'] is not set.")
      end

      environment_variable_set
    end

    def self.run_on_current_branch?
      return true if configured_branch.nil?

      run_on_current_branch = !!(current_branch =~ /#{configured_branch}/i)
      unless run_on_current_branch
        logger.info("Not reporting to Code Climate because #{configured_branch} is set as the reporting branch.")
      end

      run_on_current_branch
    end

    def self.configured_branch
      configuration.branch
    end

    def self.current_branch
      Git.branch_from_git_or_ci
    end

    def self.logger
      CodeClimate::TestReporter.configuration.logger
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
codeclimate-test-reporter-0.3.0 lib/code_climate/test_reporter.rb
codeclimate-test-reporter-0.2.0 lib/code_climate/test_reporter.rb