travis 1.11.0 → 1.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (156) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +18 -4
  3. data/Rakefile +22 -20
  4. data/bin/travis +5 -3
  5. data/examples/org_overview.rb +2 -0
  6. data/examples/pro_auth.rb +3 -1
  7. data/examples/stream.rb +5 -3
  8. data/lib/travis/auto_login.rb +2 -0
  9. data/lib/travis/cli/accounts.rb +12 -9
  10. data/lib/travis/cli/api_command.rb +85 -81
  11. data/lib/travis/cli/branches.rb +8 -6
  12. data/lib/travis/cli/cache.rb +48 -44
  13. data/lib/travis/cli/cancel.rb +4 -2
  14. data/lib/travis/cli/command.rb +170 -142
  15. data/lib/travis/cli/console.rb +5 -5
  16. data/lib/travis/cli/disable.rb +4 -2
  17. data/lib/travis/cli/enable.rb +14 -12
  18. data/lib/travis/cli/encrypt.rb +57 -57
  19. data/lib/travis/cli/encrypt_file.rb +29 -18
  20. data/lib/travis/cli/endpoint.rb +9 -7
  21. data/lib/travis/cli/env.rb +13 -8
  22. data/lib/travis/cli/help.rb +10 -8
  23. data/lib/travis/cli/history.rb +19 -15
  24. data/lib/travis/cli/init.rb +27 -24
  25. data/lib/travis/cli/lint.rb +10 -8
  26. data/lib/travis/cli/login.rb +17 -11
  27. data/lib/travis/cli/logout.rb +4 -2
  28. data/lib/travis/cli/logs.rb +28 -19
  29. data/lib/travis/cli/monitor.rb +11 -8
  30. data/lib/travis/cli/open.rb +17 -14
  31. data/lib/travis/cli/parser.rb +2 -0
  32. data/lib/travis/cli/pubkey.rb +13 -11
  33. data/lib/travis/cli/raw.rb +4 -3
  34. data/lib/travis/cli/repo_command.rb +123 -112
  35. data/lib/travis/cli/report.rb +40 -33
  36. data/lib/travis/cli/repos.rb +14 -9
  37. data/lib/travis/cli/requests.rb +13 -12
  38. data/lib/travis/cli/restart.rb +4 -2
  39. data/lib/travis/cli/settings.rb +41 -35
  40. data/lib/travis/cli/setup/anynines.rb +7 -6
  41. data/lib/travis/cli/setup/appfog.rb +6 -4
  42. data/lib/travis/cli/setup/artifacts.rb +7 -5
  43. data/lib/travis/cli/setup/biicode.rb +6 -4
  44. data/lib/travis/cli/setup/cloud_66.rb +6 -4
  45. data/lib/travis/cli/setup/cloud_control.rb +8 -6
  46. data/lib/travis/cli/setup/cloud_files.rb +7 -5
  47. data/lib/travis/cli/setup/cloud_foundry.rb +9 -7
  48. data/lib/travis/cli/setup/code_deploy.rb +33 -29
  49. data/lib/travis/cli/setup/deis.rb +8 -6
  50. data/lib/travis/cli/setup/divshot.rb +20 -18
  51. data/lib/travis/cli/setup/elastic_beanstalk.rb +10 -8
  52. data/lib/travis/cli/setup/engine_yard.rb +9 -7
  53. data/lib/travis/cli/setup/gcs.rb +9 -7
  54. data/lib/travis/cli/setup/hackage.rb +6 -4
  55. data/lib/travis/cli/setup/heroku.rb +10 -4
  56. data/lib/travis/cli/setup/modulus.rb +5 -3
  57. data/lib/travis/cli/setup/ninefold.rb +7 -5
  58. data/lib/travis/cli/setup/nodejitsu.rb +6 -4
  59. data/lib/travis/cli/setup/npm.rb +6 -4
  60. data/lib/travis/cli/setup/open_shift.rb +8 -6
  61. data/lib/travis/cli/setup/opsworks.rb +24 -22
  62. data/lib/travis/cli/setup/pypi.rb +7 -5
  63. data/lib/travis/cli/setup/releases.rb +6 -6
  64. data/lib/travis/cli/setup/ruby_gems.rb +7 -5
  65. data/lib/travis/cli/setup/s3.rb +12 -8
  66. data/lib/travis/cli/setup/sauce_connect.rb +7 -5
  67. data/lib/travis/cli/setup/service.rb +36 -25
  68. data/lib/travis/cli/setup.rb +7 -3
  69. data/lib/travis/cli/show.rb +10 -8
  70. data/lib/travis/cli/sshkey.rb +31 -28
  71. data/lib/travis/cli/status.rb +5 -3
  72. data/lib/travis/cli/sync.rb +9 -7
  73. data/lib/travis/cli/token.rb +4 -2
  74. data/lib/travis/cli/version.rb +4 -3
  75. data/lib/travis/cli/whatsup.rb +10 -8
  76. data/lib/travis/cli/whoami.rb +2 -2
  77. data/lib/travis/cli.rb +39 -36
  78. data/lib/travis/client/account.rb +8 -6
  79. data/lib/travis/client/artifact.rb +16 -12
  80. data/lib/travis/client/auto_login.rb +7 -4
  81. data/lib/travis/client/broadcast.rb +2 -0
  82. data/lib/travis/client/build.rb +7 -3
  83. data/lib/travis/client/cache.rb +4 -2
  84. data/lib/travis/client/commit.rb +5 -2
  85. data/lib/travis/client/entity.rb +50 -46
  86. data/lib/travis/client/env_var.rb +13 -8
  87. data/lib/travis/client/error.rb +5 -3
  88. data/lib/travis/client/has_uuid.rb +3 -1
  89. data/lib/travis/client/job.rb +8 -3
  90. data/lib/travis/client/lint_result.rb +2 -0
  91. data/lib/travis/client/listener.rb +70 -55
  92. data/lib/travis/client/methods.rb +10 -5
  93. data/lib/travis/client/namespace.rb +20 -16
  94. data/lib/travis/client/not_loadable.rb +3 -1
  95. data/lib/travis/client/repository.rb +34 -22
  96. data/lib/travis/client/request.rb +5 -2
  97. data/lib/travis/client/restartable.rb +2 -0
  98. data/lib/travis/client/session.rb +118 -88
  99. data/lib/travis/client/settings.rb +8 -3
  100. data/lib/travis/client/singleton_setting.rb +2 -0
  101. data/lib/travis/client/ssh_key.rb +2 -0
  102. data/lib/travis/client/states.rb +8 -6
  103. data/lib/travis/client/user.rb +2 -0
  104. data/lib/travis/client/weak_entity.rb +6 -3
  105. data/lib/travis/client.rb +4 -1
  106. data/lib/travis/pro/auto_login.rb +2 -0
  107. data/lib/travis/pro.rb +2 -0
  108. data/lib/travis/tools/assets.rb +6 -3
  109. data/lib/travis/tools/completion.rb +10 -6
  110. data/lib/travis/tools/formatter.rb +20 -14
  111. data/lib/travis/tools/github.rb +59 -49
  112. data/lib/travis/tools/notification.rb +18 -13
  113. data/lib/travis/tools/safe_string.rb +4 -1
  114. data/lib/travis/tools/ssl_key.rb +5 -2
  115. data/lib/travis/tools/system.rb +11 -6
  116. data/lib/travis/version.rb +3 -1
  117. data/lib/travis.rb +3 -1
  118. data/spec/cli/api_command_spec.rb +11 -8
  119. data/spec/cli/cancel_spec.rb +2 -4
  120. data/spec/cli/encrypt_file_spec.rb +9 -7
  121. data/spec/cli/encrypt_spec.rb +19 -17
  122. data/spec/cli/endpoint_spec.rb +12 -10
  123. data/spec/cli/help_spec.rb +14 -12
  124. data/spec/cli/history_spec.rb +2 -0
  125. data/spec/cli/init_spec.rb +35 -33
  126. data/spec/cli/logs_spec.rb +2 -0
  127. data/spec/cli/open_spec.rb +6 -4
  128. data/spec/cli/repo_command_spec.rb +8 -4
  129. data/spec/cli/restart_spec.rb +2 -4
  130. data/spec/cli/setup/service_spec.rb +17 -18
  131. data/spec/cli/setup_spec.rb +2 -4
  132. data/spec/cli/show_spec.rb +4 -2
  133. data/spec/cli/status_spec.rb +7 -5
  134. data/spec/cli/token_spec.rb +7 -5
  135. data/spec/cli/version_spec.rb +2 -0
  136. data/spec/cli/whoami_spec.rb +9 -7
  137. data/spec/client/account_spec.rb +28 -20
  138. data/spec/client/auto_login_spec.rb +12 -9
  139. data/spec/client/broadcast_spec.rb +5 -3
  140. data/spec/client/build_spec.rb +28 -24
  141. data/spec/client/commit_spec.rb +17 -14
  142. data/spec/client/job_spec.rb +27 -23
  143. data/spec/client/methods_spec.rb +8 -4
  144. data/spec/client/namespace_spec.rb +8 -4
  145. data/spec/client/repository_spec.rb +33 -30
  146. data/spec/client/session_spec.rb +71 -67
  147. data/spec/client/user_spec.rb +13 -10
  148. data/spec/client_spec.rb +6 -4
  149. data/spec/pro_spec.rb +5 -3
  150. data/spec/spec_helper.rb +3 -1
  151. data/spec/support/fake_api.rb +662 -662
  152. data/spec/support/fake_github.rb +6 -3
  153. data/spec/support/helpers.rb +13 -8
  154. data/spec/travis_spec.rb +5 -3
  155. data/travis.gemspec +400 -399
  156. metadata +30 -50
