17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/code_climate/test_reporter/client.rb', line 17
def batch_post_results(files)
uri = URI.parse("#{host}/test_reports/batch")
http = http_client(uri)
boundary = SecureRandom.uuid
post_body = []
post_body << "--#{boundary}\r\n"
post_body << "Content-Disposition: form-data; name=\"repo_token\"\r\n"
post_body << "\r\n"
post_body << ENV["CODECLIMATE_REPO_TOKEN"]
files.each_with_index do |file, index|
post_body << "\r\n--#{boundary}\r\n"
post_body << "Content-Disposition: form-data; name=\"coverage_reports[#{index}]\"; filename=\"#{File.basename(file)}\"\r\n"
post_body << "Content-Type: application/json\r\n"
post_body << "\r\n"
post_body << File.read(file)
end
post_body << "\r\n--#{boundary}--\r\n"
request = Net::HTTP::Post.new(uri.request_uri)
request.body = post_body.join
request["Content-Type"] = "multipart/form-data, boundary=#{boundary}"
response = http.request(request)
if response.code.to_i >= 200 && response.code.to_i < 300
response
else
raise "HTTP Error: #{response.code}"
end
end
|