Class: Henitai::Reporter::Dashboard

Inherits:
Base
  • Object
show all
Defined in:
lib/henitai/reporter.rb

Overview

Dashboard reporter.

Constant Summary collapse

DEFAULT_BASE_URL =
"https://dashboard.stryker-mutator.io"
HTTP_TIMEOUT_SECONDS =
30

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Henitai::Reporter::Base

Class Method Details

.normalize_git_url(url) ⇒ Object



505
506
507
508
509
# File 'lib/henitai/reporter.rb', line 505

def normalize_git_url(url)
  return nil if url.nil? || url.strip.empty?

  url.strip.sub(/\.git\z/, "")
end

.project_from_git_url(url) ⇒ Object



493
494
495
496
497
498
499
500
501
502
503
# File 'lib/henitai/reporter.rb', line 493

def project_from_git_url(url)
  normalized = normalize_git_url(url)
  return nil if normalized.nil?

  return project_from_uri_url(normalized) if normalized.include?("://")
  return project_from_ssh_url(normalized) if normalized.include?("@")

  normalized
rescue URI::InvalidURIError
  nil
end

.project_from_ssh_url(normalized) ⇒ Object



517
518
519
520
521
522
523
524
525
# File 'lib/henitai/reporter.rb', line 517

def project_from_ssh_url(normalized)
  _, host_and_path = normalized.split("@", 2)
  return nil if host_and_path.nil?

  host, path = host_and_path.split(":", 2)
  return nil unless host && path

  "#{host}/#{path}"
end

.project_from_uri_url(normalized) ⇒ Object



511
512
513
514
515
# File 'lib/henitai/reporter.rb', line 511

def project_from_uri_url(normalized)
  uri = URI.parse(normalized)
  path = uri.path.to_s.sub(%r{^/}, "")
  [uri.host, path].compact.reject(&:empty?).join("/")
end

Instance Method Details

#report(result) ⇒ Object



375
376
377
378
379
380
381
# File 'lib/henitai/reporter.rb', line 375

def report(result)
  return unless ready?

  uri = dashboard_uri
  request = build_request(result, uri)
  send_request(uri, request)
end