travis 1.11.1 → 1.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +34 -3
  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 +11 -9
  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/regenerate_token.rb +15 -0
  35. data/lib/travis/cli/remove_token.rb +15 -0
  36. data/lib/travis/cli/repo_command.rb +123 -112
  37. data/lib/travis/cli/report.rb +40 -33
  38. data/lib/travis/cli/repos.rb +14 -9
  39. data/lib/travis/cli/requests.rb +13 -12
  40. data/lib/travis/cli/restart.rb +4 -2
  41. data/lib/travis/cli/settings.rb +41 -35
  42. data/lib/travis/cli/setup/anynines.rb +7 -6
  43. data/lib/travis/cli/setup/appfog.rb +6 -4
  44. data/lib/travis/cli/setup/artifacts.rb +7 -5
  45. data/lib/travis/cli/setup/biicode.rb +6 -4
  46. data/lib/travis/cli/setup/cloud_66.rb +6 -4
  47. data/lib/travis/cli/setup/cloud_control.rb +8 -6
  48. data/lib/travis/cli/setup/cloud_files.rb +7 -5
  49. data/lib/travis/cli/setup/cloud_foundry.rb +9 -7
  50. data/lib/travis/cli/setup/code_deploy.rb +33 -29
  51. data/lib/travis/cli/setup/deis.rb +8 -6
  52. data/lib/travis/cli/setup/divshot.rb +20 -18
  53. data/lib/travis/cli/setup/elastic_beanstalk.rb +10 -8
  54. data/lib/travis/cli/setup/engine_yard.rb +9 -7
  55. data/lib/travis/cli/setup/gcs.rb +9 -7
  56. data/lib/travis/cli/setup/hackage.rb +6 -4
  57. data/lib/travis/cli/setup/heroku.rb +10 -4
  58. data/lib/travis/cli/setup/modulus.rb +5 -3
  59. data/lib/travis/cli/setup/ninefold.rb +7 -5
  60. data/lib/travis/cli/setup/nodejitsu.rb +6 -4
  61. data/lib/travis/cli/setup/npm.rb +6 -4
  62. data/lib/travis/cli/setup/open_shift.rb +8 -6
  63. data/lib/travis/cli/setup/opsworks.rb +24 -22
  64. data/lib/travis/cli/setup/pypi.rb +7 -5
  65. data/lib/travis/cli/setup/releases.rb +6 -6
  66. data/lib/travis/cli/setup/ruby_gems.rb +7 -5
  67. data/lib/travis/cli/setup/s3.rb +12 -8
  68. data/lib/travis/cli/setup/sauce_connect.rb +7 -5
  69. data/lib/travis/cli/setup/service.rb +36 -25
  70. data/lib/travis/cli/setup.rb +7 -3
  71. data/lib/travis/cli/show.rb +10 -8
  72. data/lib/travis/cli/sshkey.rb +31 -27
  73. data/lib/travis/cli/status.rb +5 -3
  74. data/lib/travis/cli/sync.rb +9 -7
  75. data/lib/travis/cli/token.rb +4 -2
  76. data/lib/travis/cli/version.rb +4 -3
  77. data/lib/travis/cli/whatsup.rb +10 -8
  78. data/lib/travis/cli/whoami.rb +2 -2
  79. data/lib/travis/cli.rb +81 -76
  80. data/lib/travis/client/account.rb +8 -6
  81. data/lib/travis/client/artifact.rb +16 -12
  82. data/lib/travis/client/auto_login.rb +7 -4
  83. data/lib/travis/client/broadcast.rb +2 -0
  84. data/lib/travis/client/build.rb +7 -3
  85. data/lib/travis/client/cache.rb +4 -2
  86. data/lib/travis/client/commit.rb +5 -2
  87. data/lib/travis/client/entity.rb +50 -46
  88. data/lib/travis/client/env_var.rb +13 -8
  89. data/lib/travis/client/error.rb +5 -3
  90. data/lib/travis/client/has_uuid.rb +3 -1
  91. data/lib/travis/client/job.rb +8 -3
  92. data/lib/travis/client/lint_result.rb +2 -0
  93. data/lib/travis/client/listener.rb +70 -55
  94. data/lib/travis/client/methods.rb +26 -5
  95. data/lib/travis/client/namespace.rb +20 -16
  96. data/lib/travis/client/not_loadable.rb +3 -1
  97. data/lib/travis/client/repository.rb +34 -22
  98. data/lib/travis/client/request.rb +5 -2
  99. data/lib/travis/client/restartable.rb +2 -0
  100. data/lib/travis/client/session.rb +118 -88
  101. data/lib/travis/client/settings.rb +8 -3
  102. data/lib/travis/client/singleton_setting.rb +2 -0
  103. data/lib/travis/client/ssh_key.rb +2 -0
  104. data/lib/travis/client/states.rb +8 -6
  105. data/lib/travis/client/user.rb +2 -0
  106. data/lib/travis/client/weak_entity.rb +6 -3
  107. data/lib/travis/client.rb +4 -1
  108. data/lib/travis/pro/auto_login.rb +2 -0
  109. data/lib/travis/pro.rb +2 -0
  110. data/lib/travis/tools/assets.rb +6 -3
  111. data/lib/travis/tools/completion.rb +10 -6
  112. data/lib/travis/tools/formatter.rb +20 -14
  113. data/lib/travis/tools/github.rb +59 -49
  114. data/lib/travis/tools/notification.rb +18 -13
  115. data/lib/travis/tools/safe_string.rb +4 -1
  116. data/lib/travis/tools/ssl_key.rb +5 -2
  117. data/lib/travis/tools/system.rb +11 -6
  118. data/lib/travis/version.rb +3 -1
  119. data/lib/travis.rb +3 -1
  120. data/spec/cli/api_command_spec.rb +11 -8
  121. data/spec/cli/cancel_spec.rb +2 -4
  122. data/spec/cli/encrypt_file_spec.rb +9 -7
  123. data/spec/cli/encrypt_spec.rb +19 -17
  124. data/spec/cli/endpoint_spec.rb +12 -10
  125. data/spec/cli/help_spec.rb +14 -12
  126. data/spec/cli/history_spec.rb +2 -0
  127. data/spec/cli/init_spec.rb +35 -33
  128. data/spec/cli/logs_spec.rb +2 -0
  129. data/spec/cli/open_spec.rb +6 -4
  130. data/spec/cli/repo_command_spec.rb +8 -4
  131. data/spec/cli/restart_spec.rb +2 -4
  132. data/spec/cli/setup/service_spec.rb +17 -18
  133. data/spec/cli/setup_spec.rb +2 -4
  134. data/spec/cli/show_spec.rb +4 -2
  135. data/spec/cli/status_spec.rb +7 -5
  136. data/spec/cli/token_spec.rb +7 -5
  137. data/spec/cli/version_spec.rb +2 -0
  138. data/spec/cli/whoami_spec.rb +9 -7
  139. data/spec/client/account_spec.rb +28 -20
  140. data/spec/client/auto_login_spec.rb +12 -9
  141. data/spec/client/broadcast_spec.rb +5 -3
  142. data/spec/client/build_spec.rb +28 -24
  143. data/spec/client/commit_spec.rb +17 -14
  144. data/spec/client/job_spec.rb +27 -23
  145. data/spec/client/methods_spec.rb +8 -4
  146. data/spec/client/namespace_spec.rb +8 -4
  147. data/spec/client/repository_spec.rb +33 -30
  148. data/spec/client/session_spec.rb +71 -67
  149. data/spec/client/user_spec.rb +13 -10
  150. data/spec/client_spec.rb +6 -4
  151. data/spec/pro_spec.rb +5 -3
  152. data/spec/spec_helper.rb +3 -1
  153. data/spec/support/fake_api.rb +662 -662
  154. data/spec/support/fake_github.rb +6 -3
  155. data/spec/support/helpers.rb +13 -8
  156. data/spec/travis_spec.rb +5 -3
  157. data/travis.gemspec +402 -399
  158. metadata +31 -49
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'travis/cli'
2
4
  require 'yaml'