@@ -1,18 +1,20 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'travis/cli/setup'
2
4
 
3
5
  module Travis
4
6
  module CLI
5
7
  class Setup
6
8
  class SauceConnect < Service
7
- description "Sauce Connet addon for Sauce Labs integration"
8
- service_name "sauce_connect"
9
+ description 'Sauce Connet addon for Sauce Labs integration'
10
+ service_name 'sauce_connect'
9
11
 
10
12
  def run
11
13
  travis_config['addons'] ||= {}
12
14
  configure 'sauce_connect', {}, travis_config['addons'] do |config|
13
- config['username'] = ask("Sauce Labs user: ").to_s
14
- config['access_key'] = ask("Sauce Labs access key: ") { |q| q.echo = "*" }.to_s
15
- encrypt(config, 'access_key') if agree("Encrypt access key? ") { |q| q.default = 'yes' }
15
+ config['username'] = ask('Sauce Labs user: ').to_s
16
+ config['access_key'] = ask('Sauce Labs access key: ') { |q| q.echo = '*' }.to_s
17
+ encrypt(config, 'access_key') if agree('Encrypt access key? ') { |q| q.default = 'yes' }
16
18
  end
17
19
  end
18
20
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'travis/cli/setup'
2
4
 
3
5
  module Travis
@@ -9,7 +11,7 @@ module Travis
9
11
  end
