Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: pass more params on webhook request #94

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion spec/coverage_reporter/api/webhook_spec.cr
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
require "../../spec_helper"

Spectator.describe CoverageReporter::Api::Webhook do
subject { described_class.new(config, "flag1,flag2") }
subject { described_class.new(config, "flag1,flag2", git_info) }

let(config) { CoverageReporter::Config.new("token") }
let(git_info) { {:branch => "chore/add-tests", :head => {:message => "add tests"}} }
let(endpoint) { "#{CoverageReporter::Config::DEFAULT_ENDPOINT}/webhook" }

after_each { WebMock.reset }
Expand All @@ -25,6 +26,12 @@ Spectator.describe CoverageReporter::Api::Webhook do
:build_num => nil,
:status => "done",
},
:git => {
:branch => "chore/add-tests",
:head => {
:message => "add tests",
},
},
}.to_json
end

Expand Down
19 changes: 19 additions & 0 deletions spec/coverage_reporter/cli/cmd_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,25 @@ Spectator.describe CoverageReporter::Cli do
end
end

context "without carryforward (new args)" do
let(options) do
%w(
done
-m
--build-number 3
--no-fail
)
end

it "doesn't fail" do
expect(subject).to eq 0
expect(reporter.carryforward).to eq nil
expect(reporter.overrides.try(&.to_h)).to eq({
:service_number => "3",
})
end
end

context "with format option" do
let(options) do
%w(
Expand Down
7 changes: 6 additions & 1 deletion src/coverage_reporter/api/webhook.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ require "json"

module CoverageReporter
class Api::Webhook
def initialize(@config : Config, @carryforward : String?)
def initialize(
@config : Config,
@carryforward : String?,
@git : Hash(Symbol, Hash(Symbol, String) | String)
)
end

def send_request(dry_run : Bool = false)
Expand All @@ -18,6 +22,7 @@ module CoverageReporter
:build_num => @config[:service_number]?,
:status => "done",
},
:git => @git,
}.compact)

Log.debug "---\n⛑ Debug Output:\n#{data.to_pretty_json}"
Expand Down
2 changes: 1 addition & 1 deletion src/coverage_reporter/cli/cmd.cr
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module CoverageReporter::Cli
overrides: opts.overrides,
parallel: opts.parallel?,
repo_token: opts.repo_token,
measure: opts.debug? || opts.measure?,
measure: opts.debug? || opts.measure?
)

if opts.parallel_done?
Expand Down
6 changes: 5 additions & 1 deletion src/coverage_reporter/reporter.cr
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ module CoverageReporter
# from a CI-specific ENV, or can be set explicitly via `COVERALLS_SERVICE_NUMBER`
# environment variable.
def parallel_done
api = Api::Webhook.new(config, settings.carryforward || config.carryforward)
api = Api::Webhook.new(
config: config,
carryforward: settings.carryforward || config.carryforward,
git: Git.info(config)
)

measure("Webhook request") do
api.send_request(settings.dry_run)
Expand Down