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,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'travis/client'
2
4
 
3
5
  module Travis
4
6
  module Client
5
7
  module States
6
- STATES = %w[created queued received started passed failed errored canceled ready]
8
+ STATES = %w[created queued received started passed failed errored canceled ready].freeze
7
9
 
8
10
  def ready?
9
11
  state == 'ready'
@@ -11,7 +13,7 @@ module Travis
11
13
 
12
14
  def pending?
13
15
  check_state
14
- %w[created started queued received ].include? state
16
+ %w[created started queued received].include? state
15
17
  end
16
18
 
17
19
  def started?
@@ -30,7 +32,7 @@ module Travis
30
32
  end
31
33
 
32
34
  def finished?
33
- not pending?
35
+ !pending?
34
36
  end
35
37
 
36
38
  def passed?
@@ -90,9 +92,9 @@ module Travis
90
92
 
91
93
  private
92
94
 
93
- def check_state
94
- raise Error, "unknown state %p for %p" % [state, self] unless STATES.include? state
95
- end
95
+ def check_state
96
+ raise Error, format('unknown state %p for %p', state, self) unless STATES.include? state
97
+ end
96
98
  end
97
99
  end
98
100
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'travis/client'
2
4
 
3
5
  module Travis
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'travis/client'
2
4
 
3
5
  module Travis
@@ -10,7 +12,7 @@ module Travis
10
12
  end
11
13
 
12
14
  def self.id_field
13
- raise "weak entities do not have id fields"
15
+ raise 'weak entities do not have id fields'
14
16
  end
15
17
 
16
18
  def self.id?(object)
@@ -19,8 +21,9 @@ module Travis
19
21
 
20
22
  def self.cast_id(object)
21
23
  return object if id? object
22
- raise "weak entities do not have id fields"
24
+
25
+ raise 'weak entities do not have id fields'
23
26
  end
24
27
  end
25
28
  end
26
- end
29
+ end
data/lib/travis/client.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'travis/client/error'
2
4
  require 'travis/client/states'
3
5
  require 'travis/client/restartable'
@@ -26,11 +28,12 @@ require 'travis/client/lint_result'
26
28
 
27
29
  module Travis
28
30
  module Client
31
+
29
32
  ORG_URI = 'https://api.travis-ci.org/'
30
33
  COM_URI = 'https://api.travis-ci.com/'
31
34
 
32
35
  def self.new(options = {})
33
- options[:uri] ||= ORG_URI if options.is_a? Hash and not options['uri']
36
+ options[:uri] ||= COM_URI if options.is_a?(Hash) && !(options['uri'])
34
37
  Session.new(options)
35
38
  end
36
39
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'travis/pro'
2
4
  require 'travis/client/auto_login'
3
5
  Travis::Client::AutoLogin.new(Travis::Pro).authenticate
data/lib/travis/pro.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'travis/client'
2
4
 
3
5
  module Travis
@@ -1,13 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'pathname'
2
4
  module Travis
3
5
  module Tools
4
6
  module Assets
5
- BASE = File.expand_path('../../../../assets', __FILE__)
6
- extend self
7
+ BASE = File.expand_path('../../../assets', __dir__)
8
+
9
+ module_function
7
10
 
8
11
  def asset_path(file)
9
12
  Pathname.glob(File.expand_path(file, BASE)).tap do |x|
10
- raise Travis::Client::AssetNotFound.new(file) if x.empty?
13
+ raise Travis::Client::AssetNotFound, file if x.empty?
11
14
  end.first.to_s
12
15
  end
13
16
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'travis/tools/assets'
2
4
  require 'travis/cli'
3
5
  require 'fileutils'
@@ -8,7 +10,8 @@ module Travis
8
10
  module Completion
9
11
  RCS = ['.zshrc', '.bashrc'].map { |f| File.expand_path(f, ENV['HOME']) }
10
12
  include FileUtils
11
- extend self
13
+
14
+ module_function
12
15
 
13
16
  def config_path
14
17
  ENV.fetch('TRAVIS_CONFIG_PATH') { File.expand_path('.travis', ENV['HOME']) }
@@ -20,12 +23,13 @@ module Travis
20
23
 
21
24
  def install_completion
22
25
  update_completion
23
- source = "source " << cmp_file
26
+ source = 'source ' << cmp_file
24
27
 
25
28
  RCS.each do |file|
