# File lib/code_climate/test_reporter/payload_validator.rb, line 6 def initialize(payload) @payload = payload end
# File lib/code_climate/test_reporter/payload_validator.rb, line 10 def self.validate(payload) new(payload).validate end
# File lib/code_climate/test_reporter/payload_validator.rb, line 14 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
# File lib/code_climate/test_reporter/payload_validator.rb, line 25 def commit_sha commit_sha_from_git || commit_sha_from_ci_service end
# File lib/code_climate/test_reporter/payload_validator.rb, line 53 def commit_sha_from_ci_service @payload[:ci_service] && @payload[:ci_service][:commit_sha] end
# File lib/code_climate/test_reporter/payload_validator.rb, line 49 def commit_sha_from_git @payload[:git] && @payload[:git][:head] end
# File lib/code_climate/test_reporter/payload_validator.rb, line 29 def committed_at @payload[:git] && @payload[:git][:committed_at] end
# File lib/code_climate/test_reporter/payload_validator.rb, line 33 def run_at @payload[:run_at] end
# File lib/code_climate/test_reporter/payload_validator.rb, line 37 def source_files? @payload[:source_files] && @payload[:source_files].any? end
# File lib/code_climate/test_reporter/payload_validator.rb, line 45 def valid_source_file?(file) file.is_a?(Hash) && file[:coverage] && file[:name] end
# File lib/code_climate/test_reporter/payload_validator.rb, line 41 def valid_source_files? @payload[:source_files].all? { |s| valid_source_file?(s) } end