class BuildMetricsLogger

Public Class Methods

new(token = nil) click to toggle source
# File lib/build_metrics_logger.rb, line 4
def initialize(token = nil)
  @token = token
  @build_id = ENV.fetch('BUILD_METRICS_LOGGER_ID')
end

Public Instance Methods

build_result_url() click to toggle source
# File lib/build_metrics_logger.rb, line 51
def build_result_url
  "https://build-metrics-web.herokuapp.com/api/builds/#{@build_id}/result"
end
dump_summary(notification) click to toggle source
# File lib/build_metrics_logger.rb, line 9
def dump_summary(notification)
  suite_finished(notification)
end
example_failed(notification) click to toggle source
# File lib/build_metrics_logger.rb, line 17
def example_failed(notification)
  example_finished(notification)
end
example_finished(notification) click to toggle source
# File lib/build_metrics_logger.rb, line 21
def example_finished(notification)
  if notification.example.metadata[:e2e] == true && ENV.fetch('IS_LOCAL', 'true') == 'false'
    id = notification.example.id.to_s
    description = notification.example.full_description.to_s
    location = notification.example.location.to_s
    passed = notification.example.execution_result.status.to_s == 'passed' ? true : false
    time = notification.example.execution_result.run_time.to_s
    exception = notification.example.execution_result.exception.to_s.empty? ? "nil" : notification.example.execution_result.exception.to_s
    test_data = {id: id, description: description, location: location, passed: passed, time: time, exception: exception}
    if @token
      log_example_result(test_data)
    end
  end
end
example_passed(notification) click to toggle source
# File lib/build_metrics_logger.rb, line 13
def example_passed(notification)
  example_finished(notification)
end
example_result_url() click to toggle source
# File lib/build_metrics_logger.rb, line 47
def example_result_url
  "https://build-metrics-web.herokuapp.com/api/builds/#{@build_id}/tests/result"
end
log_build_result(data) click to toggle source
# File lib/build_metrics_logger.rb, line 70
def log_build_result(data)
  HTTParty.post(build_result_url,
    headers: {
      "Authorization" => "Bearer #{@token}"
    },
    body: {
      passed: data[:passed],
      runtime: data[:time],
      build: @build_id
    }
  )
end
log_example_result(data) click to toggle source
# File lib/build_metrics_logger.rb, line 55
def log_example_result(data)
  HTTParty.post(example_result_url,
    headers: {
      "Authorization" => "Bearer #{@token}"
    },
    body: {
      passed: data[:passed],
      rspecID: data[:id],
      description: data[:description],
      path: data[:location],
      runtime: data[:time]
    }
  )
end
suite_finished(notification) click to toggle source
# File lib/build_metrics_logger.rb, line 36
def suite_finished(notification)
  if notification.examples[0].metadata[:e2e] == true && ENV.fetch('IS_LOCAL', 'true') == 'false'
    time = notification.duration
    passed = notification.failure_count == 0 ? true : false
    build_data = {time: time, passed: passed}
    if @token
      log_build_result(build_data)
    end
  end
end