Class: CIRunner::LogDownloader

Inherits:
Object
  • Object
show all
Defined in:
lib/ci_runner/log_downloader.rb

Overview

A PORO to help download and cache a GitHub CI log.

Examples:

Using the service

log_dl = LogDownloader.new(
  CICheck::GitHub.new(
    "catanacorp/catana",
    "commit_sha",
    "Tests Ruby 2.7",
    "failed",
    12345,
  )
)
log_file = log_dl.fetch
puts log_file # => File

Instance Method Summary collapse

Constructor Details

#initialize(check_run) ⇒ LogDownloader

Returns a new instance of LogDownloader.

Parameters:

  • check_run (Check::Base)

    A Base::Check subclass for which we want to download the log.



24
25
26
# File 'lib/ci_runner/log_downloader.rb', line 24

def initialize(check_run)
  @check_run = check_run
end

Instance Method Details

#fetch(&block) ⇒ Pathname

Ask the @check_run to download the log from its CI or retrieve it from disk in case we previously downloaded it.

Parameters:

  • block (Proc, Lambda)

    A proc that gets called if fetching the logs from GitHub fails. Allows the CLI to prematurely exit while cleaning up the CLI::UI frame.

Returns:

  • (Pathname)

    The path to the log file.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/ci_runner/log_downloader.rb', line 34

def fetch(&block)
  return cached_log if cached_log

  error = nil

  ::CLI::UI.spinner("Downloading CI logs from #{@check_run.provider}", auto_debrief: false) do
    cache_log(@check_run.download_log)
  rescue Client::Error, Error => e
    error = e

    ::CLI::UI::Spinner::TASK_FAILED
  end

  block.call(error) if error

  cached_log
end