3
5
 
@@ -9,7 +11,7 @@ module Travis
9
11
  on('-g', '--github-token TOKEN', 'identify by GitHub token')
10
12
  on('-r', '--repo SLUG', 'repository to use (will try to detect from current git clone)') do |c, slug|
11
13
  c.slug = slug
12
- c.error "SLUG should be of the form OWNER/REPO" unless slug.split('/').compact.size == 2
14
+ c.error 'SLUG should be of the form OWNER/REPO' unless slug.split('/').compact.size == 2
13
15
  end
14
16
  on('-R', '--store-repo SLUG', 'like --repo, but remembers value for current directory') do |c, slug|
15
17
  c.slug = slug
@@ -17,12 +19,15 @@ module Travis
17
19
  end
18
20
 
19
21
  attr_accessor :slug
22
+
20
23
  abstract
21
24
 
22
25
  def setup
23
26
  setup_enterprise
24
- error "Can't figure out GitHub repo name. Ensure you're in the repo directory, or specify the repo name via the -r option (e.g. travis <command> -r <owner>/<repo>)" unless self.slug ||= find_slug
25
- error "GitHub repo name is invalid, it should be of the form 'owner/repo'" unless self.slug.include?("/")
27
+ unless self.slug ||= find_slug
28
+ error "Can't figure out GitHub repo name. Ensure you're in the repo directory, or specify the repo name via the -r option (e.g. travis <command> -r <owner>/<repo>)"
29
+ end
30
+ error "GitHub repo name is invalid, it should be of the form 'owner/repo'" unless self.slug.include?('/')
26
31
  self.api_endpoint = detect_api_endpoint