10
12
 
11
13
  def self.description(description = nil)
12
- @description ||= ""
14
+ @description ||= ''
13
15
  @description = description if description
14
16
  @description
15
17
  end
@@ -36,39 +38,48 @@ module Travis
36
38
 
37
39
  private
38
40
 
39
- def on(question, config, condition)
40
- return unless agree(question) { |q| q.default = 'yes' }
41
- config['on'] ||= {}
42
- config['on'].merge! condition
43
- end
41
+ def on(question, config, condition)
42
+ return unless agree(question) { |q| q.default = 'yes' }
44
43
 
45
- def encrypt(config, key)
46
- encrypted = repository.encrypt(config.fetch(key))
47
- config[key] = { 'secure' => encrypted }
48
- end
44
+ config['on'] ||= {}
45
+ config['on'].merge! condition
46
+ end
49
47
 
50
- def configure(key, value = {}, config = travis_config)
51
- error "#{key} section already exists in .travis.yml, run with --force to override" if config.include? key and not force?
52
- yield(config[key] = value)
53
- end
48
+ def encrypt(config, key)
49
+ encrypted = repository.encrypt(config.fetch(key))
50
+ config[key] = { 'secure' => encrypted }
51
+ end
54
52
 
55
- def branch
56
- @branch ||= `git rev-parse --symbolic-full-name --abbrev-ref HEAD`.chomp
53
+ def configure(key, value = {}, config = travis_config)
54
+ if config.include?(key) && !force?
55
+ error "#{key} section already exists in .travis.yml, run with --force to override"
57
56
  end
57
+ yield(config[key] = value)
58
+ end
58
59
 
