travis 1.11.1 → 1.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +34 -3
- data/Rakefile +22 -20
- data/bin/travis +5 -3
- data/examples/org_overview.rb +2 -0
- data/examples/pro_auth.rb +3 -1
- data/examples/stream.rb +5 -3
- data/lib/travis/auto_login.rb +2 -0
- data/lib/travis/cli/accounts.rb +12 -9
- data/lib/travis/cli/api_command.rb +85 -81
- data/lib/travis/cli/branches.rb +8 -6
- data/lib/travis/cli/cache.rb +48 -44
- data/lib/travis/cli/cancel.rb +4 -2
- data/lib/travis/cli/command.rb +170 -142
- data/lib/travis/cli/console.rb +5 -5
- data/lib/travis/cli/disable.rb +4 -2
- data/lib/travis/cli/enable.rb +14 -12
- data/lib/travis/cli/encrypt.rb +57 -57
- data/lib/travis/cli/encrypt_file.rb +29 -18
- data/lib/travis/cli/endpoint.rb +9 -7
- data/lib/travis/cli/env.rb +13 -8
- data/lib/travis/cli/help.rb +11 -9
- data/lib/travis/cli/history.rb +19 -15
- data/lib/travis/cli/init.rb +27 -24
- data/lib/travis/cli/lint.rb +10 -8
- data/lib/travis/cli/login.rb +17 -11
- data/lib/travis/cli/logout.rb +4 -2
- data/lib/travis/cli/logs.rb +28 -19
- data/lib/travis/cli/monitor.rb +11 -8
- data/lib/travis/cli/open.rb +17 -14
- data/lib/travis/cli/parser.rb +2 -0
- data/lib/travis/cli/pubkey.rb +13 -11
- data/lib/travis/cli/raw.rb +4 -3
- data/lib/travis/cli/regenerate_token.rb +15 -0
- data/lib/travis/cli/remove_token.rb +15 -0
- data/lib/travis/cli/repo_command.rb +123 -112
- data/lib/travis/cli/report.rb +40 -33
- data/lib/travis/cli/repos.rb +14 -9
- data/lib/travis/cli/requests.rb +13 -12
- data/lib/travis/cli/restart.rb +4 -2
- data/lib/travis/cli/settings.rb +41 -35
- data/lib/travis/cli/setup/anynines.rb +7 -6
- data/lib/travis/cli/setup/appfog.rb +6 -4
- data/lib/travis/cli/setup/artifacts.rb +7 -5
- data/lib/travis/cli/setup/biicode.rb +6 -4
- data/lib/travis/cli/setup/cloud_66.rb +6 -4
- data/lib/travis/cli/setup/cloud_control.rb +8 -6
- data/lib/travis/cli/setup/cloud_files.rb +7 -5
- data/lib/travis/cli/setup/cloud_foundry.rb +9 -7
- data/lib/travis/cli/setup/code_deploy.rb +33 -29
- data/lib/travis/cli/setup/deis.rb +8 -6
- data/lib/travis/cli/setup/divshot.rb +20 -18
- data/lib/travis/cli/setup/elastic_beanstalk.rb +10 -8
- data/lib/travis/cli/setup/engine_yard.rb +9 -7
- data/lib/travis/cli/setup/gcs.rb +9 -7
- data/lib/travis/cli/setup/hackage.rb +6 -4
- data/lib/travis/cli/setup/heroku.rb +10 -4
- data/lib/travis/cli/setup/modulus.rb +5 -3
- data/lib/travis/cli/setup/ninefold.rb +7 -5
- data/lib/travis/cli/setup/nodejitsu.rb +6 -4
- data/lib/travis/cli/setup/npm.rb +6 -4
- data/lib/travis/cli/setup/open_shift.rb +8 -6
- data/lib/travis/cli/setup/opsworks.rb +24 -22
- data/lib/travis/cli/setup/pypi.rb +7 -5
- data/lib/travis/cli/setup/releases.rb +6 -6
- data/lib/travis/cli/setup/ruby_gems.rb +7 -5
- data/lib/travis/cli/setup/s3.rb +12 -8
- data/lib/travis/cli/setup/sauce_connect.rb +7 -5
- data/lib/travis/cli/setup/service.rb +36 -25
- data/lib/travis/cli/setup.rb +7 -3
- data/lib/travis/cli/show.rb +10 -8
- data/lib/travis/cli/sshkey.rb +31 -27
- data/lib/travis/cli/status.rb +5 -3
- data/lib/travis/cli/sync.rb +9 -7
- data/lib/travis/cli/token.rb +4 -2
- data/lib/travis/cli/version.rb +4 -3
- data/lib/travis/cli/whatsup.rb +10 -8
- data/lib/travis/cli/whoami.rb +2 -2
- data/lib/travis/cli.rb +81 -76
- data/lib/travis/client/account.rb +8 -6
- data/lib/travis/client/artifact.rb +16 -12
- data/lib/travis/client/auto_login.rb +7 -4
- data/lib/travis/client/broadcast.rb +2 -0
- data/lib/travis/client/build.rb +7 -3
- data/lib/travis/client/cache.rb +4 -2
- data/lib/travis/client/commit.rb +5 -2
- data/lib/travis/client/entity.rb +50 -46
- data/lib/travis/client/env_var.rb +13 -8
- data/lib/travis/client/error.rb +5 -3
- data/lib/travis/client/has_uuid.rb +3 -1
- data/lib/travis/client/job.rb +8 -3
- data/lib/travis/client/lint_result.rb +2 -0
- data/lib/travis/client/listener.rb +70 -55
- data/lib/travis/client/methods.rb +26 -5
- data/lib/travis/client/namespace.rb +20 -16
- data/lib/travis/client/not_loadable.rb +3 -1
- data/lib/travis/client/repository.rb +34 -22
- data/lib/travis/client/request.rb +5 -2
- data/lib/travis/client/restartable.rb +2 -0
- data/lib/travis/client/session.rb +118 -88
- data/lib/travis/client/settings.rb +8 -3
- data/lib/travis/client/singleton_setting.rb +2 -0
- data/lib/travis/client/ssh_key.rb +2 -0
- data/lib/travis/client/states.rb +8 -6
- data/lib/travis/client/user.rb +2 -0
- data/lib/travis/client/weak_entity.rb +6 -3
- data/lib/travis/client.rb +4 -1
- data/lib/travis/pro/auto_login.rb +2 -0
- data/lib/travis/pro.rb +2 -0
- data/lib/travis/tools/assets.rb +6 -3
- data/lib/travis/tools/completion.rb +10 -6
- data/lib/travis/tools/formatter.rb +20 -14
- data/lib/travis/tools/github.rb +59 -49
- data/lib/travis/tools/notification.rb +18 -13
- data/lib/travis/tools/safe_string.rb +4 -1
- data/lib/travis/tools/ssl_key.rb +5 -2
- data/lib/travis/tools/system.rb +11 -6
- data/lib/travis/version.rb +3 -1
- data/lib/travis.rb +3 -1
- data/spec/cli/api_command_spec.rb +11 -8
- data/spec/cli/cancel_spec.rb +2 -4
- data/spec/cli/encrypt_file_spec.rb +9 -7
- data/spec/cli/encrypt_spec.rb +19 -17
- data/spec/cli/endpoint_spec.rb +12 -10
- data/spec/cli/help_spec.rb +14 -12
- data/spec/cli/history_spec.rb +2 -0
- data/spec/cli/init_spec.rb +35 -33
- data/spec/cli/logs_spec.rb +2 -0
- data/spec/cli/open_spec.rb +6 -4
- data/spec/cli/repo_command_spec.rb +8 -4
- data/spec/cli/restart_spec.rb +2 -4
- data/spec/cli/setup/service_spec.rb +17 -18
- data/spec/cli/setup_spec.rb +2 -4
- data/spec/cli/show_spec.rb +4 -2
- data/spec/cli/status_spec.rb +7 -5
- data/spec/cli/token_spec.rb +7 -5
- data/spec/cli/version_spec.rb +2 -0
- data/spec/cli/whoami_spec.rb +9 -7
- data/spec/client/account_spec.rb +28 -20
- data/spec/client/auto_login_spec.rb +12 -9
- data/spec/client/broadcast_spec.rb +5 -3
- data/spec/client/build_spec.rb +28 -24
- data/spec/client/commit_spec.rb +17 -14
- data/spec/client/job_spec.rb +27 -23
- data/spec/client/methods_spec.rb +8 -4
- data/spec/client/namespace_spec.rb +8 -4
- data/spec/client/repository_spec.rb +33 -30
- data/spec/client/session_spec.rb +71 -67
- data/spec/client/user_spec.rb +13 -10
- data/spec/client_spec.rb +6 -4
- data/spec/pro_spec.rb +5 -3
- data/spec/spec_helper.rb +3 -1
- data/spec/support/fake_api.rb +662 -662
- data/spec/support/fake_github.rb +6 -3
- data/spec/support/helpers.rb +13 -8
- data/spec/travis_spec.rb +5 -3
- data/travis.gemspec +402 -399
- metadata +31 -49
data/lib/travis/cli/sshkey.rb
CHANGED
@@ -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
|
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
|
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(
|
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(
|
45
|
+
ssh_key.update(value:, description: description || file)
|
44
46
|
end
|
45
47
|
|
46
48
|
def delete_key
|
47
|
-
return if interactive?
|
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
|
54
|
+
warn 'no key found to remove'
|
52
55
|
end
|
53
56
|
|
54
57
|
def generate_key
|
@@ -56,38 +59,39 @@ module Travis
|
|
56
59
|
github.with_token do |token|
|
57
60
|
access_token = github_auth(token)
|
58
61
|
end
|
59
|
-
unless access_token
|
60
|
-
|
61
|
-
end
|
62
|
+
raise Travis::Client::GitHubLoginFailed, 'all GitHub tokens given were invalid' unless access_token
|
63
|
+
|
62
64
|
gh = GH.with(token: github_token)
|
63
65
|
login = gh['user']['login']
|
64
66
|
check_access(gh)
|
65
67
|
empty_line
|
66
68
|
|
67
|
-
say
|
69
|
+
say 'Generating RSA key.'
|
68
70
|
private_key = Tools::SSLKey.generate_rsa
|
69
71
|
self.description ||= "key for fetching dependencies for #{slug} via #{login}"
|
70
72
|
|
71
|
-
say
|
72
|
-
gh.post(
|
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))
|
73
76
|
|
74
|
-
say
|
75
|
-
ssh_key.update(:
|
77
|
+
say 'Uploading private key to Travis CI.'
|
78
|
+
ssh_key.update(value: private_key.to_s, description:)
|
76
79
|
|
77
80
|
empty_line
|
78
|
-
say
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
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)
|
83
86
|
end
|
84
87
|
|
85
88
|
def remove_passphrase(value)
|
86
89
|
return value unless Tools::SSLKey.has_passphrase? value
|
87
|
-
return Tools::SSLKey.remove_passphrase(value, passphrase) || error(
|
88
|
-
|
89
|
-
|
90
|
-
|
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
|
91
95
|
empty_line
|
92
96
|
result
|
93
97
|
end
|
@@ -107,15 +111,15 @@ module Travis
|
|
107
111
|
g.github_token = github_token
|
108
112
|
g.login_header = proc { login_header }
|
109
113
|
g.debug = proc { |log| debug(log) }
|
110
|
-
g.after_tokens = proc { g.explode = true and error(
|
114
|
+
g.after_tokens = proc { g.explode = true and error('no suitable github token found') }
|
111
115
|
end
|
112
116
|
end
|
113
117
|
end
|
114
118
|
|
115
119
|
def login_header
|
116
|
-
say
|
117
|
-
say
|
118
|
-
say "Try running with #{color(
|
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)} ."
|
119
123
|
end
|
120
124
|
end
|
121
125
|
end
|
data/lib/travis/cli/status.rb
CHANGED
@@ -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
|
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?
|
15
|
-
exit 1 if fail_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
|
data/lib/travis/cli/sync.rb
CHANGED
@@ -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
|
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 "#{
|
17
|
-
elsif user.syncing?
|
18
|
-
error
|
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
|
22
|
+
say 'starting synchronization'
|
21
23
|
sync(false)
|
22
24
|
else
|
23
|
-
say
|
25
|
+
say 'synchronizing: '
|
24
26
|
sync
|
25
|
-
say color(
|
27
|
+
say color(' done', :success)
|
26
28
|
end
|
27
29
|
end
|
28
30
|
end
|
data/lib/travis/cli/token.rb
CHANGED
@@ -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
|
8
|
+
description 'outputs the secret API token'
|
7
9
|
|
8
10
|
def run
|
9
11
|
authenticate
|
10
|
-
say access_token,
|
12
|
+
say access_token, 'Your access token is %s'
|
11
13
|
end
|
12
14
|
end
|
13
15
|
end
|
data/lib/travis/cli/version.rb
CHANGED
@@ -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
|
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
|
data/lib/travis/cli/whatsup.rb
CHANGED
@@ -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
|
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
|
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
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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
|
data/lib/travis/cli/whoami.rb
CHANGED
@@ -3,12 +3,12 @@ require 'travis/cli'
|
|
3
3
|
module Travis
|
4
4
|
module CLI
|
5
5
|
class Whoami < ApiCommand
|
6
|
-
description
|
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,
|
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,58 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
begin
|
2
4
|
require 'travis/client'
|
3
5
|
rescue LoadError => e
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
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'
|
13
13
|
|
14
14
|
module Travis
|
15
15
|
module CLI
|
16
|
-
autoload :Token,
|
17
|
-
autoload :ApiCommand,
|
18
|
-
autoload :Accounts,
|
19
|
-
autoload :Branches,
|
20
|
-
autoload :Cache,
|
21
|
-
autoload :Cancel,
|
22
|
-
autoload :Command,
|
23
|
-
autoload :Console,
|
24
|
-
autoload :Disable,
|
25
|
-
autoload :Enable,
|
26
|
-
autoload :Encrypt,
|
27
|
-
autoload :EncryptFile,
|
28
|
-
autoload :Endpoint,
|
29
|
-
autoload :Env,
|
30
|
-
autoload :Help,
|
31
|
-
autoload :History,
|
32
|
-
autoload :Init,
|
33
|
-
autoload :Lint,
|
34
|
-
autoload :Login,
|
35
|
-
autoload :Logout,
|
36
|
-
autoload :Logs,
|
37
|
-
autoload :Monitor,
|
38
|
-
autoload :Open,
|
39
|
-
autoload :Parser,
|
40
|
-
autoload :Pubkey,
|
41
|
-
autoload :Raw,
|
42
|
-
autoload :
|
43
|
-
autoload :
|
44
|
-
autoload :
|
45
|
-
autoload :
|
46
|
-
autoload :
|
47
|
-
autoload :
|
48
|
-
autoload :
|
49
|
-
autoload :
|
50
|
-
autoload :
|
51
|
-
autoload :
|
52
|
-
autoload :
|
53
|
-
autoload :
|
54
|
-
autoload :
|
55
|
-
autoload :
|
16
|
+
autoload :Token, 'travis/cli/token'
|
17
|
+
autoload :ApiCommand, 'travis/cli/api_command'
|
18
|
+
autoload :Accounts, 'travis/cli/accounts'
|
19
|
+
autoload :Branches, 'travis/cli/branches'
|
20
|
+
autoload :Cache, 'travis/cli/cache'
|
21
|
+
autoload :Cancel, 'travis/cli/cancel'
|
22
|
+
autoload :Command, 'travis/cli/command'
|
23
|
+
autoload :Console, 'travis/cli/console'
|
24
|
+
autoload :Disable, 'travis/cli/disable'
|
25
|
+
autoload :Enable, 'travis/cli/enable'
|
26
|
+
autoload :Encrypt, 'travis/cli/encrypt'
|
27
|
+
autoload :EncryptFile, 'travis/cli/encrypt_file'
|
28
|
+
autoload :Endpoint, 'travis/cli/endpoint'
|
29
|
+
autoload :Env, 'travis/cli/env'
|
30
|
+
autoload :Help, 'travis/cli/help'
|
31
|
+
autoload :History, 'travis/cli/history'
|
32
|
+
autoload :Init, 'travis/cli/init'
|
33
|
+
autoload :Lint, 'travis/cli/lint'
|
34
|
+
autoload :Login, 'travis/cli/login'
|
35
|
+
autoload :Logout, 'travis/cli/logout'
|
36
|
+
autoload :Logs, 'travis/cli/logs'
|
37
|
+
autoload :Monitor, 'travis/cli/monitor'
|
38
|
+
autoload :Open, 'travis/cli/open'
|
39
|
+
autoload :Parser, 'travis/cli/parser'
|
40
|
+
autoload :Pubkey, 'travis/cli/pubkey'
|
41
|
+
autoload :Raw, 'travis/cli/raw'
|
42
|
+
autoload :RegenerateToken, 'travis/cli/regenerate_token'
|
43
|
+
autoload :RemoveToken, 'travis/cli/remove_token'
|
44
|
+
autoload :RepoCommand, 'travis/cli/repo_command'
|
45
|
+
autoload :Report, 'travis/cli/report'
|
46
|
+
autoload :Repos, 'travis/cli/repos'
|
47
|
+
autoload :Restart, 'travis/cli/restart'
|
48
|
+
autoload :Requests, 'travis/cli/requests'
|
49
|
+
autoload :Settings, 'travis/cli/settings'
|
50
|
+
autoload :Setup, 'travis/cli/setup'
|
51
|
+
autoload :Show, 'travis/cli/show'
|
52
|
+
autoload :Sshkey, 'travis/cli/sshkey'
|
53
|
+
autoload :Status, 'travis/cli/status'
|
54
|
+
autoload :Sync, 'travis/cli/sync'
|
55
|
+
autoload :Version, 'travis/cli/version'
|
56
|
+
autoload :Whatsup, 'travis/cli/whatsup'
|
57
|
+
autoload :Whoami, 'travis/cli/whoami'
|
56
58
|
|
57
59
|
extend self
|
58
60
|
|
@@ -66,11 +68,11 @@ module Travis
|
|
66
68
|
|
67
69
|
def command(name)
|
68
70
|
const_name = command_name(name)
|
69
|
-
constant = CLI.const_get(const_name) if const_name =~ /^[A-Z][A-Za-z]+$/
|
71
|
+
constant = CLI.const_get(const_name) if const_name =~ (/^[A-Z][A-Za-z]+$/) && const_defined?(const_name)
|
70
72
|
if command? constant
|
71
73
|
constant
|
72
74
|
else
|
73
|
-
|
75
|
+
warn "unknown command #{name}"
|
74
76
|
exit 1
|
75
77
|
end
|
76
78
|
end
|
@@ -80,8 +82,10 @@ module Travis
|
|
80
82
|
end
|
81
83
|
|
82
84
|
def silent
|
83
|
-
stderr
|
84
|
-
|
85
|
+
stderr = $stderr
|
86
|
+
$stderr = dummy_io
|
87
|
+
stdout = $stdout
|
88
|
+
$stdout = dummy_io
|
85
89
|
yield
|
86
90
|
ensure
|
87
91
|
$stderr = stderr if stderr
|
@@ -90,37 +94,38 @@ module Travis
|
|
90
94
|
|
91
95
|
private
|
92
96
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
+
def try_const_get(name)
|
98
|
+
CLI.const_get(name)
|
99
|
+
rescue Exception
|
100
|
+
end
|
97
101
|
|
98
|
-
|
99
|
-
|
100
|
-
File.open(IO::NULL, 'w')
|
101
|
-
end
|
102
|
+
def dummy_io
|
103
|
+
return StringIO.new unless defined? IO::NULL && IO::NULL
|
102
104
|
|
103
|
-
|
104
|
-
|
105
|
-
|
105
|
+
File.open(IO::NULL, 'w')
|
106
|
+
end
|
107
|
+
|
108
|
+
def command?(constant)
|
109
|
+
constant.is_a? Class and constant < Command and !constant.abstract?
|
110
|
+
end
|
106
111
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
end
|
112
|
+
def command_name(name)
|
113
|
+
case name
|
114
|
+
when nil, '-h', '-?' then 'Help'
|
115
|
+
when '-v' then 'Version'
|
116
|
+
when /^--/ then command_name(name[2..])
|
117
|
+
else name.split('-').map(&:capitalize).join
|
114
118
|
end
|
119
|
+
end
|
115
120
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
end
|
123
|
-
[args, opts]
|
121
|
+
# can't use flatten as it will flatten hashes
|
122
|
+
def preparse(unparsed, args = [], opts = {})
|
123
|
+
case unparsed
|
124
|
+
when Hash then opts.merge! unparsed
|
125
|
+
when Array then unparsed.each { |e| preparse(e, args, opts) }
|
126
|
+
else args << unparsed.to_s
|
124
127
|
end
|
128
|
+
[args, opts]
|
129
|
+
end
|
125
130
|
end
|
126
131
|
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(
|
37
|
+
load_attribute('repos_count') { repositories.count }
|
36
38
|
end
|
37
39
|
|
38
40
|
def repositories
|
39
|
-
attributes['repositories'] ||= session.repos(:
|
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
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
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
|
@@ -1,12 +1,13 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'travis/client'
|
3
4
|
require 'travis/tools/safe_string'
|
4
5
|
|
5
6
|
module Travis
|
6
7
|
module Client
|
7
8
|
class Artifact < Entity
|
8
|
-
CHUNKED =
|
9
|
-
TEXT = "#{CHUNKED}, text/plain"
|
9
|
+
CHUNKED = 'application/json; chunked=true; version=2, application/json; version=2'
|
10
|
+
TEXT = "#{CHUNKED}, text/plain".freeze
|
10
11
|
|
11
12
|
# @!parse attr_reader :job_id, :type, :body
|
12
13
|
attributes :job_id, :type, :body
|
@@ -15,11 +16,12 @@ module Travis
|
|
15
16
|
has :job
|
16
17
|
|
17
18
|
def delete_body(reason = {})
|
18
|
-
reason = { :
|
19
|
+
reason = { reason: } unless reason.is_a? Hash
|
19
20
|
session.patch_raw("jobs/#{job_id}/log", reason)
|
20
21
|
reload
|
21
|
-
rescue Travis::Client::Error =>
|
22
|
-
raise unless
|
22
|
+
rescue Travis::Client::Error => e
|
23
|
+
raise unless e.message == '409'
|
24
|
+
|
23
25
|
self
|
24
26
|
end
|
25
27
|
|
@@ -39,32 +41,34 @@ module Travis
|
|
39
41
|
attributes['current_body'] ||= begin
|
40
42
|
body = load_attribute('body')
|
41
43
|
if body.to_s.empty?
|
42
|
-
log = session.get_raw("jobs/#{job_id}/log", nil,
|
43
|
-
body = String
|
44
|
+
log = session.get_raw("jobs/#{job_id}/log", nil, 'Accept' => TEXT)
|
45
|
+
body = log.is_a?(String) ? log : log['log']['body']
|
44
46
|
end
|
45
47
|
body
|
46
48
|
end
|
47
49
|
end
|
48
50
|
|
49
51
|
def body(stream = block_given?)
|
50
|
-
return current_body unless block_given?
|
51
|
-
return yield(current_body) unless stream
|
52
|
+
return current_body unless block_given? || stream
|
53
|
+
return yield(current_body) unless stream && job.pending?
|
54
|
+
|
52
55
|
number = 0
|
53
56
|
|
54
57
|
session.listen(self) do |listener|
|
55
58
|
listener.on 'job:log' do |event|
|
56
59
|
next unless event.payload['number'] > number
|
60
|
+
|
57
61
|
number = event.payload['number']
|
58
62
|
yield event.payload['_log']
|
59
63
|
listener.disconnect if event.payload['final']
|
60
64
|
end
|
61
65
|
|
62
|
-
listener.on 'job:finished' do |
|
66
|
+
listener.on 'job:finished' do |_event|
|
63
67
|
listener.disconnect
|
64
68
|
end
|
65
69
|
|
66
70
|
listener.on_connect do
|
67
|
-
data = session.get_raw("/logs/#{id}", nil,
|
71
|
+
data = session.get_raw("/logs/#{id}", nil, 'Accept' => CHUNKED)['log']
|
68
72
|
if data['parts']
|
69
73
|
data['parts'].each { |p| yield p['content'] }
|
70
74
|
number = data['parts'].last['number'] if data['parts'].any?
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'travis/client'
|
2
4
|
require 'travis/tools/github'
|
3
5
|
require 'yaml'
|
@@ -12,12 +14,13 @@ module Travis
|
|
12
14
|
@session = session.session
|
13
15
|
config_path = ENV.fetch('TRAVIS_CONFIG_PATH') { File.expand_path('.travis', Dir.home) }
|
14
16
|
@config_file = options.fetch(:config_file) { File.expand_path('config.yml', config_path) }
|
15
|
-
@auto_token = options.fetch(:auto_token
|
16
|
-
@raise = options.fetch(:raise
|
17
|
+
@auto_token = options.fetch(:auto_token, true)
|
18
|
+
@raise = options.fetch(:raise, true)
|
17
19
|
end
|
18
20
|
|
19
21
|
def authenticate
|
20
|
-
return if session.access_token = cli_token
|
22
|
+
return if (session.access_token = cli_token)
|
23
|
+
|
21
24
|
github.with_token { |t| session.github_auth(t) }
|
22
25
|
end
|
23
26
|
|
@@ -25,7 +28,7 @@ module Travis
|
|
25
28
|
@github ||= Tools::Github.new(session.config['github']) do |g|
|
26
29
|
g.explode = true
|
27
30
|
g.auto_token = @auto_token
|
28
|
-
g.after_tokens = proc { raise NoTokenError,
|
31
|
+
g.after_tokens = proc { raise NoTokenError, 'no suitable github token found' } if @raise
|
29
32
|
end
|
30
33
|
end
|
31
34
|
|