26
- next unless File.exist? file and File.writable? file
29
+ next unless File.exist?(file) && File.writable?(file)
27
30
  next if File.read(file).include? source
28
- File.open(file, "a") { |f| f.puts("", "# added by travis gem", "[ ! -s #{cmp_file} ] || #{source}") }
31
+
32
+ File.open(file, 'a') { |f| f.puts('', '# added by travis gem', "[ ! -s #{cmp_file} ] || #{source}") }
29
33
  end
30
34
  end
31
35
 
@@ -35,9 +39,9 @@ module Travis
35
39
  end
36
40
 
37
41
  def completion_installed?
38
- source = "source " << config_path
42
+ source = 'source ' << config_path
39
43
  RCS.each do |file|
40
- next unless File.exist? file and File.writable? file
44
+ next unless File.exist?(file) && File.writable?(file)
41
45
  return false unless File.read(file).include? source
42
46
  end
43
47
  true
@@ -1,30 +1,35 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'time'
2
4
 
3
5
  module Travis
4
6
  module Tools
5
7
  class Formatter
6
8
  DAY = 24 * 60 * 60
7
- TIME_FORMAT = "%Y-%m-%d %H:%M:%S"
8
- CONFIG_KEYS = ['rvm', 'gemfile', 'env', 'jdk', 'otp_release', 'php', 'node_js', 'perl', 'python', 'scala', 'compiler', 'os']
9
+ TIME_FORMAT = '%Y-%m-%d %H:%M:%S'
10
+ CONFIG_KEYS = %w[rvm gemfile env jdk otp_release php node_js perl python scala
11
+ compiler os].freeze
9
12
 
10
13
  def duration(seconds, suffix = nil)
11
- return "none" if seconds.nil?
14
+ return 'none' if seconds.nil?
15
+
12
16
  seconds = (Time.now - seconds).to_i if seconds.is_a? Time
13
17
  output = []
14
18
  minutes, seconds = seconds.divmod(60)
15
19
  hours, minutes = minutes.divmod(60)
16
- output << "#{hours } hrs" if hours > 0
17
- output << "#{minutes} min" if minutes > 0
18
- output << "#{seconds} sec" if seconds > 0 or output.empty?
20
+ output << "#{hours} hrs" if hours.positive?
21
+ output << "#{minutes} min" if minutes.positive?
22
+ output << "#{seconds} sec" if seconds.positive? || output.empty?
19
23
  output << suffix if suffix
20
- output.join(" ")
24
+ output.join(' ')
21
25
  end
22
26
 
23
- def file_size(input, human = true)
27
+ def file_size(input, human: true)
24
28
  return "#{input} B" unless human
25
- format = "B"
29
+
30
+ format = 'B'
26
31
  iec = %w[KiB MiB GiB TiB PiB EiB ZiB YiB]
27
- while human and input > 512 and iec.any?
32
+ while human && (input > 512) && iec.any?
28
33
  input /= 1024.0
29
34
  format = iec.shift
30
35
  end
@@ -33,8 +38,9 @@ module Travis
33
38
  end
34
39
 
35
40
  def time(time)
36
- return "not yet" if time.nil? # or time > Time.now
37
- #return duration(time, "ago") if Time.now - time < DAY
41
+ return 'not yet' if time.nil? # or time > Time.now
42
+
43
+ # return duration(time, "ago") if Time.now - time < DAY
38
44
  time.localtime.strftime(TIME_FORMAT)
39
45
  end
40
46
 
@@ -43,8 +49,8 @@ module Travis
43
49
  config.each_pair do |key, value|
44
50
  output << "#{key}: #{value}" if CONFIG_KEYS.include? key
45
51
  end
46
- output.join(", ")
52
+ output.join(', ')
47
53
  end
48
54
  end
49
55
  end
50
- end
56
+ end
@@ -1,3 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'English'
1
4
  require 'travis/tools/system'
2
5
  require 'yaml'
3
6
  require 'json'
@@ -11,21 +14,21 @@ module Travis
11
14
  GITHUB_HOST = 'github.com'
12
15
 
13
16
  attr_accessor :api_url, :scopes, :github_token, :drop_token, :callback, :explode, :after_tokens,
14
- :login_header, :auto_token, :note,
15
- :hub_path, :oauth_paths, :composer_path, :git_config_keys, :debug, :no_token, :check_token
17
+ :login_header, :auto_token, :note,
18
+ :hub_path, :oauth_paths, :composer_path, :git_config_keys, :debug, :no_token, :check_token
16
19
 