59
- def deploy(provider, verb = "deploy")
60
- configure('deploy', 'provider' => provider) do |config|
61
- yield config
62
-
63
- on("#{verb.capitalize} only from #{repository.slug}? ", config, 'repo' => repository.slug)
64
- on("#{verb.capitalize} from #{branch} branch? ", config, 'branch' => branch) if branch != 'master' and branch != 'HEAD'
60
+ def branch
61
+ @branch ||= `git rev-parse --symbolic-full-name --abbrev-ref HEAD`.chomp
62
+ end
65
63
 
66
- config['skip_cleanup'] = 'true' if not ( config.has_key?('skip_cleanup') or config.fetch('edge', 'false') != 'false' )
64
+ def deploy(provider, verb = 'deploy')
65
+ configure('deploy', 'provider' => provider) do |config|
66
+ yield config
67
67
 
68
- encrypt(config, 'password') if config['password'] and agree("Encrypt Password? ") { |q| q.default = 'yes' }
69
- encrypt(config, 'api_key') if config['api_key'] and agree("Encrypt API key? ") { |q| q.default = 'yes' }
68
+ on("#{verb.capitalize} only from #{repository.slug}? ", config, 'repo' => repository.slug)
69
+ if (branch != 'master') && (branch != 'HEAD')
70
+ on("#{verb.capitalize} from #{branch} branch? ", config,
71
+ 'branch' => branch)
70
72
  end
73
+
74
+ config['skip_cleanup'] = 'true' unless config.key?('skip_cleanup') || (config.fetch('edge',
75
+ 'false') != 'false')
76
+
77
+ encrypt(config, 'password') if config['password'] && agree('Encrypt Password? ') do |q|
78
+ q.default = 'yes'
79
+ end
80
+ encrypt(config, 'api_key') if config['api_key'] && agree('Encrypt API key? ') { |q| q.default = 'yes' }
71
81
  end
82
+ end
72
83
  end
73
84
  end
74
85
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'travis/cli'
2
4
 
3
5
  module Travis
@@ -32,14 +34,14 @@ module Travis
32
34
  autoload :Deis, 'travis/cli/setup/deis'
33
35
  autoload :Service, 'travis/cli/setup/service'
34
36
 
35
- description "sets up an addon or deploy target"
37
+ description 'sets up an addon or deploy target'
36
38
  on('-f', '--force', 'override config section if it already exists')
37
39
 
38
40
  def self.service(name)
39
41
  normal_name = Service.normalized_name(name)
40
42
  const_name = constants(false).detect { |c| Service.normalized_name(c) == normal_name }
41
43
  constant = const_get(const_name) if const_name
42
- constant if constant and constant < Service and constant.known_as? name
44
+ constant if constant && (constant < Service) && constant.known_as?(name)
43
45
  end
44
46
 
45
47
  def self.services
@@ -47,7 +49,9 @@ module Travis
47
49
  end
48
50
 
49
51
  def help
50
- services = self.class.services.map { |s| "\t" << color(s.service_name.ljust(20), :command) << color(s.description, :info) }.join("\n")
52
+ services = self.class.services.map do |s|
53
+ "\t" << color(s.service_name.ljust(20), :command) << color(s.description, :info)
54
+ end.join("\n")
51
55
  super("\nAvailable services:\n\n#{services}\n\n")
52
56
  end
53
57
 
@@ -1,12 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'travis/cli'
2
4
 
3
5
  module Travis
4
6
  module CLI
5
7
  class Show < RepoCommand
6
- description "displays a build or job"
8
+ description 'displays a build or job'
7
9
 
8
10
  def run(number = last_build.number)
9
- number = repository.branch(number).number if number !~ /^\d+(\.\d+)?$/ and repository.branch(number)
11
+ number = repository.branch(number).number if number !~ /^\d+(\.\d+)?$/ && repository.branch(number)
10
12
  entity = job(number) || build(number)
11
13
 
12
14
  error "could not find job or build #{repository.slug}##{number}" unless entity
@@ -17,7 +19,7 @@ module Travis
17
19
  entity.commit.subject,
18
20
  entity.state,
19
21
  entity.color,
20
- entity.pull_request? ? "pull request" : "push",
22
+ entity.pull_request? ? 'pull request' : 'push',
21
23
  entity.branch_info,
22
24
  entity.commit.short_sha,
23
25
  entity.commit.compare_url,
@@ -33,13 +35,13 @@ module Travis
33
35
  color("##{job.number} #{job.state}:".ljust(16), [job.color, :bold]),
34
36
  formatter.duration(job.duration).ljust(14),
