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: allow specifying endpoint in yaml config #48

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
2 changes: 1 addition & 1 deletion spec/coverage_reporter/api/jobs_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Spectator.describe CoverageReporter::Api::Jobs do
]
end

let(endpoint) { "#{CoverageReporter::Api::DEFAULT_DOMAIN}/api/#{CoverageReporter::Api::API_VERSION}/jobs" }
let(endpoint) { "#{CoverageReporter::Config::DEFAULT_ENDPOINT}/api/#{CoverageReporter::Api::Jobs::API_VERSION}/jobs" }

before_each do
ENV["COVERALLS_RUN_AT"] = Time::Format::RFC_3339.format(Time.local)
Expand Down
2 changes: 1 addition & 1 deletion spec/coverage_reporter/api/webhook_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Spectator.describe CoverageReporter::Api::Webhook do
subject { described_class.new(config, "flag1,flag2") }

let(config) { CoverageReporter::Config.new("token") }
let(endpoint) { "#{CoverageReporter::Api::DEFAULT_DOMAIN}/webhook" }
let(endpoint) { "#{CoverageReporter::Config::DEFAULT_ENDPOINT}/webhook" }

after_each { WebMock.reset }

Expand Down
19 changes: 0 additions & 19 deletions src/coverage_reporter/api.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,9 @@ module CoverageReporter
module Api
extend self

API_VERSION = "v1"
DEFAULT_DOMAIN = "https://coveralls.io"
LOCAL_DOMAIN = "http://localhost:3000"

def show_response(res)
# TODO: include info about account status
Log.info "---\n✅ API Response: #{res.body}\n- 💛, Coveralls"
end

def uri(path)
if ENV["COVERALLS_ENDPOINT"]?.presence
domain = ENV["COVERALLS_ENDPOINT"]
else
domain =
if ENV["COVERALLS_DEVELOPMENT"]?.presence
LOCAL_DOMAIN
else
DEFAULT_DOMAIN
end
end

"#{domain}/#{path}"
end
end
end
4 changes: 3 additions & 1 deletion src/coverage_reporter/api/jobs.cr
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ module CoverageReporter
class Api::Jobs
@source : Array(Hash(Symbol, String | Array(Int64?) | Array(Int64)))

API_VERSION = "v1"

def initialize(
@config : Config,
@parallel : Bool,
Expand All @@ -24,7 +26,7 @@ module CoverageReporter

def send_request(dry_run : Bool = false)
data = build_request
api_url = Api.uri("api/#{API_VERSION}/jobs")
api_url = "#{@config.endpoint}/api/#{API_VERSION}/jobs"

Log.info " ·job_flag: #{@config.flag_name}" if @config.flag_name
Log.info "🚀 Posting coverage data to #{api_url}"
Expand Down
2 changes: 1 addition & 1 deletion src/coverage_reporter/api/webhook.cr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module CoverageReporter
end

def send_request(dry_run : Bool = false)
webhook_url = Api.uri("webhook")
webhook_url = "#{@config.endpoint}/webhook"

Log.info "⭐️ Calling parallel done webhook: #{webhook_url}"

Expand Down
15 changes: 15 additions & 0 deletions src/coverage_reporter/config.cr
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ module CoverageReporter
CI::Local,
}

DEFAULT_ENDPOINT = "https://coveralls.io"
LOCAL_ENDPOINT = "http://localhost:3000"

def initialize(
repo_token : String?,
path : String? = "",
Expand Down Expand Up @@ -71,6 +74,18 @@ module CoverageReporter
}.compact)
end

def endpoint
if ENV["COVERALLS_ENDPOINT"]?.presence
return ENV["COVERALLS_ENDPOINT"]
end

if ENV["COVERALLS_DEVELOPMENT"]?.presence
return LOCAL_ENDPOINT
end

@yaml.endpoint.presence || DEFAULT_ENDPOINT
end

private def ci_options : Hash(Symbol, String)
CI_OPTIONS.each do |ci|
res = ci.options
Expand Down
1 change: 1 addition & 0 deletions src/coverage_reporter/yaml_config.cr
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module CoverageReporter
property repo_token : String?
property repo_secret_token : String?
property repo_name : String?
property endpoint : String?

DEFAULT_LOCATION = ".coveralls.yml"

Expand Down