lib/datadog/ci/transport/api/base.rb in datadog-ci-0.8.3 vs lib/datadog/ci/transport/api/base.rb in datadog-ci-1.0.0.beta1

- old
+ new

@@ -1,7 +1,9 @@ # frozen_string_literal: true +require "securerandom" + require_relative "../../ext/transport" module Datadog module CI module Transport @@ -11,9 +13,30 @@ headers[Ext::Transport::HEADER_CONTENT_TYPE] ||= Ext::Transport::CONTENT_TYPE_JSON end def citestcycle_request(path:, payload:, headers: {}, verb: "post") headers[Ext::Transport::HEADER_CONTENT_TYPE] ||= Ext::Transport::CONTENT_TYPE_MESSAGEPACK + end + + def citestcov_request(path:, payload:, headers: {}, verb: "post") + citestcov_request_boundary = ::SecureRandom.uuid + + headers[Ext::Transport::HEADER_CONTENT_TYPE] ||= + "#{Ext::Transport::CONTENT_TYPE_MULTIPART_FORM_DATA}; boundary=#{citestcov_request_boundary}" + + @citestcov_payload = [ + "--#{citestcov_request_boundary}", + 'Content-Disposition: form-data; name="event"; filename="event.json"', + "Content-Type: application/json", + "", + '{"dummy":true}', + "--#{citestcov_request_boundary}", + 'Content-Disposition: form-data; name="coverage1"; filename="coverage1.msgpack"', + "Content-Type: application/msgpack", + "", + payload, + "--#{citestcov_request_boundary}--" + ].join("\r\n") end def headers_with_default(headers) request_headers = default_headers request_headers.merge!(headers)