35
37
  formatter.job_config(job.config),
36
- (color("(failure allowed)", :info) if job.allow_failures?)
37
- ].compact.join(" ").rstrip
38
+ (color('(failure allowed)', :info) if job.allow_failures?)
39
+ ].compact.join(' ').rstrip
38
40
  end
39
41
  else
40
42
  config = formatter.job_config(entity.config)
41
- say color("Allow Failure: ", :info) + entity.allow_failures?.inspect
42
- say color("Config: ", :info) + config unless config.empty?
43
+ say color('Allow Failure: ', :info) + entity.allow_failures?.inspect
44
+ say color('Config: ', :info) + config unless config.empty?
43
45
  end
44
46
  end
45
47
  end
@@ -56,4 +58,4 @@ __END__
56
58
  <[[ color("Compare URL: ", :info) ]]>%s
57
59
  <[[ color("Duration: ", :info) ]]>%s
58
60
  <[[ color("Started: ", :info) ]]>%s
59
- <[[ color("Finished: ", :info) ]]>%s
61
+ <[[ color("Finished: ", :info) ]]>%s
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'travis/cli'
2
4
  require 'travis/tools/ssl_key'
3
5
  require 'travis/tools/github'
@@ -5,7 +7,7 @@ require 'travis/tools/github'
5
7
  module Travis
6
8
  module CLI
7
9
  class Sshkey < RepoCommand
8
- description "checks, updates or deletes an SSH key"
10
+ description 'checks, updates or deletes an SSH key'
9
11
  on '-D', '--delete', 'remove SSH key'
10
12
  on '-d', '--description DESCRIPTION', 'set description'
11
13
  on '-u', '--upload FILE', 'upload key from given file'
@@ -30,25 +32,26 @@ module Travis
30
32
  say "Current SSH key: #{color(ssh_key.description, :info)}"
31
33
  say "Finger print: #{color(ssh_key.fingerprint, :info)}"
32
34
  rescue Travis::Client::NotFound
33
- say "No custom SSH key installed."
35
+ say 'No custom SSH key installed.'
34
36
  exit 1 if check?
35
37
  end
36
38
 
37
39
  def update_key(value, file)
38
40
  error "#{file} does not look like a private key" unless value.lines.first =~ /PRIVATE KEY/
39
41
  value = remove_passphrase(value)
40
- self.description ||= ask("Key description: ") { |q| q.default = "Custom Key" } if interactive?
42
+ self.description ||= ask('Key description: ') { |q| q.default = 'Custom Key' } if interactive?
41
43
  say "Updating ssh key for #{color slug, :info} with key from #{color file, :info}"
42
44
  empty_line
43
- ssh_key.update(:value => value, :description => description || file)
45
+ ssh_key.update(value:, description: description || file)
44
46
  end
45
47
 
46
48
  def delete_key
47
- return if interactive? and not danger_zone? "Remove SSH key for #{color slug, :info}?"
49
+ return if interactive? && !danger_zone?("Remove SSH key for #{color slug, :info}?")
50
+
48
51
  say "Removing ssh key for #{color slug, :info}"
49
52
  ssh_key.delete
50
53
  rescue Travis::Client::NotFound
51
- warn "no key found to remove"
54
+ warn 'no key found to remove'
52
55
  end
53
56
 
54
57
  def generate_key
@@ -56,39 +59,39 @@ module Travis
56
59
  github.with_token do |token|
57
60
  access_token = github_auth(token)
58
61
  end
59
- session.access_token = nil
60
- unless access_token
61
- raise Travis::Client::GitHubLoginFailed, "all GitHub tokens given were invalid"
62
- end
62
+ raise Travis::Client::GitHubLoginFailed, 'all GitHub tokens given were invalid' unless access_token
63
+
63
64
  gh = GH.with(token: github_token)
64
65
  login = gh['user']['login']
65
66
  check_access(gh)
66
67
  empty_line
67
68
 
68
- say "Generating RSA key."
69
+ say 'Generating RSA key.'
69
70
  private_key = Tools::SSLKey.generate_rsa
70
71
  self.description ||= "key for fetching dependencies for #{slug} via #{login}"
71
72
 
