travis 1.1.3 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -38,6 +38,7 @@ The [travis gem](https://rubygems.org/gems/travis) includes both a command line
38
38
  * [Artifacts](#artifacts)
39
39
  * [Users](#users)
40
40
  * [Commits](#commits)
41
+ * [Workers](#workers)
41
42
  * [Dealing with Sessions](#dealing-with-sessions)
42
43
  * [Using Namespaces](#using-namespaces)
43
44
  * [Installation](#installation)
@@ -89,6 +90,7 @@ Additionally, every API command understands the following options:
89
90
  --org short-cut for --api-endpoint 'https://api.travis-ci.org/'
90
91
  -t, --token [ACCESS_TOKEN] access token to use
91
92
  --debug show API requests
93
+ --adapter ADAPTER Faraday adapter to use for HTTP requests
92
94
 
93
95
  By default, [General API Commands](#general-api-commands) will talk to [api.travis-ci.org](https://api.travis-ci.org). You can change this by supplying `--pro` for [api.travis-ci.com](https://api.travis-ci.com) or `--api-endpoint` with your own endpoint. Note that all [Repository Commands](#repository-commands) will try to figure out the API endpoint to talk to automatically depending on the project's visibility on GitHub.
94
96
 
@@ -96,6 +98,15 @@ You can supply an access token via `--token` if you want to make an authenticate
96
98
 
97
99
  The `--debug` option will print HTTP requests to STDERR. Like `--explode`, this is really helpful when contributing to this project.
98
100
 
101
+ There are many libraries out there to do HTTP requests in Ruby. You can switch amongst common ones with `--adapter`:
102
+
103
+ $ travis show --adapter net-http
104
+ ...
105
+ $ gem install excon
106
+ ...
107
+ $ travis show --adapter excon
108
+ ...
109
+
99
110
  #### `console`
100
111
 
101
112
  Running `travis console` gives you an interactive Ruby session with all the [entities](#entities) imported into global namespace.
@@ -770,6 +781,19 @@ commit = repo.last_build.commit
770
781
  puts "Last tested commit: #{commit.short_sha} on #{commit.branch} by #{commit.author_name} - #{commit.subject}"
771
782
  ```
772
783
 
784
+ #### Workers
785
+
786
+ If a worker is running something, it will reference a `job` and a `repository`. Otherwise the values will be `nil`.
787
+
788
+ ``` ruby
789
+ require 'travis'
790
+ workers = Travis::Worker.find_all
791
+
792
+ workers.each do |worker|
793
+ puts "#{worker.name}: #{worker.host} - #{worker.state} - #{worker.repository.slug if worker.repository}"
794
+ end
795
+ ```
796
+
773
797
  ### Dealing with Sessions
774
798
 
775
799
  Under the hood the session is where the fun is happening. Most methods on the constants and entities just wrap methods on your session, so you don't have to pass the session around all the time or even see it if you don't want to.
@@ -832,7 +856,7 @@ session.clear_cache! # empty identity map
832
856
 
833
857
  ``` ruby
834
858
  require 'travis/client'
835
- MyTravis = Travis::Namespaces.new("http://localhost:3000")
859
+ MyTravis = Travis::Client::Namespaces.new("http://localhost:3000")
836
860
 
837
861
  MyTravis.access_token = "..."
838
862
  MyTravis::Repository.find("foo/bar")
@@ -844,7 +868,7 @@ Since namespaces are Modules, you can also include them.
844
868
  require 'travis/client'
845
869
 
846
870
  class MyTravis
847
- include Travis::Namespaces.new
871
+ include Travis::Client::Namespaces.new
848
872
  end
849
873
 
850
874
  MyTravis::Repository.find('rails/rails')
@@ -862,6 +886,18 @@ If you have the old `travis-cli` gem installed, you should `gem uninstall travis
862
886
 
863
887
  ## Version History
864
888
 
889
+ **Not yet released**
890
+
891
+ * add `--adapter` to API endpoints
892
+ * added branch to `show`
893
+ * fix bug where colors were not used if stdin is a pipe
894
+ * make `encrypt` options `--split` and `--add` work together properly
895
+ * better handling of missing or empty `.travis.yml` when running `encrypt --add`
896
+ * fix broken example code
897
+ * no longer require network connection to automatically detect repository slug
898
+ * add worker support to the ruby library
899
+ * adjust artifacts/logs code to upstream api changes
900
+
865
901
  **v1.1.3** (January 26, 2013)
866
902
 
867
903
  * use persistent HTTP connections (performance for commands with multiple api requests)
@@ -22,6 +22,13 @@ module Travis
22
22
  end
23
23
  end
24
24
 
25
+ on('--adapter ADAPTER', 'Faraday adapter to use for HTTP requests') do |c, adapter|
26
+ adapter.gsub! '-', '_'
27
+ require "faraday/adapter/#{adapter}"
28
+ require 'typhoeus/adapters/faraday' if adapter == 'typhoeus'
29
+ c.session.faraday_adapter = adapter.to_sym
30
+ end
31
+
25
32
  def initialize(*)
26
33
  @session = Travis::Client.new
27
34
  super
@@ -12,7 +12,7 @@ module Travis
12
12
  extend Forwardable
13
13
  def_delegators :terminal, :agree, :ask, :choose
14
14
 
15
- HighLine.use_color = !CLI.windows? && $stdin.tty?
15
+ HighLine.use_color = !CLI.windows? && $stdout.tty?
16
16
  HighLine.color_scheme = HighLine::ColorScheme.new do |cs|
17
17
  cs[:command] = [ :bold ]
18
18
  cs[:error] = [ :red ]
@@ -33,11 +33,13 @@ module Travis
33
33
 
34
34
  if config_key
35
35
  travis_config = YAML.load_file(travis_yaml)
36
+ travis_config = {} if [[], false, nil].include? travis_config
36
37
  keys = config_key.split('.')
37
38
  last_key = keys.pop
38
39
  nested_config = keys.inject(travis_config) { |c,k| c[k] ||= {}}
40
+ nested_config = nested_config[last_key] ||= []
39
41
  encrypted.each do |encrypted|
40
- nested_config[last_key] ||= [] << { 'secure' => encrypted }
42
+ nested_config << { 'secure' => encrypted }
41
43
  end
42
44
  File.write(travis_yaml, travis_config.to_yaml)
43
45
  else
@@ -54,7 +56,8 @@ module Travis
54
56
  path
55
57
  else
56
58
  parent = File.expand_path('..', dir)
57
- travis_yaml(parent) if parent != dir
59
+ error "no .travis.yml found" if parent == dir
60
+ travis_yaml(parent)
58
61
  end
59
62
  end
60
63
  end
@@ -3,7 +3,7 @@ require 'travis/cli'
3
3
  module Travis
4
4
  module CLI
5
5
  class RepoCommand < ApiCommand
6
- GIT_REGEX = %r{Fetch URL: (?:https://|git://|git@)github\.com[:/](.*/.+?)(\.git)?$}
6
+ GIT_REGEX = %r{^(?:https://|git://|git@)github\.com[:/](.*/.+?)(\.git)?$}
7
7
  on('-r', '--repo SLUG') { |c, slug| c.slug = slug }
8
8
 
9
9
  attr_accessor :slug
@@ -43,7 +43,7 @@ module Travis
43
43
  end
44
44
 
45
45
  def find_slug
46
- git_info = `git remote show origin 2>&1`
46
+ git_info = `git config --get remote.origin.url 2>&1`
47
47
  $1 if git_info =~ GIT_REGEX
48
48
  end
49
49
 
@@ -5,6 +5,7 @@ module Travis
5
5
  class Show < RepoCommand
6
6
  def run(number = last_build.number)
7
7
  entity = job(number) || build(number)
8
+ error "unknown build or job #{number}" unless entity
8
9
 
9
10
  say template(__FILE__) % [
10
11
  entity.class.one.capitalize,
@@ -13,6 +14,7 @@ module Travis
13
14
  entity.state,
14
15
  entity.color,
15
16
  entity.pull_request? ? "pull request" : "push",
17
+ entity.branch_info,
16
18
  entity.commit.compare_url,
17
19
  formatter.duration(entity.duration),
18
20
  formatter.time(entity.started_at),
@@ -44,6 +46,7 @@ __END__
44
46
  <[[ color("%s #%s: %s", :bold) ]]>
45
47
  <[[ color("State: ", :info) ]]><[[ color(%p, :%s) ]]>
46
48
  <[[ color("Type: ", :info) ]]>%s
49
+ <[[ color("Branch: ", :info) ]]>%s
47
50
  <[[ color("Compare URL: ", :info) ]]>%s
48
51
  <[[ color("Duration: ", :info) ]]>%s
49
52
  <[[ color("Started: ", :info) ]]>%s
data/lib/travis/client.rb CHANGED
@@ -10,6 +10,7 @@ require 'travis/client/build'
10
10
  require 'travis/client/artifact'
11
11
  require 'travis/client/commit'
12
12
  require 'travis/client/job'
13
+ require 'travis/client/worker'
13
14
  require 'travis/client/namespace'
14
15
 
15
16
  module Travis
@@ -17,9 +17,9 @@ module Travis
17
17
  attributes['clean_body'] ||= colorized_body.gsub(/\e[^m]+m/, '')
18
18
  end
19
19
 
20
- one :artifact
21
- many :artifacts
22
- aka :log
20
+ one :log
21
+ many :logs
22
+ aka :artifact
23
23
  end
24
24
  end
25
25
  end
@@ -69,10 +69,14 @@ module Travis
69
69
  private(:inspect_info)
70
70
  end
71
71
 
72
+ def self.cast_id(id)
73
+ Integer(id)
74
+ end
75
+
72
76
  def initialize(session, id)
73
77
  @attributes = {}
74
78
  @session = session
75
- @id = Integer(id)
79
+ @id = self.class.cast_id(id)
76
80
  end
77
81
 
78
82
  def update_attributes(data)
@@ -29,6 +29,10 @@ module Travis
29
29
  build.push?
30
30
  end
31
31
 
32
+ def branch_info
33
+ build.branch_info
34
+ end
35
+
32
36
  def allow_failures?
33
37
  return false unless config.include? 'matrix' and config['matrix'].include? 'allow_failures'
34
38
  config['matrix']['allow_failures'].any? do |allow|
@@ -37,6 +37,14 @@ module Travis
37
37
  session.find_one(Repository, id_or_slug)
38
38
  end
39
39
 
40
+ def worker(id)
41
+ session.find_one(Worker, id)
42
+ end
43
+
44
+ def workers(params = {})
45
+ session.find_many(Worker, params)
46
+ end
47
+
40
48
  def build(id)
41
49
  session.find_one(Build, id)
42
50
  end
@@ -38,7 +38,6 @@ module Travis
38
38
  end
39
39
  end
40
40
 
41
-
42
41
  include Methods
43
42
  attr_accessor :session
44
43
 
@@ -104,7 +104,7 @@ module Travis
104
104
  build_number = number.to_s[/^\d+/]
105
105
  build = build(build_number)
106
106
  job = build.jobs.detect { |j| j.number == number } if number != build_number
107
- job ||= build.jobs.first if build.jobs.size == 1
107
+ job ||= build.jobs.first if build and build.jobs.size == 1
108
108
  job
109
109
  end
110
110
 
@@ -1,7 +1,6 @@
1
1
  require 'travis/client'
2
2
 
3
3
  require 'faraday'
4
- require 'faraday/adapter/net_http_persistent'
5
4
  require 'faraday_middleware'
6
5
  require 'json'
7
6
 
@@ -10,13 +9,14 @@ module Travis
10
9
  class Session
11
10
  SSL_OPTIONS = { :ca_file => File.expand_path("../../cacert.pem", __FILE__) }
12
11
  include Methods
13
- attr_reader :connection, :headers, :access_token, :instruments
12
+ attr_reader :connection, :headers, :access_token, :instruments, :faraday_adapter
14
13
 
15
14
  def initialize(options = Travis::Client::ORG_URI)
16
- @headers = {}
17
- @cache = {}
18
- @instruments = []
19
- @config = nil
15
+ @headers = {}
16
+ @cache = {}
17
+ @instruments = []
18
+ @config = nil
19
+ @faraday_adapter = :net_http_persistent
20
20
 
21
21
  options = { :uri => options } unless options.respond_to? :each_pair
22
22
  options.each_pair { |key, value| public_send("#{key}=", value) }
@@ -40,6 +40,11 @@ module Travis
40
40
  end
41
41
  end
42
42
 
43
+ def faraday_adapter=(adapter)
44
+ @faraday_adapter = adapter
45
+ self.uri &&= uri
46
+ end
47
+
43
48
  def access_token=(token)
44
49
  clear_cache!
45
50
  @access_token = token
@@ -104,9 +109,9 @@ module Travis
104
109
  @config ||= get_raw('/config')['config']
105
110
  end
106
111
 
107
- def get(*args)
112
+ def load(data)
108
113
  result = {}
109
- get_raw(*args).each_pair do |key, value|
114
+ (data || {}).each_pair do |key, value|
110
115
  type = Entity.subclass_for(key)
111
116
  if value.respond_to? :to_ary
112
117
  result[key] = value.to_ary.map { |e| create_entity(type, e) }
@@ -117,6 +122,10 @@ module Travis
117
122
  result
118
123
  end
119
124
 
125
+ def get(*args)
126
+ load get_raw(*args)
127
+ end
128
+
120
129
  def get_raw(*args)
121
130
  raw(:get, *args)
122
131
  end
@@ -171,7 +180,7 @@ module Travis
171
180
  end
172
181
 
173
182
  def create_entity(type, data)
174
- id = Integer(data.fetch('id'))
183
+ id = type.cast_id(data.fetch('id'))
175
184
  entity = cached(type, :id, id) { type.new(self, id) }
176
185
  entity.update_attributes(data)
177
186
  entity
@@ -184,10 +193,6 @@ module Travis
184
193
  raise klass, message, e.backtrace
185
194
  end
186
195
 
187
- def faraday_adapter
188
- :net_http_persistent #Faraday.default_adapter
189
- end
190
-
191
196
  def reset_entities
192
197
  subcaches do |subcache|
193
198
  subcache[:id].each_value { |e| e.attributes.clear } if subcache.include? :id
@@ -3,7 +3,11 @@ require 'travis/client'
3
3
  module Travis
4
4
  module Client
5
5
  module States
6
- STATES = %w[created queued started passed failed errored canceled]
6
+ STATES = %w[created queued started passed failed errored canceled ready]
7
+
8
+ def ready?
9
+ state == 'ready'
10
+ end
7
11
 
8
12
  def pending?
9
13
  check_state
@@ -54,7 +58,11 @@ module Travis
54
58
  end
55
59
 
56
60
  def color
57
- pending? ? 'yellow' : passed? ? 'green' : 'red'
61
+ case state
62
+ when 'created', 'queued', 'started' then 'yellow'
63
+ when 'passed', 'ready' then 'green'
64
+ when 'errored', 'canceled', 'failed' then 'red'
65
+ end
58
66
  end
59
67
 
60
68
  def yellow?
@@ -0,0 +1,32 @@
1
+ require 'travis/client'
2
+
3
+ module Travis
4
+ module Client
5
+ class Worker < Entity
6
+ include States
7
+
8
+ def self.cast_id(id)
9
+ String(id)
10
+ end
11
+
12
+ # @!parse attr_reader :name, :host, :state, :payload
13
+ attributes :name, :host, :state, :payload
14
+ inspect_info :name
15
+
16
+ one :worker
17
+ many :workers
18
+
19
+ def payload=(value)
20
+ set_attribute(:payload, session.load(value))
21
+ end
22
+
23
+ def repository
24
+ payload['repo']
25
+ end
26
+
27
+ def job
28
+ payload['job']
29
+ end
30
+ end
31
+ end
32
+ end
@@ -1,3 +1,3 @@
1
1
  module Travis
2
- VERSION = '1.1.3'
2
+ VERSION = '1.2.0'
3
3
  end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe Travis::CLI::Show do
4
4
  example 'show 6180.1' do
5
- run_cli('show', '6180.1').should be_success
5
+ run_cli('show', '6180.1', '-E').should be_success
6
6
  stdout.should include("Config: ")
7
7
  stdout.should include("env: GEM=railties")
8
8
  end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe Travis::Client::Worker do
4
+ let(:session) { Travis::Client.new }
5
+ subject { session.workers.first }
6
+
7
+ its(:id) { should be == 'foo' }
8
+ its(:name) { should be == 'ruby-1' }
9
+ its(:host) { should be == 'ruby-1.worker.travis-ci.org' }
10
+ its(:state) { should be == 'ready' }
11
+ its(:color) { should be == 'green' }
12
+ its(:job) { should be_a(Travis::Client::Job) }
13
+ its(:repository) { should be_a(Travis::Client::Repository) }
14
+
15
+ it { should be_ready }
16
+
17
+ describe 'without payload' do
18
+ subject { session.worker('foo') }
19
+ its(:payload) { should be == {}}
20
+ its(:job) { should be_nil }
21
+ its(:repository) { should be_nil }
22
+ end
23
+ end
@@ -647,8 +647,8 @@ module Travis
647
647
  {"config" => {"host" => "travis-ci.org"}}.to_json
648
648
  end
649
649
 
650
- get '/artifacts/3168318' do
651
- {"artifact"=>
650
+ get '/logs/3168318' do
651
+ {"log"=>
652
652
  {"id"=>3168318,
653
653
  "job_id"=>4125096,
654
654
  "type"=>"Log",
@@ -685,6 +685,26 @@ module Travis
685
685
  {"key"=>RAILS_KEY}.to_json
686
686
  end
687
687
 
688
+ get '/workers/' do
689
+ {"workers"=>
690
+ [{'id' => 'foo',
691
+ 'name' => 'ruby-1',
692
+ 'host' => 'ruby-1.worker.travis-ci.org',
693
+ 'state' => 'ready',
694
+ 'payload' => {
695
+ "job"=>{"id"=>4125096},
696
+ "repo"=>{"id"=>891}}}]}.to_json
697
+ end
698
+
699
+ get '/workers/foo' do
700
+ {"worker"=>
701
+ {'id' => 'foo',
702
+ 'name' => 'ruby-1',
703
+ 'host' => 'ruby-1.worker.travis-ci.org',
704
+ 'state' => 'ready',
705
+ 'payload' => nil}}.to_json
706
+ end
707
+
688
708
  post '/requests' do
689
709
  $params = params
690
710
  "{}"
@@ -17,4 +17,4 @@ module GH
17
17
  end
18
18
 
19
19
  DefaultStack.replace(Remote, FakeRemote)
20
- end
20
+ end
@@ -20,6 +20,7 @@ module Helpers
20
20
  end
21
21
 
22
22
  def run_cli(*args)
23
+ args << ENV['TRAVIS_OPTS'] if ENV['TRAVIS_OPTS']
23
24
  capture do
24
25
  yield $stdin if block_given?
25
26
  $stdin.rewind
data/travis.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
  Gem::Specification.new do |s|
3
3
  # general infos
4
4
  s.name = "travis"
5
- s.version = "1.1.3"
5
+ s.version = "1.2.0"
6
6
  s.description = "CLI and Ruby client library for Travis CI"
7
7
  s.homepage = "https://github.com/travis-ci/travis"
8
8
  s.summary = "Travis CI client"
@@ -73,6 +73,7 @@ Gem::Specification.new do |s|
73
73
  "lib/travis/client/session.rb",
74
74
  "lib/travis/client/states.rb",
75
75
  "lib/travis/client/user.rb",
76
+ "lib/travis/client/worker.rb",
76
77
  "lib/travis/pro.rb",
77
78
  "lib/travis/tools/formatter.rb",
78
79
  "lib/travis/tools/token_finder.rb",
@@ -98,6 +99,7 @@ Gem::Specification.new do |s|
98
99
  "spec/client/repository_spec.rb",
99
100
  "spec/client/session_spec.rb",
100
101
  "spec/client/user_spec.rb",
102
+ "spec/client/worker_spec.rb",
101
103
  "spec/client_spec.rb",
102
104
  "spec/pro_spec.rb",
103
105
  "spec/spec_helper.rb",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: travis
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2013-01-26 00:00:00.000000000 Z
16
+ date: 2013-02-22 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: faraday
@@ -263,6 +263,7 @@ files:
263
263
  - lib/travis/client/session.rb
264
264
  - lib/travis/client/states.rb
265
265
  - lib/travis/client/user.rb
266
+ - lib/travis/client/worker.rb
266
267
  - lib/travis/pro.rb
267
268
  - lib/travis/tools/formatter.rb
268
269
  - lib/travis/tools/token_finder.rb
@@ -288,6 +289,7 @@ files:
288
289
  - spec/client/repository_spec.rb
289
290
  - spec/client/session_spec.rb
290
291
  - spec/client/user_spec.rb
292
+ - spec/client/worker_spec.rb
291
293
  - spec/client_spec.rb
292
294
  - spec/pro_spec.rb
293
295
  - spec/spec_helper.rb