Class: Travis::CLI::Report

Inherits:
ApiCommand show all
Defined in:
lib/travis/cli/report.rb

Constant Summary

Constants inherited from Command

Command::DAY, Command::HOUR, Command::MINUTE, Command::WEEK

Constants included from Tools::Assets

Tools::Assets::BASE

Instance Attribute Summary

Attributes inherited from ApiCommand

#enterprise_name, #session

Attributes inherited from Command

#arguments, #config, #debug, #force_interactive, #formatter, #input, #output

Instance Method Summary collapse

Methods inherited from ApiCommand

#authenticate, #detected_endpoint?, #endpoint_config, #enterprise?, #initialize, #org?, #pro?, #setup, #sync

Methods included from Travis::Client::Methods

#access_token, #access_token=, #account, #accounts, #api_endpoint, #api_endpoint=, #artifact, #broadcasts, #build, #cancel, #explicit_api_endpoint?, #github_auth, #hooks, #job, #lint, #listen, #repo, #repos, #restart, #user

Methods inherited from Command

abstract, abstract?, #check_completion, #check_ruby, #check_version, command_name, #command_name, #debug?, description, #execute, #help, #info, #initialize, #last_check, #on_signal, #parse, #say, #setup, skip, subcommands, #terminal, #time, #usage, #usage_for, #write_to

Methods included from Tools::Assets

#asset, #asset_path

Methods included from Parser

#new, #on, #on_initialize

Constructor Details

This class inherits a constructor from Travis::CLI::ApiCommand

Instance Method Details

#cli_info {|"Version", Travis::VERSION| ... } ⇒ Object

Yields:



51
52
53
54
55
56
# File 'lib/travis/cli/report.rb', line 51

def cli_info
  yield "Version",            Travis::VERSION
  yield "Plugins",            defined?(TRAVIS_PLUGINS) ? TRAVIS_PLUGINS : []
  yield "Auto-Completion",    Tools::Completion.completion_installed?
  yield "Last Version Check", last_check['at'] ? Time.at(last_check['at']) : 'never'
end

#display(title, method, *args) ⇒ Object



27
28
29
30
31
# File 'lib/travis/cli/report.rb', line 27

def display(title, method, *args)
  say color(title, [:bold, :underline])
  send(method, *args) { |*a| list(*a) }
  puts
end

#display_errorObject



22
23
24
25
# File 'lib/travis/cli/report.rb', line 22

def display_error
  return unless error = load_file("error.log")
  display("Last Exception", :say, color(error, :info))
end

#endpoint_name(url, prefix = "") ⇒ Object



77
78
79
80
81
82
83
84
85
86
# File 'lib/travis/cli/report.rb', line 77

def endpoint_name(url, prefix = "")
  case url
  when Travis::Client::ORG_URI  then "#{prefix}org"
  when Travis::Client::PRO_URI  then "#{prefix}pro"
  when /api-staging\.travis-ci/ then endpoint_name(url.sub("api-staging.", "api."), "staging-")
  else
    key, _ = config['enterprise'].detect { |k,v| v.start_with? url }
    key ? "enterprise %p" % key : "???"
  end
end

#endpointsObject



65
66
67
68
69
70
71
72
73
74
75
# File 'lib/travis/cli/report.rb', line 65

def endpoints
  config['endpoints'].each do |endpoint, info|
    info = [
      info['access_token']         ? 'access token' : nil,
      info['insecure']             ? 'insecure'     : nil,
      default_endpoint == endpoint ? 'default'      : nil,
      endpoint == api_endpoint     ? 'current'      : nil
    ].compact
    yield endpoint_name(endpoint), endpoint, info.join(', ')
  end
end

#general {|"Ruby", Tools::System.ruby| ... } ⇒ Object

Yields:



45
46
47
48
49
# File 'lib/travis/cli/report.rb', line 45

def general
  yield "Ruby",               Tools::System.ruby
  yield "Operating System",   Tools::System.os
  yield "RubyGems",           Tools::System.rubygems
end

#known_reposObject



88
89
90
91
92
# File 'lib/travis/cli/report.rb', line 88

def known_repos
  config["repos"].each do |key, info|
    yield key, info['endpoint']
  end
end

#list(key, value, additional = nil) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/travis/cli/report.rb', line 33

def list(key, value, additional = nil)
  value = case value
          when Array then value.empty? ? 'none' : value.map(&:inspect).join(", ")
          when true  then "yes"
          when false then "no"
          when nil   then "unknown"
          else value.to_s
          end
  additional &&= " (#{additional})"
  say "#{key}:".ljust(known_repos? ? 50 : 25) << " " << color(value.to_s, :bold) << additional.to_s
end

#runObject



11
12
13
14
15
16
17
18
19
20
# File 'lib/travis/cli/report.rb', line 11

def run
  display("System",    :general)
  display("CLI",       :cli_info)
  display("Session",   :session_info)
  display("Endpoints", :endpoints)
  display("Known Repositories", :known_repos) if known_repos?
  display_error
  say "For issues with the command line tool, please visit #{color("https://github.com/travis-ci/travis.rb/issues", :underline)}."
  say "For Travis CI in general, go to #{color("https://github.com/travis-ci/travis-ci/issues", :underline)} or email #{color("[email protected]", :underline)}."
end

#session_info {|"API Endpoint", api_endpoint| ... } ⇒ Object

Yields:



58
59
60
61
62
63
# File 'lib/travis/cli/report.rb', line 58

def session_info
  yield "API Endpoint",       api_endpoint
  yield "Logged In",          
  yield "Verify SSL",         !insecure
  yield "Enterprise",         enterprise?
end

#user_infoObject



94
95
96
97
98
# File 'lib/travis/cli/report.rb', line 94

def 
  access_token ? "as %p" % user. : "no"
rescue Travis::Client::Error => e
  e.message
end