Class: CIRunner::CLI
- Inherits:
-
Thor
- Object
- Thor
- CIRunner::CLI
- Defined in:
- lib/ci_runner/cli.rb
Class Method Summary collapse
Instance Method Summary collapse
- #buildkite_token(token, organization) ⇒ Object
- #circle_ci_token(token) ⇒ Object
- #github_token(token) ⇒ Object
- #rerun ⇒ Object
Class Method Details
.exit_on_failure? ⇒ Boolean
10 11 12 |
# File 'lib/ci_runner/cli.rb', line 10 def self.exit_on_failure? true end |
Instance Method Details
#buildkite_token(token, organization) ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/ci_runner/cli.rb', line 130 def buildkite_token(token, organization) ::CLI::UI::StdoutRouter.enable required_scopes = ["read_builds", "read_build_logs"] token_scopes = Client::AuthenticatedBuildkite.new(token).access_token["scopes"] missing_scopes = required_scopes - token_scopes if missing_scopes.empty? Configuration::User.instance.save_buildkite_token(token, organization) ::CLI::UI.puts(<<~EOM) {{success:Your token is valid!}} {{info:The token has been saved in this file: #{Configuration::User.instance.config_file}}} EOM else ::CLI::UI.puts("{{red:\nYour token is missing required scope(s): #{missing_scopes.join(",")}") end rescue Client::Error => e ::CLI::UI.puts("{{red:\nYour token doesn't seem to be valid. The response from Buildkite was: #{e.}}}") exit(false) end |
#circle_ci_token(token) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/ci_runner/cli.rb', line 102 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.}}}") exit(false) end end |
#github_token(token) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/ci_runner/cli.rb', line 75 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.}}}") exit(false) end end |
#rerun ⇒ Object
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 66 |
# File 'lib/ci_runner/cli.rb', line 35 def rerun ::CLI::UI::StdoutRouter.enable check_for_new_version runner = nil ::CLI::UI.frame("Preparing CI Runner") do Configuration::User.instance.validate_token! commit = [:commit] || GitHelper.head_commit repository = [:repository] || GitHelper.repository_from_remote ci_checks = fetch_ci_checks(repository, commit) run_name = [: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.}}}", frame_color: :red) exit(false) end ::CLI::UI::Frame.open("Your test run is about to start") do runner.report runner.start! end end |