72
- say "Uploading public key to GitHub."
73
- gh.post("/user/keys", :title => "#{description} (Travis CI)", :key => Tools::SSLKey.rsa_ssh(private_key.public_key))
73
+ say 'Uploading public key to GitHub.'
74
+ gh.post('/user/keys', title: "#{description} (Travis CI)",
75
+ key: Tools::SSLKey.rsa_ssh(private_key.public_key))
74
76
 
75
- say "Uploading private key to Travis CI."
76
- ssh_key.update(:value => private_key.to_s, :description => description)
77
+ say 'Uploading private key to Travis CI.'
78
+ ssh_key.update(value: private_key.to_s, description:)
77
79
 
78
80
  empty_line
79
- say "You can store the private key to reuse it for other repositories (travis sshkey --upload FILE)."
80
- if agree("Store private key? ") { |q| q.default = "no" }
81
- path = ask("Path: ") { |q| q.default = "id_travis_rsa" }
82
- File.write(path, private_key.to_s)
83
- end
81
+ say 'You can store the private key to reuse it for other repositories (travis sshkey --upload FILE).'
82
+ return unless agree('Store private key? ') { |q| q.default = 'no' }
83
+
84
+ path = ask('Path: ') { |q| q.default = 'id_travis_rsa' }
85
+ File.write(path, private_key.to_s)
84
86
  end
85
87
 
86
88
  def remove_passphrase(value)
87
89
  return value unless Tools::SSLKey.has_passphrase? value
88
- return Tools::SSLKey.remove_passphrase(value, passphrase) || error("wrong pass phrase") if passphrase
89
- error "Key is encrypted, but missing --passphrase option" unless interactive?
90
- say "The private key is protected by a pass phrase."
91
- result = Tools::SSLKey.remove_passphrase(value, ask("Enter pass phrase: ") { |q| q.echo = "*" }) until result
90
+ return Tools::SSLKey.remove_passphrase(value, passphrase) || error('wrong pass phrase') if passphrase
91
+
92
+ error 'Key is encrypted, but missing --passphrase option' unless interactive?
93
+ say 'The private key is protected by a pass phrase.'
94
+ result = Tools::SSLKey.remove_passphrase(value, ask('Enter pass phrase: ') { |q| q.echo = '*' }) until result
92
95
  empty_line
93
96
  result
94
97
  end
@@ -108,15 +111,15 @@ module Travis
108
111
  g.github_token = github_token
109
112
  g.login_header = proc { login_header }
110
113
  g.debug = proc { |log| debug(log) }
111
- g.after_tokens = proc { g.explode = true and error("no suitable github token found") }
114
+ g.after_tokens = proc { g.explode = true and error('no suitable github token found') }
112
115
  end
113
116
  end
114
117
  end
115
118
 
116
119
  def login_header
117
- say "GitHub deprecated its Authorizations API exchanging a password for a token."
118
- say "Please visit https://github.blog/2020-07-30-token-authentication-requirements-for-api-and-git-operations for more information."
119
- say "Try running with #{color("--github-token", :info)} or #{color("--auto-token", :info)} ."
120
+ say 'GitHub deprecated its Authorizations API exchanging a password for a token.'
121
+ say 'Please visit https://github.blog/2020-07-30-token-authentication-requirements-for-api-and-git-operations for more information.'
122
+ say "Try running with #{color('--github-token', :info)} or #{color('--auto-token', :info)} ."
120
123
  end
121
124
  end
122
125
  end
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'travis/cli'
2
4
 
3
5
  module Travis
4
6
  module CLI
5
7
  class Status < RepoCommand
6
- description "checks status of the latest build"
8
+ description 'checks status of the latest build'
7
9
 
8
10
  on '-x', '--[no-]exit-code', 'sets the exit code to 1 if the build failed'
9
11
  on '-q', '--[no-]quiet', 'does not print anything'
@@ -11,8 +13,8 @@ module Travis
11
13
 
12
14
  def run
13
15
  say color(last_build.state, last_build.color), "build ##{last_build.number} %s" unless quiet?
14
- exit 1 if exit_code? and last_build.unsuccessful?
15
- exit 1 if fail_pending? and last_build.pending?
16
+ exit 1 if exit_code? && last_build.unsuccessful?
17
+ exit 1 if fail_pending? && last_build.pending?
16
18
  end
17
19
  end
18
20
  end
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'travis/cli'
2
4
 
3
5
  module Travis
4
6
  module CLI
5
7
  class Sync < ApiCommand
