Sha256: b1e7db3fe6d608b4dff8b734c336212eb35277bc7a70f07f046b40bb2eb53a2d

Contents?: true

Size: 1.99 KB

Versions: 16

Compression:

Stored size: 1.99 KB

Contents

module CodeClimate
  module TestReporter
    WARNING_MESSAGE = <<-EOS.freeze
      This usage of the Code Climate Test Reporter is now deprecated. Since version
      1.0, we now require you to run `SimpleCov` in your test/spec helper, and then
      run the provided `codeclimate-test-reporter` binary separately to report your
      results to Code Climate.

      More information here: https://github.com/codeclimate/ruby-test-reporter/blob/master/README.md
    EOS

    def self.start
      logger.warn(WARNING_MESSAGE)
      exit(1)
    end

    def self.run(results)
      return unless CodeClimate::TestReporter.run?
      formatted_results = CodeClimate::TestReporter::Formatter.new.format(results)
      CodeClimate::TestReporter::PostResults.new(formatted_results).post
    end

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

    def self.environment_variable_set?
      return @environment_variable_set if defined?(@environment_variable_set)

      @environment_variable_set = !!ENV["CODECLIMATE_REPO_TOKEN"]
      if @environment_variable_set
        logger.info("Reporting coverage data to Code Climate.")
      end

      @environment_variable_set
    end

    def self.run_on_current_branch?
      return @run_on_current_branch if defined?(@run_on_current_branch)

      @run_on_current_branch = 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

    def self.tddium?
      ci_service_data && ci_service_data[:name] == "tddium"
    end

    def self.ci_service_data
      Ci.service_data
    end
  end
end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
codeclimate-test-reporter-1.0.9 lib/code_climate/test_reporter.rb
dirwatch-0.0.9 vendor/bundle/ruby/2.5.0/gems/codeclimate-test-reporter-1.0.8/lib/code_climate/test_reporter.rb
dirwatch-0.0.8 vendor/bundle/ruby/2.5.0/gems/codeclimate-test-reporter-1.0.8/lib/code_climate/test_reporter.rb
dirwatch-0.0.6 vendor/bundle/ruby/2.3.0/gems/codeclimate-test-reporter-1.0.8/lib/code_climate/test_reporter.rb
dirwatch-0.0.5 vendor/bundle/ruby/2.3.0/gems/codeclimate-test-reporter-1.0.8/lib/code_climate/test_reporter.rb
dirwatch-0.0.4 vendor/bundle/ruby/2.3.0/gems/codeclimate-test-reporter-1.0.8/lib/code_climate/test_reporter.rb
dirwatch-0.0.3 vendor/bundle/ruby/2.3.0/gems/codeclimate-test-reporter-1.0.8/lib/code_climate/test_reporter.rb
dirwatch-0.0.2 vendor/bundle/ruby/2.3.0/gems/codeclimate-test-reporter-1.0.8/lib/code_climate/test_reporter.rb
codeclimate-test-reporter-1.0.8 lib/code_climate/test_reporter.rb
codeclimate-test-reporter-1.0.7 lib/code_climate/test_reporter.rb
codeclimate-test-reporter-1.0.6 lib/code_climate/test_reporter.rb
codeclimate-test-reporter-1.0.5 lib/code_climate/test_reporter.rb
codeclimate-test-reporter-1.0.4 lib/code_climate/test_reporter.rb
codeclimate-test-reporter-1.0.3 lib/code_climate/test_reporter.rb
codeclimate-test-reporter-1.0.2 lib/code_climate/test_reporter.rb
codeclimate-test-reporter-1.0.1 lib/code_climate/test_reporter.rb