27
32
  super
28
33
  repository.load # makes sure we actually have access to the repo
@@ -36,140 +41,146 @@ module Travis
36
41
 
37
42
  private
38
43
 
39
- def build(number_or_id)
40
- return super if number_or_id.is_a? Integer
41
- repository.build(number_or_id)
42
- end
44
+ def build(number_or_id)
45
+ return super if number_or_id.is_a? Integer
43
46
 
44
- def job(number_or_id)
45
- return super if number_or_id.is_a? Integer
46
- repository.job(number_or_id)
47
- end
47
+ repository.build(number_or_id)
48
+ end
48
49
 
49
- def branch(name)
50
- repository.branch(name)
51
- end
50
+ def job(number_or_id)
51
+ return super if number_or_id.is_a? Integer
52
52
 
53
- def last_build
54
- repository.last_build or error("no build yet for #{slug}")
55
- end
53
+ repository.job(number_or_id)
54
+ end
56
55
 
57
- def detected_endpoint?
58
- !explicit_api_endpoint?
59
- end
56
+ def branch(name)
57
+ repository.branch(name)
58
+ end
60
59
 
61
- def find_slug
62
- load_slug || begin
63
- slug = detect_slug
64
- interactive? ? store_slug(slug) : slug if slug
65
- end
66
- end
60
+ def last_build
61
+ repository.last_build or error("no build yet for #{slug}")
62
+ end
63
+
64
+ def detected_endpoint?
65
+ !explicit_api_endpoint?
66
+ end
67
67
 
68
- def detect_slug
69
- git_head = `git name-rev --name-only HEAD 2>#{IO::NULL}`.chomp
70
- git_remote = `git config --get branch.#{git_head}.remote 2>#{IO::NULL}`.chomp
71
- git_remote = 'origin' if git_remote.empty?
72
- git_info = `git ls-remote --get-url #{git_remote} 2>#{IO::NULL}`.chomp
73
-
74
- if parse_remote(git_info) =~ GIT_REGEX
75
- detected_slug = $1
76
- if interactive?
77
- if agree("Detected repository as #{color(detected_slug, :info)}, is this correct? ") { |q| q.default = 'yes' }
78
- detected_slug
79
- else
80
- ask("Repository slug (owner/name): ") { |q| q.default = detected_slug }
81
- end
82
- else
83
- info "detected repository as #{color(detected_slug, :bold)}"
84
- detected_slug
85
- end
68
+ def find_slug
69
+ load_slug || begin
70
+ slug = detect_slug
71
+ if slug
72
+ interactive? ? store_slug(slug) : slug
86
73
  end
87
74
  end
75
+ end
76
+
77
+ def detect_slug
78
+ git_head = `git name-rev --name-only HEAD 2>#{IO::NULL}`.chomp
79
+ git_remote = `git config --get branch.#{git_head}.remote 2>#{IO::NULL}`.chomp
80
+ git_remote = 'origin' if git_remote.empty?
81
+ git_info = `git ls-remote --get-url #{git_remote} 2>#{IO::NULL}`.chomp
82
+
83
+ return unless parse_remote(git_info) =~ GIT_REGEX
88
84
 
89
- def parse_remote(url)
90
- if url =~ /^git@[^:]+:/
91
- path = url.split(':').last
92
- path = "/#{path}" unless path.start_with?('/')
93
- path
85
+ detected_slug = ::Regexp.last_match(1)
86
+ if interactive?
87
+ if agree("Detected repository as #{color(detected_slug, :info)}, is this correct? ") do |q|
88
+ q.default = 'yes'
89
+ end
90
+ detected_slug
94
91
  else