17
20
  def initialize(options = nil)
18
21
  @check_token = true
19
- @ask_login = proc { raise "ask_login callback not set" }
20
- @after_tokens = proc { }
22
+ @ask_login = proc { raise 'ask_login callback not set' }
23
+ @after_tokens = proc {}
21
24
  @debug = proc { |_| }
22
25
  @hub_path = ENV['HUB_CONFIG'] || '~/.config/hub'
23
26
  @oauth_paths = ['~/.github-oauth-token']
24
- @composer_path = "~/.composer/config.json"
27
+ @composer_path = '~/.composer/config.json'
25
28
  @note = 'temporary token'
26
29
  @git_config_keys = %w[github.token github.oauth-token]
27
30
  @scopes = ['user', 'user:email', 'repo'] # overridden by value from /config
28
- options.each_pair { |k,v| send("#{k}=", v) if respond_to? "#{k}=" } if options
31
+ options&.each_pair { |k, v| send("#{k}=", v) if respond_to? "#{k}=" }
29
32
  yield self if block_given?
30
33
  end
31
34
 
@@ -37,12 +40,13 @@ module Travis
37
40
  require 'gh' unless defined? GH
38
41
  possible_tokens { |t| yield(t) if acceptable?(t) }
39
42
  ensure
40
- callback, self.callback = self.callback, nil
41
- callback.call if callback
43
+ callback = self.callback
44
+ self.callback = nil
45
+ callback&.call
42
46
  end
43
47
 
44
- def with_session(&block)
45
- with_token { |t| GH.with(:token => t) { yield(t) } }
48
+ def with_session
49
+ with_token { |t| GH.with(token: t) { yield(t) } }
46
50
  end
47
51
 
48
52
  def possible_tokens(&block)
@@ -66,6 +70,7 @@ module Travis
66
70
 
67
71
  def git_tokens
68
72
  return unless System.has? 'git'
73
+
69
74
  git_config_keys.each do |key|
70
75
  `git config --get-all #{key}`.each_line do |line|
71
76
  token = line.strip
@@ -83,11 +88,11 @@ module Travis
83
88
 
84
89
  def hub_tokens
85
90
  hub.fetch(host, []).each do |entry|
86
- yield entry["oauth_token"] if entry["oauth_token"]
91
+ yield entry['oauth_token'] if entry['oauth_token']
87
92
  end
88
93
  end
89
94
 
90
- def oauth_file_tokens(&block)
95
+ def oauth_file_tokens
91
96
  oauth_paths.each do |path|
92
97
  file(path) do |content|
93
98
  token = content.strip
@@ -103,12 +108,12 @@ module Travis
103
108
  end
104
109
 
105
110
  def issuepost_token(&block)
106
- security(:generic, :w, "-l issuepost.github.access_token", "issuepost token", &block) if host == 'github.com'
111
+ security(:generic, :w, '-l issuepost.github.access_token', 'issuepost token', &block) if host == 'github.com'
107
112
  end
108
113
 
109
114
  def github_for_mac_token(&block)
110
115
  command = '-s "github.com/mac"'
111
- security(:internet, :w, command, "GitHub for Mac token", &block) if host == 'github.com'
116
+ security(:internet, :w, command, 'GitHub for Mac token', &block) if host == 'github.com'
112
117
  end
113
118
 
114
119
  def host
@@ -117,57 +122,62 @@ module Travis
117
122
 
118
123
  def api_host
119
124
  return GITHUB_API unless api_url
