Class: CIRunner::CLI

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/ci_runner/cli.rb', line 10

def self.exit_on_failure?
  true
end

Instance Method Details

#circle_ci_token(token) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/ci_runner/cli.rb', line 101

def circle_ci_token(token)
  ::CLI::UI::StdoutRouter.enable

  ::CLI::UI.frame("Saving CircleCI Token") do
    user = Client::CircleCI.new(token).me
    Configuration::User.instance.save_circle_ci_token(token)

    ::CLI::UI.puts(<<~EOM)
      Hello {{warning:#{user["login"]}}}! {{success:Your token is valid!}}

      {{info:The token has been saved in this file: #{Configuration::User.instance.config_file}}}
    EOM
  rescue Client::Error => e
    ::CLI::UI.puts("{{red:\nYour token doesn't seem to be valid. The response from Circle CI was: #{e.message}}}")

    exit(false)
  end
end

#github_token(token) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/ci_runner/cli.rb', line 74

def github_token(token)
  ::CLI::UI::StdoutRouter.enable

  ::CLI::UI.frame("Saving GitHub Token") do
    user = Client::Github.new(token).me
    Configuration::User.instance.save_github_token(token)

    ::CLI::UI.puts(<<~EOM)
      Hello {{warning:#{user["login"]}}}! {{success:Your token is valid!}}

      {{info:The token has been saved in this file: #{Configuration::User.instance.config_file}}}
    EOM
  rescue Client::Error => e
    ::CLI::UI.puts("{{red:\nYour token doesn't seem to be valid. The response from GitHub was: #{e.message}}}")

    exit(false)
  end
end

#rerunObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/ci_runner/cli.rb', line 35

def rerun
  ::CLI::UI::StdoutRouter.enable

  runner = nil

  ::CLI::UI.frame("Preparing CI Runner") do
    Configuration::User.instance.validate_token!

    commit = options[:commit] || GitHelper.head_commit
    repository = options[:repository] || GitHelper.repository_from_remote
    ci_checks = fetch_ci_checks(repository, commit)

    run_name = options[:run_name] || ask_for_name(ci_checks)
    check_run = TestRunFinder.find(ci_checks, run_name)

    ci_log = fetch_ci_log(check_run)
    runner = TestRunFinder.detect_runner(ci_log.read)
    runner.parse!

    no_failure_error(ci_log, runner) if runner.failures.count.zero?
  rescue Client::Error, Error => e
    ::CLI::UI.puts("\n{{red:#{e.message}}}", frame_color: :red)

    exit(false)
  end

  ::CLI::UI::Frame.open("Your test run is about to start") do
    runner.report
    runner.start!
  end
end