95
- URI.parse(url).path
92
+ ask('Repository slug (owner/name): ') { |q| q.default = detected_slug }
96
93
  end
94
+ else
95
+ info "detected repository as #{color(detected_slug, :bold)}"
96
+ detected_slug
97
97
  end
98
+ end
98
99
 
99
- def load_slug
100
- stored = `git config --get travis.slug`.chomp
101
- stored unless stored.empty?
100
+ def parse_remote(url)
101
+ if url =~ /^git@[^:]+:/
102
+ path = url.split(':').last
103
+ path = "/#{path}" unless path.start_with?('/')
104
+ path
105
+ else
106
+ URI.parse(url).path
102
107
  end
108
+ end
103
109
 
104
- def store_slug(value)
105
- `git config travis.slug #{value}` if value
106
- value
107
- end
110
+ def load_slug
111
+ stored = `git config --get travis.slug`.chomp
112
+ stored unless stored.empty?
113
+ end
108
114
 
109
- def repo_config
110
- config['repos'] ||= {}
111
- config['repos'][slug] ||= {}
112
- end
115
+ def store_slug(value)
116
+ `git config travis.slug #{value}` if value
117
+ value
118
+ end
113
119
 
114
- def detect_api_endpoint
115
- if explicit_api_endpoint? or enterprise?
116
- repo_config['endpoint'] = api_endpoint
117
- elsif ENV['TRAVIS_ENDPOINT']
118
- ENV['TRAVIS_ENDPOINT']
119
- elsif config['default_endpoint'] and config['default_endpoint'] !~ TRAVIS
120
- repo_config['endpoint'] ||= config['default_endpoint']
121
- else
122
- repo_config['endpoint'] ||= begin
123
- load_gh
124
- GH.head("/repos/#{slug}")
125
- Travis::Client::ORG_URI
126
- rescue GH::Error
127
- Travis::Client::COM_URI
128
- end
129
- end
130
- end
120
+ def repo_config
121
+ config['repos'] ||= {}
122
+ config['repos'][slug] ||= {}
123
+ end
131
124
 
132
- def travis_config
133
- @travis_config ||= begin
134
- payload = YAML.load_file(travis_yaml)
135
- payload.respond_to?(:to_hash) ? payload.to_hash : {}
125
+ def detect_api_endpoint
126
+ if explicit_api_endpoint? || enterprise?
127
+ repo_config['endpoint'] = api_endpoint
128
+ elsif ENV['TRAVIS_ENDPOINT']
129
+ ENV['TRAVIS_ENDPOINT']
130
+ elsif config['default_endpoint'] && config['default_endpoint'] !~ (TRAVIS)
131
+ repo_config['endpoint'] ||= config['default_endpoint']
132
+ else
133
+ repo_config['endpoint'] ||= begin
134
+ load_gh
135
+ GH.head("/repos/#{slug}")
136
+ Travis::Client::ORG_URI
137
+ rescue GH::Error
138
+ Travis::Client::COM_URI
136
139
  end
137
140
  end
141
+ end
138
142
 
139
- def travis_yaml(dir = Dir.pwd)
140
- path = File.expand_path('.travis.yml', dir)
141
- if File.exist? path
142
- path
143
- else
144
- parent = File.expand_path('..', dir)
145
- error "no .travis.yml found" if parent == dir
146
- travis_yaml(parent)
147
- end
143
+ def travis_config
144
+ @travis_config ||= begin
145
+ payload = YAML.load_file(travis_yaml)
146
+ payload.respond_to?(:to_hash) ? payload.to_hash : {}
148
147
  end
148
+ end
149
149
 
150
- def confirm_and_save_travis_config(confirm = true, file = travis_yaml)
151
- if confirm
152
- ans = ask [
153
- nil,
154
- color("Overwrite the config file #{travis_yaml} with the content below?", [:info, :yellow]),
155
- color("This reformats the existing file.", [:info, :red]),
156
- travis_config.to_yaml,
157
- color("(y/N)", [:info, :yellow])
158
- ].join("\n\n")
159
- proceed = ans =~ /^y/i
160
- else
161
- proceed = true
162
- end
163
-
164
- save_travis_config if proceed
150
+ def travis_yaml(dir = Dir.pwd)
151
+ path = File.expand_path('.travis.yml', dir)
152
+ if File.exist? path
153
+ path
154
+ else
155
+ parent = File.expand_path('..', dir)
156
+ error 'no .travis.yml found' if parent == dir
157
+ travis_yaml(parent)
165
158
  end