6
- description "triggers a new sync with GitHub"
8
+ description 'triggers a new sync with GitHub'
7
9
 
8
10
  on '-c', '--check', 'only check the sync status'
9
11
  on '-b', '--background', 'will trigger sync but not block until sync is done'
@@ -13,16 +15,16 @@ module Travis
13
15
  authenticate
14
16
 
15
17
  if check?
16
- say "#{"not " unless user.syncing?}syncing", "#{user.login} is currently %s"
17
- elsif user.syncing? and not force?
18
- error "user is already syncing"
18
+ say "#{'not ' unless user.syncing?}syncing", "#{user.login} is currently %s"
19
+ elsif user.syncing? && !force?
20
+ error 'user is already syncing'
19
21
  elsif background?
20
- say "starting synchronization"
22
+ say 'starting synchronization'
21
23
  sync(false)
22
24
  else
23
- say "synchronizing: "
25
+ say 'synchronizing: '
24
26
  sync
25
- say color(" done", :success)
27
+ say color(' done', :success)
26
28
  end
27
29
  end
28
30
  end
@@ -1,13 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'travis/cli'
2
4
 
3
5
  module Travis
4
6
  module CLI
5
7
  class Token < ApiCommand
6
- description "outputs the secret API token"
8
+ description 'outputs the secret API token'
7
9
 
8
10
  def run
9
11
  authenticate
10
- say access_token, "Your access token is %s"
12
+ say access_token, 'Your access token is %s'
11
13
  end
12
14
  end
13
15
  end
@@ -1,17 +1,18 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'travis/cli'
2
4
  require 'travis/version'
3
5
 
4
6
  module Travis
5
7
  module CLI
6
8
  class Version < Command
7
- description "outputs the client version"
9
+ description 'outputs the client version'
8
10
 
9
11
  def run
10
12
  say Travis::VERSION
11
13
  end
12
14
 
13
- def check_version
14
- end
15
+ def check_version; end
15
16
  end
16
17
  end
17
18
  end
@@ -1,30 +1,32 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'travis/cli'
2
4
 
3
5
  module Travis
4
6
  module CLI
5
7
  class Whatsup < ApiCommand
6
- description "lists most recent builds"
8
+ description 'lists most recent builds'
7
9
  on('-m', '--my-repos', 'Only display my own repositories')
8
10
 
9
11
  def run
10
- say "nothing to show" if recent.empty?
12
+ say 'nothing to show' if recent.empty?
11
13
 
12
14
  recent.each do |repo|
13
15
  say [
14
16
  color(repo.slug, [:bold, repo.color]),
15
17
  color("#{repo.last_build.state}: ##{repo.last_build.number}", repo.color)
16
- ].join(" ")
18
+ ].join(' ')
17
19
  end
18
20
  end
19
21
 
20
22
  private
21
23
 
22
- def recent
23
- @recent ||= begin
24
- recent = my_repos ? repos : repos(:member => user.login)
25
- recent.select { |repo| repo.last_build }
26
- end
24
+ def recent
25
+ @recent ||= begin
26
+ recent = my_repos ? repos : repos(member: user.login)
27
+ recent.select { |repo| repo.last_build }
27
28
  end
29
+ end
28
30
  end
29
31
  end
30
32
  end
@@ -3,12 +3,12 @@ require 'travis/cli'
3
3
  module Travis
4
4
  module CLI
5
5
  class Whoami < ApiCommand
6
- description "outputs the current user"
6
+ description 'outputs the current user'
7
7
 
8
8
  def run
9
9
  authenticate
10
10
  name = " (#{user.name})" unless user.name.to_s.empty?
11
- say user.login, "You are %s" << name.to_s
11
+ say user.login, 'You are %s' << name.to_s
12
12
  end
13
13
  end
14
14
  end
data/lib/travis/cli.rb CHANGED
@@ -1,12 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  begin
2
4
  require 'travis/client'
3
5
  rescue LoadError => e
4
- if e.message == 'no such file to load -- json'
5
- $stderr.puts "You should either run `gem install json` or upgrade your Ruby version!"
6
- exit 1
7
- else
8
- raise e
9
- end
6
+ raise e unless e.message == 'no such file to load -- json'
7
+
8
+ warn 'You should either run `gem install json` or upgrade your Ruby version!'
9
+ exit 1
10
10
  end
11
11
 
12
12
  require 'stringio'
