Sha256: 2a1cfd90e6788d62f32b8546bffcf9194e8691843a618e791874b71db5e808eb

Contents?: true

Size: 1.6 KB

Versions: 19

Compression:

Stored size: 1.6 KB

Contents

module CodeClimate
  module TestReporter
    InvalidPayload = Class.new(StandardError)

    class PayloadValidator
      def initialize(payload)
        @payload = payload
      end

      def self.validate(payload)
        new(payload).validate
      end

      def validate
        raise InvalidPayload, "A git commit sha was not found in the test report payload" unless commit_sha
        raise InvalidPayload, "A git commit timestamp was not found in the test report payload" unless committed_at
        raise InvalidPayload, "A run at timestamp was not found in the test report payload" unless run_at
        raise InvalidPayload, "No source files were found in the test report payload" unless source_files?
        raise InvalidPayload, "Invalid source files were found in the test report payload" unless valid_source_files?
        true
      end

    private

      def commit_sha
        commit_sha_from_git || commit_sha_from_ci_service
      end

      def committed_at
        @payload[:git] && @payload[:git][:committed_at]
      end

      def run_at
        @payload[:run_at]
      end

      def source_files?
        @payload[:source_files] && @payload[:source_files].any?
      end

      def valid_source_files?
        @payload[:source_files].all? { |s| valid_source_file?(s) }
      end

      def valid_source_file?(file)
        file.is_a?(Hash) && file[:coverage] && file[:name]
      end

      def commit_sha_from_git
        @payload[:git] && @payload[:git][:head]
      end

      def commit_sha_from_ci_service
        @payload[:ci_service] && @payload[:ci_service][:commit_sha]
      end
    end

  end
end

Version data entries

19 entries across 17 versions & 3 rubygems

Version Path
codeclimate-test-reporter-0.5.0 lib/code_climate/test_reporter/payload_validator.rb
honeybadger-2.4.0 vendor/gems/ruby/2.1.0/gems/codeclimate-test-reporter-0.4.0/lib/code_climate/test_reporter/payload_validator.rb
honeybadger-2.4.0 vendor/gems/ruby/2.2.0/gems/codeclimate-test-reporter-0.4.0/lib/code_climate/test_reporter/payload_validator.rb
honeybadger-2.4.0 vendor/gems/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.0/lib/code_climate/test_reporter/payload_validator.rb
codeclimate-test-reporter-0.4.8 lib/code_climate/test_reporter/payload_validator.rb
construi-0.6.0 vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/lib/code_climate/test_reporter/payload_validator.rb
construi-0.5.0 vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/lib/code_climate/test_reporter/payload_validator.rb
construi-0.4.0 vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/lib/code_climate/test_reporter/payload_validator.rb
construi-0.2.0 vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/lib/code_climate/test_reporter/payload_validator.rb
construi-0.1.0 vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/lib/code_climate/test_reporter/payload_validator.rb
codeclimate-test-reporter-0.4.7 lib/code_climate/test_reporter/payload_validator.rb
codeclimate-test-reporter-0.4.6 lib/code_climate/test_reporter/payload_validator.rb
codeclimate-test-reporter-0.4.5 lib/code_climate/test_reporter/payload_validator.rb
codeclimate-test-reporter-0.4.4 lib/code_climate/test_reporter/payload_validator.rb
codeclimate-test-reporter-0.4.3 lib/code_climate/test_reporter/payload_validator.rb
codeclimate-test-reporter-0.4.2 lib/code_climate/test_reporter/payload_validator.rb
codeclimate-test-reporter-0.4.1 lib/code_climate/test_reporter/payload_validator.rb
codeclimate-test-reporter-0.4.0 lib/code_climate/test_reporter/payload_validator.rb
codeclimate-test-reporter-0.3.0 lib/code_climate/test_reporter/payload_validator.rb