Skip to content

Commit

Permalink
fix: use stdlib http client
Browse files Browse the repository at this point in the history
  • Loading branch information
mrexox committed Jun 27, 2023
1 parent 5aa64c3 commit e52fcc3
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 20 deletions.
12 changes: 0 additions & 12 deletions shard.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ shards:
git: https://github.com/crystal-ameba/ameba.git
version: 1.4.2

crest:
git: https://github.com/mamantoha/crest.git
version: 1.3.8

crystal-kcov:
git: https://github.com/vici37/crystal-kcov.git
version: 0.2.3+git.commit.7e49fe22d7d47040c9de77eb77a6daa76ce0655d
Expand All @@ -16,14 +12,6 @@ shards:
git: https://github.com/crystal-lang/crystal-db.git
version: 0.11.0

http-client-digest_auth:
git: https://github.com/mamantoha/http-client-digest_auth.git
version: 0.6.0

http_proxy:
git: https://github.com/mamantoha/http_proxy.git
version: 0.9.0

spectator:
git: https://gitlab.com/arctic-fox/spectator.git
version: 0.11.6
Expand Down
2 changes: 0 additions & 2 deletions shard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ authors:
- Nick Merwin <[email protected]>

dependencies:
crest:
github: mamantoha/crest
sqlite3:
github: crystal-lang/crystal-sqlite3

Expand Down
17 changes: 15 additions & 2 deletions spec/coverage_reporter/api/jobs_spec.cr
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require "../../spec_helper"
require "http"

Spectator.describe CoverageReporter::Api::Jobs do
subject { described_class.new(config, parallel, source_files, git_info) }
Expand Down Expand Up @@ -55,15 +56,27 @@ Spectator.describe CoverageReporter::Api::Jobs do
Compress::Gzip::Writer.open(io, &.print(data))
end

io = IO::Memory.new
channel = Channel(String).new(1)

boundary = CoverageReporter::Api::Jobs::BOUNDARY
HTTP::FormData.build(io, boundary) do |formdata|
channel.send(formdata.content_type)

metadata = HTTP::FormData::FileMetadata.new(filename: "json_file")
headers = HTTP::Headers{"Content-Type" => "application/gzip"}
formdata.file("json_file", IO::Memory.new(body), metadata, headers)
end

WebMock.stub(:post, endpoint).with(
headers: {
"Content-Type" => "application/gzip",
"Content-Type" => "multipart/form-data; boundary=#{boundary}",
"X-Coveralls-Reporter" => "coverage-reporter",
"X-Coveralls-Reporter-Version" => CoverageReporter::VERSION,
"X-Coveralls-Coverage-Formats" => "cobertura",
"X-Coveralls-Source" => "cli",
},
body: body,
body: io.to_s,
).to_return(status: 200, body: {:result => "ok"}.to_json)

subject.send_request
Expand Down
9 changes: 6 additions & 3 deletions src/coverage_reporter/api/jobs.cr
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require "json"
module CoverageReporter
class Api::Jobs
API_VERSION = "v1"
BOUNDARY = "CoverageReporterBoundary".rjust(50, '-')

def initialize(
@config : Config,
Expand Down Expand Up @@ -56,7 +57,9 @@ module CoverageReporter
end

with_file(IO::Memory.new(gzipped_json)) do |content_type, body|
headers.merge!(HTTP::Headers{"Content-Type" => content_type})
# NOTE: Removing quotes from boundary -- required by Coveralls.io nginx rule
headers.merge!(HTTP::Headers{"Content-Type" => content_type.gsub("\"", "")})

response = HTTP::Client.post(
api_url,
body: body,
Expand Down Expand Up @@ -84,11 +87,11 @@ module CoverageReporter
channel = Channel(String).new(1)

spawn do
HTTP::FormData.build(writer) do |formdata|
HTTP::FormData.build(writer, BOUNDARY) do |formdata|
channel.send(formdata.content_type)

metadata = HTTP::FormData::FileMetadata.new(filename: "json_file")
headers = HTTP::Headers{"Content-Type" => "application/x-gzip"}
headers = HTTP::Headers{"Content-Type" => "application/gzip"}
formdata.file("json_file", gzfile, metadata, headers)
end

Expand Down
1 change: 0 additions & 1 deletion src/coverage_reporter/api/webhook.cr
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# require "crest"
require "http"
require "json"

Expand Down

0 comments on commit e52fcc3

Please sign in to comment.