@@ -66,11 +66,11 @@ module Travis
66
66
 
67
67
  def command(name)
68
68
  const_name = command_name(name)
69
- constant = CLI.const_get(const_name) if const_name =~ /^[A-Z][A-Za-z]+$/ and const_defined? const_name
69
+ constant = CLI.const_get(const_name) if const_name =~ (/^[A-Z][A-Za-z]+$/) && const_defined?(const_name)
70
70
  if command? constant
71
71
  constant
72
72
  else
73
- $stderr.puts "unknown command #{name}"
73
+ warn "unknown command #{name}"
74
74
  exit 1
75
75
  end
76
76
  end
@@ -80,8 +80,10 @@ module Travis
80
80
  end
81
81
 
82
82
  def silent
83
- stderr, $stderr = $stderr, dummy_io
84
- stdout, $stdout = $stdout, dummy_io
83
+ stderr = $stderr
84
+ $stderr = dummy_io
85
+ stdout = $stdout
86
+ $stdout = dummy_io
85
87
  yield
86
88
  ensure
87
89
  $stderr = stderr if stderr
@@ -90,37 +92,38 @@ module Travis
90
92
 
91
93
  private
92
94
 
93
- def try_const_get(name)
94
- CLI.const_get(name)
95
- rescue Exception
96
- end
95
+ def try_const_get(name)
96
+ CLI.const_get(name)
97
+ rescue Exception
98
+ end
97
99
 
98
- def dummy_io
99
- return StringIO.new unless defined? IO::NULL and IO::NULL
100
- File.open(IO::NULL, 'w')
101
- end
100
+ def dummy_io
101
+ return StringIO.new unless defined? IO::NULL && IO::NULL
102
102
 
103
- def command?(constant)
104
- constant.is_a? Class and constant < Command and not constant.abstract?
105
- end
103
+ File.open(IO::NULL, 'w')
104
+ end
105
+
106
+ def command?(constant)
107
+ constant.is_a? Class and constant < Command and !constant.abstract?
108
+ end
106
109
 
107
- def command_name(name)
108
- case name
109
- when nil, '-h', '-?' then 'Help'
110
- when '-v' then 'Version'
111
- when /^--/ then command_name(name[2..-1])
112
- else name.split('-').map(&:capitalize).join
113
- end
110
+ def command_name(name)
111
+ case name
112
+ when nil, '-h', '-?' then 'Help'
113
+ when '-v' then 'Version'
114
+ when /^--/ then command_name(name[2..])
115
+ else name.split('-').map(&:capitalize).join
114
116
  end
117
+ end
115
118
 
116
- # can't use flatten as it will flatten hashes
117
- def preparse(unparsed, args = [], opts = {})
118
- case unparsed
119
- when Hash then opts.merge! unparsed
120
- when Array then unparsed.each { |e| preparse(e, args, opts) }
121
- else args << unparsed.to_s
122
- end
123
- [args, opts]
119
+ # can't use flatten as it will flatten hashes
120
+ def preparse(unparsed, args = [], opts = {})
121
+ case unparsed
122
+ when Hash then opts.merge! unparsed
123
+ when Array then unparsed.each { |e| preparse(e, args, opts) }
124
+ else args << unparsed.to_s
124
125
  end
126
+ [args, opts]
127
+ end
125
128
  end
126
129
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'travis/client'
2
4
 
3
5
  module Travis
@@ -32,11 +34,11 @@ module Travis
32
34
  end
33
35
 
34
36
  def repos_count
35
- load_attribute("repos_count") { repositories.count }
37
+ load_attribute('repos_count') { repositories.count }
36
38
  end
37
39
 
38
40
  def repositories
39
- attributes['repositories'] ||= session.repos(:owner_name => login)
41
+ attributes['repositories'] ||= session.repos(owner_name: login)
40
42
  end
41
43
 
42
44
  def member?
@@ -47,10 +49,10 @@ module Travis
47
49
 
48
50
  private
49
51
 
50
- def load_attribute(name, &block)
51
- session.accounts if missing? name
52
- block ? attributes.fetch(name.to_s, &block) : attributes[name.to_s]
53
- end
52
+ def load_attribute(name, &block)
53
+ session.accounts if missing? name
54
+ block ? attributes.fetch(name.to_s, &block) : attributes[name.to_s]
55
+ end
54
56
  end
55
57
  end
56
58
  end