159
+ end
166
160
 
167
- def save_travis_config(file = travis_yaml)
168
- yaml = travis_config.to_yaml
169
- yaml.gsub! /^(\s+)('on'|true):/, "\\1on:"
170
- yaml.gsub! /\A---\s*\n/, ''
171
- File.write(file, yaml)
172
- end
161
+ def confirm_and_save_travis_config(confirm = true, _file = travis_yaml)
162
+ if confirm
163
+ ans = ask [
164
+ nil,
165
+ color("Overwrite the config file #{travis_yaml} with the content below?", %i[info yellow]),
166
+ color('This reformats the existing file.', %i[info red]),
167
+ travis_config.to_yaml,
168
+ color('(y/N)', %i[info yellow])
169
+ ].join("\n\n")
170
+ proceed = ans =~ /^y/i
171
+ else
172
+ proceed = true
173
+ end
174
+
175
+ save_travis_config if proceed
176
+ end
177
+
178
+ def save_travis_config(file = travis_yaml)
179
+ yaml = travis_config.to_yaml
180
+ yaml.gsub!(/^(\s+)('on'|true):/, '\\1on:')
181
+ yaml.gsub!(/\A---\s*\n/, '')
182
+ File.write(file, yaml)
183
+ end
173
184
  end
174
185
  end
175
186
  end
@@ -1,65 +1,72 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'travis/cli'
2
4
  require 'travis/tools/system'
3
5
 
4
6
  module Travis
5
7
  module CLI
6
8
  class Report < ApiCommand
7
- description "generates a report useful for filing issues"
9
+ description 'generates a report useful for filing issues'
8
10
  on '-r', '--known-repos', 'include repositories in report'
9
11
  skip :authenticate, :clear_error
10
12
 
11
13
  def run
12
- display("System", :general)
13
- display("CLI", :cli_info)
14
- display("Session", :session_info)
15
- display("Endpoints", :endpoints)
16
- display("Known Repositories", :known_repos) if known_repos?
14
+ display('System', :general)
15
+ display('CLI', :cli_info)
16
+ display('Session', :session_info)
17
+ display('Endpoints', :endpoints)
18
+ display('Known Repositories', :known_repos) if known_repos?
17
19
  display_error
18
- say "For issues with the command line tool, please visit #{color("https://github.com/travis-ci/travis.rb/issues", :underline)}."
19
- say "For Travis CI in general, go to #{color("https://github.com/travis-ci/travis-ci/issues", :underline)} or email #{color("support@travis-ci.com", :underline)}."
20
+ say "For issues with the command line tool, please visit #{color(
21
+ 'https://github.com/travis-ci/travis.rb/issues', :underline
22
+ )}."
23
+ say "For Travis CI in general, go to #{color('https://github.com/travis-ci/travis-ci/issues',
24
+ :underline)} or email #{color('support@travis-ci.com',
25
+ :underline)}."
20
26
  end
21
27
 
22
28
  def display_error
23
- return unless error = load_file("error.log")
24
- display("Last Exception", :say, color(error, :info))
29
+ return unless (error = load_file('error.log'))
30
+
31
+ display('Last Exception', :say, color(error, :info))
25
32
  end
26
33
 
27
34
  def display(title, method, *args)
28
- say color(title, [:bold, :underline])
35
+ say color(title, %i[bold underline])
29
36
  send(method, *args) { |*a| list(*a) }
30
37
  puts
31
38
  end
32
39
 
33
40
  def list(key, value, additional = nil)
34
41
  value = case value
35
- when Array then value.empty? ? 'none' : value.map(&:inspect).join(", ")
36
- when true then "yes"
37
- when false then "no"
38
- when nil then "unknown"
42
+ when Array then value.empty? ? 'none' : value.map(&:inspect).join(', ')
43
+ when true then 'yes'
44
+ when false then 'no'
45
+ when nil then 'unknown'
39
46
  else value.to_s
40
47
  end
41
48
  additional &&= " (#{additional})"