125
+
120
126
  api_url[%r{^(?:https?://)?([^/]+)}, 1]
121
127
  end
122
128
 
123
129
  def acceptable?(token)
124
130
  return true unless check_token
125
- gh = GH.with(:token => token)
126
- user = gh['user']
131
+
132
+ gh = GH.with(token:)
133
+ gh['user']
127
134
 
128
135
  true
129
- rescue GH::Error => error
130
- debug "token is not acceptable: #{gh_error(error)}"
136
+ rescue GH::Error => e
137
+ debug "token is not acceptable: #{gh_error(e)}"
131
138
  false
132
139
  end
133
140
 
134
141
  private
135
142
 
136
- def gh_error(error)
137
- raise error if explode
138
- if error.info.key? :response_body
139
- JSON.parse(error.info[:response_body])["message"].to_s
140
- else
141
- "Unknown error"
142
- end
143
- end
143
+ def gh_error(error)
144
+ raise error if explode
144
145
 
145
- def debug(line)
146
- return unless @debug
147
- @debug.call "Tools::Github: #{line}"
146
+ if error.info.key? :response_body
147
+ JSON.parse(error.info[:response_body])['message'].to_s
148
+ else
149
+ 'Unknown error'
148
150
  end
151
+ end
149
152
 
150
- def security(type, key, arg, name)
151
- return false unless System.has? 'security'
152
- return false unless system "security find-#{type}-password #{arg} 2>/dev/null >/dev/null"
153
- debug "requesting to load #{name} from keychain"
154
- result = %x[security find-#{type}-password #{arg} -#{key} 2>&1].chomp
155
- $?.success? ? yield(result) : debug("request denied")
156
- rescue => e
157
- raise e if explode
158
- end
153
+ def debug(line)
154
+ return unless @debug
159
155
 
160
- def file(path, default = nil)
161
- path &&= File.expand_path(path)
162
- @file ||= {}
163
- @file[path] ||= if path and File.readable?(path)
164
- debug "reading #{path}"
165
- yield File.read(path)
166
- end
167
- @file[path] || default
168
- rescue => e
169
- raise e if explode
170
- end
156
+ @debug.call "Tools::Github: #{line}"
157
+ end
158
+
159
+ def security(type, key, arg, name)
160
+ return false unless System.has? 'security'
161
+ return false unless system "security find-#{type}-password #{arg} 2>/dev/null >/dev/null"
162
+
163
+ debug "requesting to load #{name} from keychain"
164
+ result = `security find-#{type}-password #{arg} -#{key} 2>&1`.chomp
165
+ $CHILD_STATUS.success? ? yield(result) : debug('request denied')
166
+ rescue StandardError => e
167
+ raise e if explode
168
+ end
169
+
170
+ def file(path, default = nil)
171
+ path &&= File.expand_path(path)
172
+ @file ||= {}
173
+ @file[path] ||= if path && File.readable?(path)
174
+ debug "reading #{path}"
175
+ yield File.read(path)
176
+ end
177
+ @file[path] || default
178
+ rescue StandardError => e
179
+ raise e if explode
180
+ end
171
181
  end
172
182
  end
173
183
  end
@@ -1,31 +1,35 @@
1
- require "travis"
2
- require "travis/tools/system"
3
- require "travis/tools/assets"
4
- require "cgi"
1
+ # frozen_string_literal: true
2
+
3
+ require 'travis'
4
+ require 'travis/tools/system'
5
+ require 'travis/tools/assets'
6
+ require 'cgi'
5
7
 
6
8
  module Travis
7
9
  module Tools
8
10
  module Notification
9
- extend self
10
- DEFAULT = [:osx, :growl, :libnotify]
11
+ module_function
12
+
13
+ DEFAULT = %i[osx growl libnotify].freeze
11
14
  ICON = Assets['notifications/icon.png']
12
15
 
13
16
  def new(*list)
14
17
  list.concat(DEFAULT) if list.empty?
15
18
  notification = list.map { |n| get(n) }.detect { |n| n.available? }
16
- raise ArgumentError, "no notification system found (looked for #{list.join(", ")})" unless notification
19
+ raise ArgumentError, "no notification system found (looked for #{list.join(', ')})" unless notification
20
+
17
21
  notification
18
22
  end
19
23
 
20
24
  def get(name)
21
25
  const = constants.detect { |c| c.to_s[/[^:]+$/].downcase == name.to_s }
22
- raise ArgumentError, "unknown notifications type %p" % name unless const
26
+ raise ArgumentError, 'unknown notifications type %p' % name unless const
27
+
23
28
  const_get(const).new
24
29
  end
25
30
 
26
31
  class Dummy
27
- def notify(title, body)
28
- end
32
+ def notify(title, body); end
29
33
 
30
34
  def available?
31
35
  true
@@ -33,14 +37,15 @@ module Travis
33
37
  end
34
38
 
35
39
  class OSX
36
- BIN_PATH = Assets["notifications/Travis CI.app/Contents/MacOS/Travis CI"]
40
+ BIN_PATH = Assets['notifications/Travis CI.app/Contents/MacOS/Travis CI']
37
41
 
38
42
  def notify(title, body)
39
43
  system BIN_PATH, '-message', body.to_s, '-title', title.to_s, '-sender', 'org.travis-ci.Travis-CI'
40
44
  end
41
45
 
42
46
  def available?
43
- System.mac? and System.recent_version?(System.os_version.to_s, '10.8') and System.running? "NotificationCenter"
47
+ System.mac? and System.recent_version?(System.os_version.to_s,
48
+ '10.8') and System.running? 'NotificationCenter'
44
49
  end
45
50
  end
46
51
 
@@ -50,7 +55,7 @@ module Travis
50
55
  end
51
56
 
52
57
  def available?
53
- System.has? 'growlnotify' and System.running? "Growl"
58
+ System.has? 'growlnotify' and System.running? 'Growl'
54
59
  end
55
60
  end
56
61
 
@@ -1,10 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Travis
2
4
  module Tools
3
5
  module SafeString
4
- extend self
6
+ module_function
5
7
 
6
8
  def encoded(string)
7
9
  return string unless string.respond_to? :encode
10
+
8
11
  string.encode 'utf-8'
9
12
  rescue Encoding::UndefinedConversionError
10
13
  string.force_encoding 'utf-8'
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'openssl'
2
4
  require 'base64'
3
5
 
4
6
  module Travis
5
7
  module Tools
6
8
  module SSLKey
7
- extend self
9
+ module_function
8
10
 
9
11
  def generate_rsa(size = 2048)
10
12
  OpenSSL::PKey::RSA.generate(size)
@@ -40,7 +42,8 @@ module Travis
40
42
  end
41
43
 
42
44
  def to_byte_array(num, *significant)
43
- return significant if num.between?(-1, 0) and significant[0][7] == num[7]
45
+ return significant if num.between?(-1, 0) && (significant[0][7] == num[7])
46
+
44
47
  to_byte_array(*num.divmod(256)) + significant
45
48
  end
46
49
  end
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Travis
2
4
  module Tools
3
5
  module System
4
- extend self
6
+ module_function
5
7
 
6
8
  def recent_version?(version, minimum)
7
9
  version = version.split('.').map { |s| s.to_i }
@@ -10,7 +12,7 @@ module Travis
10
12
  end
11
13
 
12
14
  def windows?
13
- File::ALT_SEPARATOR == "\\"
15
+ File::ALT_SEPARATOR == '\\'
14
16
  end
15
17
 
16
18
  def mac?
@@ -22,7 +24,7 @@ module Travis
22
24
  end
23
25
 
24
26
  def unix?
25
- not windows?
27
+ !windows?
26
28
  end
27
29
 
28
30
  def os
@@ -52,7 +54,7 @@ module Travis
52
54
  end
53
55
 
54
56
  def ruby_version
55
- "%s-p%s" % [RUBY_VERSION, RUBY_PATCHLEVEL]
57
+ format('%s-p%s', RUBY_VERSION, RUBY_PATCHLEVEL)
56
58
  end
57
59
 
58
60
  def ruby
@@ -65,22 +67,25 @@ module Travis
65
67
  end
66
68
 
67
69
  def rubygems
68
- return "no RubyGems" unless defined? Gem
70
+ return 'no RubyGems' unless defined? Gem
71
+
69
72
  "RubyGems #{Gem::VERSION}"
70
73
  end
71
74
 
72
75
  def description(*args)
73
- [ full_os, ruby, rubygems, *args.flatten].compact.uniq.join("; ")
76
+ [full_os, ruby, rubygems, *args.flatten].compact.uniq.join('; ')
74
77
  end
75
78
 
76
79
  def has?(command)
77
80
  return false unless unix?
81
+
78
82
  @has ||= {}
79
83
  @has.fetch(command) { @has[command] = system "command -v #{command} 2>/dev/null >/dev/null" }
80
84
  end
81
85
 
82
86
  def running?(app)
83
87
  return false unless unix?
88
+
84
89
  system "/usr/bin/pgrep -u $(whoami) #{app} >/dev/null"
85
90
  end
86
91
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Travis
2
- VERSION = '1.11.1'
4
+ VERSION = '1.13.0'
3
5
  end
data/lib/travis.rb CHANGED
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Travis
2
4
  autoload :Client, 'travis/client'
3
5
  autoload :CLI, 'travis/cli'
4
6
  autoload :Pro, 'travis/pro'
5
7
  autoload :Version, 'travis/version'
6
8
 
7
- include Client::Namespace.new(Client::ORG_URI)
9
+ include Client::Namespace.new(Client::COM_URI)
8
10
  end