travis-async-listener 1.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +22 -0
- data/README.md +2486 -0
- data/Rakefile +63 -0
- data/assets/cacert.pem +69 -0
- data/assets/init/c.yml +4 -0
- data/assets/init/clojure.yml +1 -0
- data/assets/init/cpp.yml +4 -0
- data/assets/init/erlang.yml +3 -0
- data/assets/init/go.yml +4 -0
- data/assets/init/groovy.yml +1 -0
- data/assets/init/haskell.yml +1 -0
- data/assets/init/java.yml +4 -0
- data/assets/init/node_js.yml +4 -0
- data/assets/init/objective-c.yml +1 -0
- data/assets/init/perl.yml +4 -0
- data/assets/init/php.yml +4 -0
- data/assets/init/python.yml +5 -0
- data/assets/init/ruby.yml +6 -0
- data/assets/init/scala.yml +4 -0
- data/assets/notifications/Travis CI.app/Contents/Info.plist +52 -0
- data/assets/notifications/Travis CI.app/Contents/MacOS/Travis CI +0 -0
- data/assets/notifications/Travis CI.app/Contents/PkgInfo +1 -0
- data/assets/notifications/Travis CI.app/Contents/Resources/Travis CI.icns +0 -0
- data/assets/notifications/Travis CI.app/Contents/Resources/en.lproj/Credits.rtf +29 -0
- data/assets/notifications/Travis CI.app/Contents/Resources/en.lproj/InfoPlist.strings +0 -0
- data/assets/notifications/Travis CI.app/Contents/Resources/en.lproj/MainMenu.nib +0 -0
- data/assets/notifications/Travis CI.app/Contents/_CodeSignature/CodeResources +173 -0
- data/assets/notifications/Travis CI.app/Contents/embedded.provisionprofile +0 -0
- data/assets/notifications/icon.png +0 -0
- data/assets/travis.sh +163 -0
- data/assets/travis.sh.erb +64 -0
- data/bin/travis +18 -0
- data/examples/org_overview.rb +3 -0
- data/examples/pro_auth.rb +23 -0
- data/examples/stream.rb +6 -0
- data/lib/travis.rb +8 -0
- data/lib/travis/auto_login.rb +3 -0
- data/lib/travis/cli.rb +126 -0
- data/lib/travis/cli/accounts.rb +31 -0
- data/lib/travis/cli/api_command.rb +180 -0
- data/lib/travis/cli/branches.rb +25 -0
- data/lib/travis/cli/cache.rb +76 -0
- data/lib/travis/cli/cancel.rb +18 -0
- data/lib/travis/cli/command.rb +422 -0
- data/lib/travis/cli/console.rb +31 -0
- data/lib/travis/cli/disable.rb +15 -0
- data/lib/travis/cli/enable.rb +31 -0
- data/lib/travis/cli/encrypt.rb +108 -0
- data/lib/travis/cli/encrypt_file.rb +140 -0
- data/lib/travis/cli/endpoint.rb +35 -0
- data/lib/travis/cli/env.rb +66 -0
- data/lib/travis/cli/help.rb +23 -0
- data/lib/travis/cli/history.rb +49 -0
- data/lib/travis/cli/init.rb +82 -0
- data/lib/travis/cli/lint.rb +49 -0
- data/lib/travis/cli/login.rb +76 -0
- data/lib/travis/cli/logout.rb +14 -0
- data/lib/travis/cli/logs.rb +65 -0
- data/lib/travis/cli/monitor.rb +110 -0
- data/lib/travis/cli/open.rb +39 -0
- data/lib/travis/cli/parser.rb +43 -0
- data/lib/travis/cli/pubkey.rb +30 -0
- data/lib/travis/cli/raw.rb +20 -0
- data/lib/travis/cli/repo_command.rb +154 -0
- data/lib/travis/cli/report.rb +101 -0
- data/lib/travis/cli/repos.rb +53 -0
- data/lib/travis/cli/requests.rb +47 -0
- data/lib/travis/cli/restart.rb +18 -0
- data/lib/travis/cli/settings.rb +77 -0
- data/lib/travis/cli/setup.rb +66 -0
- data/lib/travis/cli/setup/anynines.rb +21 -0
- data/lib/travis/cli/setup/appfog.rb +19 -0
- data/lib/travis/cli/setup/artifacts.rb +23 -0
- data/lib/travis/cli/setup/biicode.rb +19 -0
- data/lib/travis/cli/setup/cloud_66.rb +20 -0
- data/lib/travis/cli/setup/cloud_control.rb +21 -0
- data/lib/travis/cli/setup/cloud_files.rb +20 -0
- data/lib/travis/cli/setup/cloud_foundry.rb +23 -0
- data/lib/travis/cli/setup/code_deploy.rb +55 -0
- data/lib/travis/cli/setup/deis.rb +20 -0
- data/lib/travis/cli/setup/divshot.rb +18 -0
- data/lib/travis/cli/setup/elastic_beanstalk.rb +23 -0
- data/lib/travis/cli/setup/engine_yard.rb +24 -0
- data/lib/travis/cli/setup/gcs.rb +22 -0
- data/lib/travis/cli/setup/hackage.rb +18 -0
- data/lib/travis/cli/setup/heroku.rb +20 -0
- data/lib/travis/cli/setup/modulus.rb +18 -0
- data/lib/travis/cli/setup/ninefold.rb +20 -0
- data/lib/travis/cli/setup/nodejitsu.rb +27 -0
- data/lib/travis/cli/setup/npm.rb +20 -0
- data/lib/travis/cli/setup/open_shift.rb +20 -0
- data/lib/travis/cli/setup/opsworks.rb +22 -0
- data/lib/travis/cli/setup/pypi.rb +22 -0
- data/lib/travis/cli/setup/releases.rb +35 -0
- data/lib/travis/cli/setup/ruby_gems.rb +25 -0
- data/lib/travis/cli/setup/s3.rb +25 -0
- data/lib/travis/cli/setup/sauce_connect.rb +21 -0
- data/lib/travis/cli/setup/service.rb +73 -0
- data/lib/travis/cli/show.rb +69 -0
- data/lib/travis/cli/sshkey.rb +118 -0
- data/lib/travis/cli/status.rb +19 -0
- data/lib/travis/cli/sync.rb +30 -0
- data/lib/travis/cli/token.rb +14 -0
- data/lib/travis/cli/version.rb +17 -0
- data/lib/travis/cli/whatsup.rb +30 -0
- data/lib/travis/cli/whoami.rb +15 -0
- data/lib/travis/client.rb +39 -0
- data/lib/travis/client/account.rb +56 -0
- data/lib/travis/client/annotation.rb +21 -0
- data/lib/travis/client/artifact.rb +88 -0
- data/lib/travis/client/auto_login.rb +45 -0
- data/lib/travis/client/broadcast.rb +14 -0
- data/lib/travis/client/build.rb +47 -0
- data/lib/travis/client/cache.rb +25 -0
- data/lib/travis/client/commit.rb +28 -0
- data/lib/travis/client/entity.rb +238 -0
- data/lib/travis/client/env_var.rb +102 -0
- data/lib/travis/client/error.rb +38 -0
- data/lib/travis/client/has_uuid.rb +13 -0
- data/lib/travis/client/job.rb +61 -0
- data/lib/travis/client/lint_result.rb +25 -0
- data/lib/travis/client/listener.rb +184 -0
- data/lib/travis/client/methods.rb +104 -0
- data/lib/travis/client/namespace.rb +85 -0
- data/lib/travis/client/not_loadable.rb +13 -0
- data/lib/travis/client/repository.rb +224 -0
- data/lib/travis/client/request.rb +36 -0
- data/lib/travis/client/restartable.rb +23 -0
- data/lib/travis/client/session.rb +339 -0
- data/lib/travis/client/settings.rb +25 -0
- data/lib/travis/client/singleton_setting.rb +36 -0
- data/lib/travis/client/ssh_key.rb +11 -0
- data/lib/travis/client/states.rb +98 -0
- data/lib/travis/client/user.rb +67 -0
- data/lib/travis/client/weak_entity.rb +26 -0
- data/lib/travis/pro.rb +5 -0
- data/lib/travis/pro/auto_login.rb +3 -0
- data/lib/travis/tools/assets.rb +21 -0
- data/lib/travis/tools/completion.rb +54 -0
- data/lib/travis/tools/formatter.rb +50 -0
- data/lib/travis/tools/github.rb +279 -0
- data/lib/travis/tools/notification.rb +69 -0
- data/lib/travis/tools/safe_string.rb +22 -0
- data/lib/travis/tools/ssl_key.rb +48 -0
- data/lib/travis/tools/system.rb +88 -0
- data/lib/travis/version.rb +3 -0
- data/spec/cli/cancel_spec.rb +15 -0
- data/spec/cli/encrypt_spec.rb +43 -0
- data/spec/cli/endpoint_spec.rb +34 -0
- data/spec/cli/help_spec.rb +33 -0
- data/spec/cli/history_spec.rb +38 -0
- data/spec/cli/init_spec.rb +226 -0
- data/spec/cli/login_spec.rb +13 -0
- data/spec/cli/logs_spec.rb +8 -0
- data/spec/cli/open_spec.rb +33 -0
- data/spec/cli/repo_command_spec.rb +25 -0
- data/spec/cli/restart_spec.rb +15 -0
- data/spec/cli/setup_spec.rb +5 -0
- data/spec/cli/show_spec.rb +9 -0
- data/spec/cli/status_spec.rb +28 -0
- data/spec/cli/token_spec.rb +22 -0
- data/spec/cli/version_spec.rb +18 -0
- data/spec/cli/whoami_spec.rb +34 -0
- data/spec/client/account_spec.rb +32 -0
- data/spec/client/annotation_spec.rb +14 -0
- data/spec/client/broadcast_spec.rb +10 -0
- data/spec/client/build_spec.rb +31 -0
- data/spec/client/commit_spec.rb +22 -0
- data/spec/client/job_spec.rb +30 -0
- data/spec/client/methods_spec.rb +15 -0
- data/spec/client/namespace_spec.rb +19 -0
- data/spec/client/repository_spec.rb +39 -0
- data/spec/client/session_spec.rb +165 -0
- data/spec/client/user_spec.rb +16 -0
- data/spec/client_spec.rb +17 -0
- data/spec/pro_spec.rb +10 -0
- data/spec/spec_helper.rb +29 -0
- data/spec/support/fake_api.rb +738 -0
- data/spec/support/fake_github.rb +24 -0
- data/spec/support/helpers.rb +45 -0
- data/spec/travis_spec.rb +10 -0
- data/travis.gemspec +323 -0
- metadata +489 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
require 'travis/cli'
|
|
2
|
+
|
|
3
|
+
module Travis
|
|
4
|
+
module CLI
|
|
5
|
+
class History < RepoCommand
|
|
6
|
+
description "displays a projects build history"
|
|
7
|
+
|
|
8
|
+
on('-a', '--after BUILD', 'Only show history after a given build number')
|
|
9
|
+
on('-p', '--pull-request NUMBER', 'Only show history for the given Pull Request')
|
|
10
|
+
on('-b', '--branch BRANCH', 'Only show history for the given branch')
|
|
11
|
+
on('-l', '--limit LIMIT', 'Maximum number of history items')
|
|
12
|
+
on('-d', '--date', 'Include date in output')
|
|
13
|
+
on('-c', '--committer', 'Include committer in output')
|
|
14
|
+
on('--[no-]all', 'Display all history items')
|
|
15
|
+
|
|
16
|
+
def run
|
|
17
|
+
countdown = Integer(limit || 10) unless all?
|
|
18
|
+
params = { :after_number => after } if after
|
|
19
|
+
repository.each_build(params) do |build|
|
|
20
|
+
next unless display? build
|
|
21
|
+
display(build)
|
|
22
|
+
|
|
23
|
+
if countdown
|
|
24
|
+
countdown -= 1
|
|
25
|
+
break if countdown < 1
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
private
|
|
31
|
+
|
|
32
|
+
def display?(build)
|
|
33
|
+
return build.pr_number == pull_request if pull_request
|
|
34
|
+
return build.branch_info == branch if branch
|
|
35
|
+
true
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def display(build)
|
|
39
|
+
say [
|
|
40
|
+
date? && color(formatter.time(build.finished_at || build.started_at), build.color),
|
|
41
|
+
color("##{build.number} #{build.state}:".ljust(16), [build.color, :bold]),
|
|
42
|
+
color("#{build.branch_info}", :info),
|
|
43
|
+
committer? && build.commit.author_name.ljust(25),
|
|
44
|
+
build.commit.subject
|
|
45
|
+
].compact.join(" ").strip + "\n"
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
require 'travis/cli'
|
|
2
|
+
|
|
3
|
+
module Travis
|
|
4
|
+
module CLI
|
|
5
|
+
class Init < Enable
|
|
6
|
+
LANGUAGE_MAPPING = {
|
|
7
|
+
"node" => "node_js",
|
|
8
|
+
"node.js" => "node_js",
|
|
9
|
+
"javascript" => "node_js",
|
|
10
|
+
"coffeescript" => "node_js",
|
|
11
|
+
"c++" => "cpp",
|
|
12
|
+
"obj-c" => "objective-c"
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
description "generates a .travis.yml and enables the project"
|
|
16
|
+
|
|
17
|
+
on('-f', '--force', 'override .travis.yml if it already exists')
|
|
18
|
+
on('-k', '--skip-enable', 'do not enable project, only add .travis.yml')
|
|
19
|
+
on('-p', '--print-conf', 'print generated config instead of writing to file')
|
|
20
|
+
|
|
21
|
+
options = %w[
|
|
22
|
+
script before_script after_script after_success install before_install
|
|
23
|
+
compiler otp_release go jdk node_js perl php python rvm scala
|
|
24
|
+
env gemfile
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
options.each do |option|
|
|
28
|
+
on "--#{option.gsub('_', '-')} VALUE", "sets #{option} option in .travis.yml (can be used more than once)" do |c, value|
|
|
29
|
+
c.custom_config[option] &&= Array(c.custom_config[option]) << value
|
|
30
|
+
c.custom_config[option] ||= value
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
attr_writer :travis_config
|
|
35
|
+
|
|
36
|
+
def self.languages
|
|
37
|
+
Dir[asset_path('init/*.yml')].map { |f| File.basename(f, '.yml') }.sort
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def help
|
|
41
|
+
super("Available languages: #{self.class.languages.join(", ")}\n\n")
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def run(language = nil, file = '.travis.yml')
|
|
45
|
+
error "#{file} already exists, use --force to override" if File.exist?(file) and not force? and not print_conf?
|
|
46
|
+
language ||= ask('Main programming language used: ') { |q| q.default = detect_language }
|
|
47
|
+
self.travis_config = template(language).merge(custom_config)
|
|
48
|
+
|
|
49
|
+
if print_conf?
|
|
50
|
+
puts travis_config.to_yaml
|
|
51
|
+
else
|
|
52
|
+
save_travis_config(file)
|
|
53
|
+
say("#{file} file created!")
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
super() unless skip_enable?
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def custom_config
|
|
60
|
+
@custom_config ||= {}
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
private
|
|
64
|
+
|
|
65
|
+
def template_name(language)
|
|
66
|
+
asset_path "init/#{language}.yml"
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def template(language)
|
|
70
|
+
language = language.to_s.downcase
|
|
71
|
+
language = LANGUAGE_MAPPING[language] || language
|
|
72
|
+
file = template_name(language)
|
|
73
|
+
error "unknown language #{language}" unless File.exist? file
|
|
74
|
+
YAML.load_file(file)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def detect_language
|
|
78
|
+
repository.github_language || "Ruby"
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
require 'travis/cli'
|
|
2
|
+
|
|
3
|
+
module Travis
|
|
4
|
+
module CLI
|
|
5
|
+
class Lint < ApiCommand
|
|
6
|
+
description 'display warnings for a .travis.yml'
|
|
7
|
+
on '-q', '--[no-]quiet', 'does not print anything'
|
|
8
|
+
on '-x', '--[no-]exit-code', 'sets the exit code to 1 if there are warning'
|
|
9
|
+
|
|
10
|
+
def run(file = nil)
|
|
11
|
+
file ||= '.travis.yml' if $stdin.tty? or $stdin.eof?
|
|
12
|
+
|
|
13
|
+
if file and file != '-'
|
|
14
|
+
debug "reading #{file}"
|
|
15
|
+
error "file does not exist: #{color(file, :bold)}" unless File.exist? file
|
|
16
|
+
error "cannot read #{color(file, :bold)}" unless File.readable? file
|
|
17
|
+
content = File.read(file)
|
|
18
|
+
else
|
|
19
|
+
debug "reading stdin"
|
|
20
|
+
file = 'STDIN'
|
|
21
|
+
content = $stdin.read
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
lint = session.lint(content)
|
|
25
|
+
|
|
26
|
+
unless quiet?
|
|
27
|
+
if lint.ok?
|
|
28
|
+
say "valid", color("Hooray, #{file} looks %s :)", :success)
|
|
29
|
+
else
|
|
30
|
+
say "Warnings for #{color(file, :info)}:"
|
|
31
|
+
lint.warnings.each do |warning|
|
|
32
|
+
say color('[x]', [:red, :bold]) + " "
|
|
33
|
+
if warning.key.any?
|
|
34
|
+
say [
|
|
35
|
+
color('in ', :info),
|
|
36
|
+
color(warning.key.join('.'), [:info, :bold, :underline]),
|
|
37
|
+
color(' section:', :info), ' '
|
|
38
|
+
].join
|
|
39
|
+
end
|
|
40
|
+
say warning.message.gsub(/"(.*?)"/) { color($1, [:info, :important]) }
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
exit 1 if lint.warnings? and exit_code?
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
require 'travis/cli'
|
|
2
|
+
require 'travis/tools/github'
|
|
3
|
+
require 'json'
|
|
4
|
+
|
|
5
|
+
module Travis
|
|
6
|
+
module CLI
|
|
7
|
+
class Login < ApiCommand
|
|
8
|
+
skip :authenticate
|
|
9
|
+
|
|
10
|
+
description "authenticates against the API and stores the token"
|
|
11
|
+
on('-g', '--github-token TOKEN', 'identify by GitHub token')
|
|
12
|
+
on('-T', '--auto-token', 'try to figure out who you are automatically (might send another apps token to Travis, token will not be stored)')
|
|
13
|
+
on('-p', '--auto-password', 'try to load password from OSX keychain (will not be stored)')
|
|
14
|
+
on('-a', '--auto', 'shorthand for --auto-token --auto-password') { |c| c.auto_token = c.auto_password = true }
|
|
15
|
+
on('-u', '--user LOGIN', 'user to log in as') { |c,n| c.user_login = n }
|
|
16
|
+
on('-M', '--no-manual', 'do not use interactive login')
|
|
17
|
+
on('--list-github-token', 'instead of actually logging in, list found GitHub tokens')
|
|
18
|
+
on('--skip-token-check', 'don\'t verify the token with github')
|
|
19
|
+
|
|
20
|
+
attr_accessor :user_login
|
|
21
|
+
|
|
22
|
+
def list_token
|
|
23
|
+
github.after_tokens = proc { }
|
|
24
|
+
github.each_token do |token|
|
|
25
|
+
say token
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def login
|
|
30
|
+
session.access_token = nil
|
|
31
|
+
github.with_token do |token|
|
|
32
|
+
endpoint_config['access_token'] = github_auth(token)
|
|
33
|
+
error("user mismatch: logged in as %p instead of %p" % [user.login, user_login]) if user_login and user.login != user_login
|
|
34
|
+
error("#{user.login} has not granted Travis CI the required permissions, please log in via #{session.config['host']}") unless user.correct_scopes?
|
|
35
|
+
success("Successfully logged in as #{user.login}!")
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def run
|
|
40
|
+
list_github_token ? list_token : login
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def github
|
|
44
|
+
@github ||= begin
|
|
45
|
+
load_gh
|
|
46
|
+
Tools::Github.new(session.config['github']) do |g|
|
|
47
|
+
g.note = "temporary token to identify with the travis command line client against #{api_endpoint}"
|
|
48
|
+
g.manual_login = no_manual.nil?
|
|
49
|
+
g.explode = explode?
|
|
50
|
+
g.github_token = github_token
|
|
51
|
+
g.auto_token = auto_token
|
|
52
|
+
g.auto_password = auto_password
|
|
53
|
+
g.github_login = user_login
|
|
54
|
+
g.check_token = !skip_token_check?
|
|
55
|
+
g.drop_token = true
|
|
56
|
+
g.ask_login = proc { ask("Username: ") }
|
|
57
|
+
g.ask_password = proc { |user| ask("Password for #{user}: ") { |q| q.echo = "*" } }
|
|
58
|
+
g.ask_otp = proc { |user| ask("Two-factor authentication code for #{user}: ") }
|
|
59
|
+
g.login_header = proc { login_header }
|
|
60
|
+
g.debug = proc { |log| debug(log) }
|
|
61
|
+
g.after_tokens = proc { g.explode = true and error("no suitable github token found") }
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def login_header
|
|
67
|
+
say "We need your #{color("GitHub login", :important)} to identify you."
|
|
68
|
+
say "This information will #{color("not be sent to Travis CI", :important)}, only to #{color(github_endpoint.host, :info)}."
|
|
69
|
+
say "The password will not be displayed."
|
|
70
|
+
empty_line
|
|
71
|
+
say "Try running with #{color("--github-token", :info)} or #{color("--auto", :info)} if you don't want to enter your password anyway."
|
|
72
|
+
empty_line
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
require 'travis/cli'
|
|
2
|
+
require 'travis/tools/safe_string'
|
|
3
|
+
require 'travis/tools/system'
|
|
4
|
+
|
|
5
|
+
module Travis
|
|
6
|
+
module CLI
|
|
7
|
+
class Logs < RepoCommand
|
|
8
|
+
attr_accessor :delete, :reason
|
|
9
|
+
description "streams test logs"
|
|
10
|
+
on('-d', '--delete [REASON]', 'remove logs') { |c, reason| c.delete, c.reason = true, reason }
|
|
11
|
+
on('-f', '--force', 'do not ask user to confirm deleting the logs')
|
|
12
|
+
on('--[no-]stream', 'only print current logs, do not stream')
|
|
13
|
+
|
|
14
|
+
def setup
|
|
15
|
+
super
|
|
16
|
+
check_websocket
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
include Tools::SafeString
|
|
20
|
+
def run(number = last_build.number)
|
|
21
|
+
self.stream = true if stream.nil?
|
|
22
|
+
job ||= job(number) || error("no such job ##{number}")
|
|
23
|
+
delete ? delete_log(job) : display_log(job)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def delete_log(job)
|
|
27
|
+
unless force?
|
|
28
|
+
error "not deleting logs without --force" unless interactive?
|
|
29
|
+
error "aborted" unless danger_zone? "Do you really want to delete the build log for #{color(job.inspect_info, :underline)}?"
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
warn "deleting log for #{color(job.inspect_info, [:bold, :info])}"
|
|
33
|
+
job.delete_log(reason || {})
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def display_log(job)
|
|
37
|
+
info "displaying logs for #{color(job.inspect_info, [:bold, :info])}"
|
|
38
|
+
return print_log(job.log.body) unless stream?
|
|
39
|
+
job.log.body { |part| print_log(part) }
|
|
40
|
+
ensure
|
|
41
|
+
print "\e[0m" if interactive?
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def print_log(part)
|
|
45
|
+
print interactive? ? encoded(part) : clean(part)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
private
|
|
49
|
+
|
|
50
|
+
def job(number)
|
|
51
|
+
number = last_build.number + number if number.start_with? '.'
|
|
52
|
+
job = super(number) || build(number) || branch(number)
|
|
53
|
+
job = job.jobs.first if job.respond_to? :jobs
|
|
54
|
+
job
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def check_websocket
|
|
58
|
+
require 'websocket-native' if stream?
|
|
59
|
+
rescue LoadError => e
|
|
60
|
+
raise e if e.respond_to?(:path) and e.path != 'websocket-native'
|
|
61
|
+
info "speed up log streaming by installing the websocket-native gem"
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
require 'travis/cli'
|
|
2
|
+
require 'travis/tools/notification'
|
|
3
|
+
|
|
4
|
+
module Travis
|
|
5
|
+
module CLI
|
|
6
|
+
class Monitor < ApiCommand
|
|
7
|
+
description "live monitor for what's going on"
|
|
8
|
+
on('-m', '--my-repos', 'Only monitor my own repositories')
|
|
9
|
+
|
|
10
|
+
on('-r', '--repo SLUG', 'monitor given repository (can be used more than once)') do |c, slug|
|
|
11
|
+
c.repos << slug
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
types = Tools::Notification::DEFAULT.map(&:to_s).join(", ")
|
|
15
|
+
on('-n', '--[no-]notify [TYPE]', "send out desktop notifications (optional type: #{types})") do |c, type|
|
|
16
|
+
c.setup_notification(type)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
on('-b', '--builds', 'only monitor builds, not jobs')
|
|
20
|
+
on('-p', '--push', 'monitor push events')
|
|
21
|
+
on('-P', '--pull', 'monitor pull request events')
|
|
22
|
+
|
|
23
|
+
attr_reader :repos, :notification
|
|
24
|
+
|
|
25
|
+
def initialize(*)
|
|
26
|
+
@repos = []
|
|
27
|
+
super
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def setup
|
|
31
|
+
super
|
|
32
|
+
repos.map! { |r| repo(r) }
|
|
33
|
+
repos.concat(user.repositories) if my_repos?
|
|
34
|
+
setup_notification(!firehose? || :dummy) unless notification
|
|
35
|
+
debug "Using notifications: #{notification.class.name[/[^:]+$/]}"
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def setup_notification(type = nil)
|
|
39
|
+
refuse = false
|
|
40
|
+
case type
|
|
41
|
+
when false then @notification = Tools::Notification.new(:dummy)
|
|
42
|
+
when nil, true then @notification = Tools::Notification.new
|
|
43
|
+
else
|
|
44
|
+
refuse = true
|
|
45
|
+
@notification = Tools::Notification.new(type)
|
|
46
|
+
end
|
|
47
|
+
rescue ArgumentError => e
|
|
48
|
+
@notification = Tools::Notification.new(:dummy)
|
|
49
|
+
error(e.message) if refuse
|
|
50
|
+
warn(e.message)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def description
|
|
54
|
+
case repos.size
|
|
55
|
+
when 0 then session.config['host']
|
|
56
|
+
when 1 then repos.first.slug
|
|
57
|
+
else "#{repos.size} repositories"
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def events
|
|
62
|
+
events = %w[build:started build:finished]
|
|
63
|
+
events << 'job:started' << 'job:finished' unless builds?
|
|
64
|
+
events
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def firehose?
|
|
68
|
+
org? and repos.empty?
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def all?
|
|
72
|
+
!pull? and !push?
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def monitor?(entity)
|
|
76
|
+
return true if all?
|
|
77
|
+
entity.pull_request? ? pull? : push?
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def display(entity, time)
|
|
81
|
+
say [
|
|
82
|
+
color(formatter.time(time), entity.color),
|
|
83
|
+
color(entity.inspect_info, [entity.color, :bold]),
|
|
84
|
+
color(entity.state, entity.color)
|
|
85
|
+
].join(" ")
|
|
86
|
+
notification.notify(entity.repository.slug, [
|
|
87
|
+
entity.class.name[/[^:]+$/],
|
|
88
|
+
entity.number,
|
|
89
|
+
entity.state + ":",
|
|
90
|
+
entity.commit.subject
|
|
91
|
+
].join(" "))
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def handle_event(event)
|
|
95
|
+
entity = event.job || event.build
|
|
96
|
+
time = entity.finished_at || entity.started_at
|
|
97
|
+
display(entity, time) if monitor? entity
|
|
98
|
+
rescue Travis::Client::Error => error
|
|
99
|
+
raise error if explode?
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def run
|
|
103
|
+
listen(*repos) do |listener|
|
|
104
|
+
listener.on_connect { say description, "Monitoring #{"builds for " if builds?}%s:" }
|
|
105
|
+
listener.on(*events) { |e| handle_event(e) }
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|