42
- say "#{key}:".ljust(known_repos? ? 50 : 25) << " " << color(value.to_s, :bold) << additional.to_s
49
+ say "#{key}:".ljust(known_repos? ? 50 : 25) << ' ' << color(value.to_s, :bold) << additional.to_s
43
50
  end
44
51
 
45
52
  def general
46
- yield "Ruby", Tools::System.ruby
47
- yield "Operating System", Tools::System.os
48
- yield "RubyGems", Tools::System.rubygems
53
+ yield 'Ruby', Tools::System.ruby
54
+ yield 'Operating System', Tools::System.os
55
+ yield 'RubyGems', Tools::System.rubygems
49
56
  end
50
57
 
51
58
  def cli_info
52
- yield "Version", Travis::VERSION
53
- yield "Plugins", defined?(TRAVIS_PLUGINS) ? TRAVIS_PLUGINS : []
54
- yield "Auto-Completion", Tools::Completion.completion_installed?
55
- yield "Last Version Check", last_check['at'] ? Time.at(last_check['at']) : 'never'
59
+ yield 'Version', Travis::VERSION
60
+ yield 'Plugins', defined?(TRAVIS_PLUGINS) ? TRAVIS_PLUGINS : []
61
+ yield 'Auto-Completion', Tools::Completion.completion_installed?
62
+ yield 'Last Version Check', last_check['at'] ? Time.at(last_check['at']) : 'never'
56
63
  end
57
64
 
58
65
  def session_info
59
- yield "API Endpoint", api_endpoint
60
- yield "Logged In", user_info
61
- yield "Verify SSL", !insecure
62
- yield "Enterprise", enterprise?
66
+ yield 'API Endpoint', api_endpoint
67
+ yield 'Logged In', user_info
68
+ yield 'Verify SSL', !insecure
69
+ yield 'Enterprise', enterprise?
63
70
  end
64
71
 
65
72
  def endpoints
@@ -74,25 +81,25 @@ module Travis
74
81
  end
75
82
  end
76
83
 
77
- def endpoint_name(url, prefix = "")
84
+ def endpoint_name(url, prefix = '')
78
85
  case url
79
86
  when Travis::Client::ORG_URI then "#{prefix}org"
80
87
  when Travis::Client::COM_URI then "#{prefix}com"
81
- when /api-staging\.travis-ci/ then endpoint_name(url.sub("api-staging.", "api."), "staging-")
88
+ when /api-staging\.travis-ci/ then endpoint_name(url.sub('api-staging.', 'api.'), 'staging-')
82
89
  else
83
- key, _ = config['enterprise'].detect { |k,v| v.start_with? url } if config['enterprise'].respond_to?(:detect)
84
- key ? "enterprise %p" % key : "???"
90
+ key, = config['enterprise'].detect { |_k, v| v.start_with? url } if config['enterprise'].respond_to?(:detect)
91
+ key ? 'enterprise %p' % key : '???'
85
92
  end
86
93
  end
87
94
 
88
95
  def known_repos
89
- config["repos"].each do |key, info|
96
+ config['repos'].each do |key, info|
90
97
  yield key, info['endpoint']
91
98
  end
92
99
  end
93
100
 
94
101
  def user_info
95
- access_token ? "as %p" % user.login : "no"
102
+ access_token ? 'as %p' % user.login : 'no'
96
103
  rescue Travis::Client::Error => e
97
104
  e.message
98
105
  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 Repos < ApiCommand
6
- description "lists repositories the user has certain permissions on"
8
+ description 'lists repositories the user has certain permissions on'
7
9
  on('-m', '--match PATTERN', 'only list repositories matching the given pattern (shell style)')
8
10
  on('-o', '--owner LOGIN', 'only list repos for a certain owner')
9
11
  on('-n', '--name NAME', 'only list repos with a given name')
@@ -15,11 +17,12 @@ module Travis
15
17
  def run
16
18
  repositories.each do |repo|
17
19
  next say(repo.slug) unless interactive?
20
+
18
21
  state_color = repo.active? ? :green : :yellow
19
- say color(repo.slug, [:bold, state_color]) + " "
20
- say color("(" << attributes(repo).map { |n,v| "#{n}: #{v ? "yes" : "no"}" }.join(", ") << ")", state_color)
22
+ say "#{color(repo.slug, [:bold, state_color])} "
23
+ say color('(' << attributes(repo).map { |n, v| "#{n}: #{v ? 'yes' : 'no'}" }.join(', ') << ')', state_color)
21
24
  description = repo.description.lines.first.chomp unless repo.description.to_s.empty?
