class Herkko::Travis

Checks status of CI build from Travis.

Public Instance Methods

status_for(branch) click to toggle source
# File lib/herkko/travis.rb, line 6
def status_for(branch)
  if travis_cli_installed?
    status = fetch_status(branch)
    status_to_code(status)
  else
    Herkko.info "Travis CLI has not been installed, run: gem install travis"
    :unknown
  end
end

Private Instance Methods

fetch_status(branch) click to toggle source
# File lib/herkko/travis.rb, line 18
def fetch_status(branch)
  Herkko.run(
    "travis",
    "history",
    "--skip-version-check",
    "-l",
    "1",
    "-b",
    branch
  )
end
status_to_code(status) click to toggle source
# File lib/herkko/travis.rb, line 34
def status_to_code(status)
  if !status[1].empty?
    Herkko.info "There was an error with checking Travis: #{status[1]}"
    :red
  elsif status[0].strip.empty?
    :not_used
  else
    case status[0].split(":")[0]
    when /passed/
      :green
    when /started/
      :yellow
    when /created/
      :queued
    else
      :red
    end
  end
end
travis_cli_installed?() click to toggle source
# File lib/herkko/travis.rb, line 30
def travis_cli_installed?
  system("command -v travis > /dev/null 2>&1")
end