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, #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, #logout, #regenerate_token, #remove_token, #repo, #repos, #restart, #user

Methods inherited from Command

abstract, abstract?, #check_completion, #check_ruby, #check_version, command_name, #command_name, #debug?, description, #error, #execute, #help, #info, #initialize, #last_check, #on_signal, #parse, #say, #setup, skip, subcommands, #terminal, #time, #usage, #usage_for, #warn, #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:



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

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



34
35
36
37
38
# File 'lib/travis/cli/report.rb', line 34

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

#display_errorObject



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

def display_error
  return unless (error = load_file('error.log'))

  display('Last Exception', :say, color(error, :info))
end

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



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

def endpoint_name(url, prefix = '')
  case url
  when Travis::Client::COM_URI  then "#{prefix}com"
  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 } if config['enterprise'].respond_to?(:detect)
    key ? 'enterprise %p' % key : '???'
  end
end

#endpointsObject



72
73
74
75
76
77
78
79
80
81
82
# File 'lib/travis/cli/report.rb', line 72

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:



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

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

#known_reposObject



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

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

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



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/travis/cli/report.rb', line 40

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



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/travis/cli/report.rb', line 13

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:



65
66
67
68
69
70
# File 'lib/travis/cli/report.rb', line 65

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

#user_infoObject



100
101
102
103
104
# File 'lib/travis/cli/report.rb', line 100

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