22
- say "Description: #{description || "???"}"
25
+ say "Description: #{description || '???'}"
23
26
  empty_line unless repo == repositories.last
24
27
  end
25
28
  end
@@ -29,21 +32,23 @@ module Travis
29
32
  repos = session.hooks.concat(user.repositories).uniq
30
33
  session.preload(repos).sort_by(&:slug).select do |repo|
31
34
  next false unless match? repo.slug
32
- next false unless active.nil? or repo.active? == active
33
- next false unless owner.nil? or repo.owner_name == owner
34
- next false unless name.nil? or repo.name == name
35
- next false unless admin.nil? or repo.admin? == admin
35
+ next false unless active.nil? || (repo.active? == active)
36
+ next false unless owner.nil? || (repo.owner_name == owner)
37
+ next false unless name.nil? || (repo.name == name)
38
+ next false unless admin.nil? || (repo.admin? == admin)
39
+
36
40
  true
37
41
  end
38
42
  end
39
43
  end
40
44
 
41
45
  def attributes(repo)
42
- { "active" => repo.active?, "admin" => repo.admin?, "push" => repo.push?, "pull" => repo.pull? }
46
+ { 'active' => repo.active?, 'admin' => repo.admin?, 'push' => repo.push?, 'pull' => repo.pull? }
43
47
  end
44
48
 
45
49
  def match?(string)
46
50
  return true if match.nil?
51
+
47
52
  flags = File::FNM_PATHNAME | File::FNM_DOTMATCH
48
53
  flags |= File::FNM_EXTGLOB if defined? File::FNM_EXTGLOB
49
54
  File.fnmatch?(match, string, flags)
@@ -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 Requests < RepoCommand
6
- description "lists recent requests"
8
+ description 'lists recent requests'
7
9
  on '-l', '--limit LIMIT', 'Maximum number requests to display'
8
10
 
9
11
  def run
@@ -16,18 +18,17 @@ module Travis
16
18
 
17
19
  case request.event_type
18
20
  when 'push'
19
- result = request.result || "received"
21
+ result = request.result || 'received'
20
22
  message = request.message
21
- message ||= "validation pending" unless request.rejected? or request.accepted?
22
- message ||= "unknown reason" unless request.accepted?
23
- message ||= "triggered new build" unless request.rejected?
24
- description = "push to #{request.branch || request.tag || "???"}"
23
+ message ||= 'validation pending' unless request.rejected? || request.accepted?
24
+ message ||= 'unknown reason' unless request.accepted?
25
+ message ||= 'triggered new build' unless request.rejected?
26
+ description = "push to #{request.branch || request.tag || '???'}"
25
27
  when 'pull_request'
26
- result = request.result || "received"
28
+ result = request.result || 'received'
27
29
  message = request.message
28
- message ||= "HEAD commit not updated" unless request.accepted?
29
- message ||= "triggered new build" unless request.rejected?
30
- description = "push to #{request.branch || request.tag || "???"}"
30
+ message ||= 'HEAD commit not updated' unless request.accepted?
31
+ message ||= 'triggered new build' unless request.rejected?
31
32
  description = "PR ##{request.pull_request_number}"
32
33
  end
33
34
 
@@ -35,9 +36,9 @@ module Travis
35
36
  color(description, [:bold, style]),
36
37
  color(result, style),
37
38
  color("(#{message})", style)
38
- ].join(" ").strip + "\n"
39
+ ].join(' ').strip + "\n"
39
40
 
40
- say " " + color(request.commit.short_sha, :bold) + " - " + request.commit.subject if request.commit
41
+ say " #{color(request.commit.short_sha, :bold)} - #{request.commit.subject}" if request.commit
41
42
  say " received at: #{formatter.time(request.created_at)}"
42
43
  empty_line
43
44
  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 Restart < RepoCommand
6
- description "restarts a build or job"
8
+ description 'restarts a build or job'
7
9
 
8
10
  def run(number = last_build.number)
9
11
  authenticate
@@ -11,7 +13,7 @@ module Travis
11
13
  error "could not find job or build #{repository.slug}##{number}" unless entity
12
14
  entity.restart
13
15
 
14
- say "restarted", "#{entity.class.one} ##{entity.number} has been %s"
16
+ say 'restarted', "#{entity.class.one} ##{entity.number} has been %s"
15
17
  end
16
18
  end
17
19
  end