travis 1.0.3 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/README.md +786 -86
  2. data/Rakefile +3 -0
  3. data/lib/travis/cli/api_command.rb +22 -0
  4. data/lib/travis/cli/command.rb +36 -15
  5. data/lib/travis/cli/console.rb +13 -0
  6. data/lib/travis/cli/disable.rb +13 -0
  7. data/lib/travis/cli/enable.rb +29 -0
  8. data/lib/travis/cli/encrypt.rb +17 -4
  9. data/lib/travis/cli/history.rb +43 -0
  10. data/lib/travis/cli/logs.rb +18 -0
  11. data/lib/travis/cli/open.rb +36 -0
  12. data/lib/travis/cli/parser.rb +3 -3
  13. data/lib/travis/cli/repo_command.rb +16 -1
  14. data/lib/travis/cli/restart.rb +14 -0
  15. data/lib/travis/cli/show.rb +50 -0
  16. data/lib/travis/cli/status.rb +17 -0
  17. data/lib/travis/cli/sync.rb +28 -0
  18. data/lib/travis/cli/whatsup.rb +16 -0
  19. data/lib/travis/cli.rb +11 -0
  20. data/lib/travis/client/artifact.rb +25 -0
  21. data/lib/travis/client/build.rb +41 -0
  22. data/lib/travis/client/commit.rb +26 -0
  23. data/lib/travis/client/entity.rb +47 -3
  24. data/lib/travis/client/job.rb +52 -0
  25. data/lib/travis/client/methods.rb +22 -1
  26. data/lib/travis/client/repository.rb +70 -5
  27. data/lib/travis/client/session.rb +40 -8
  28. data/lib/travis/client/states.rb +85 -0
  29. data/lib/travis/client/user.rb +6 -0
  30. data/lib/travis/client.rb +5 -0
  31. data/lib/travis/tools/formatter.rb +38 -0
  32. data/lib/travis/version.rb +1 -1
  33. data/spec/cli/encrypt_spec.rb +16 -1
  34. data/spec/cli/history_spec.rb +28 -0
  35. data/spec/cli/logs_spec.rb +8 -0
  36. data/spec/cli/open_spec.rb +33 -0
  37. data/spec/cli/restart_spec.rb +15 -0
  38. data/spec/cli/show_spec.rb +9 -0
  39. data/spec/cli/status_spec.rb +28 -0
  40. data/spec/client/build_spec.rb +31 -0
  41. data/spec/client/commit_spec.rb +18 -0
  42. data/spec/client/job_spec.rb +30 -0
  43. data/spec/client/repository_spec.rb +15 -0
  44. data/spec/client/session_spec.rb +4 -0
  45. data/spec/spec_helper.rb +4 -1
  46. data/spec/support/fake_api.rb +616 -1
  47. data/travis.gemspec +37 -3
  48. metadata +66 -2
data/README.md CHANGED
@@ -1,130 +1,860 @@
1
- # Travis Client
2
-
3
- The `travis` [gem](https://rubygems.org/) includes both a command line client and a Ruby library to interface with a Travis CI service.
1
+ # The Travis Client
2
+
3
+ The [travis gem](https://rubygems.org/gems/travis) includes both a command line client and a Ruby library to interface with a Travis CI service. Both work with [travis-ci.org](https://travis-ci.org), [travis-ci.com](https://travis-ci.com) or any custom Travis CI setup you might have.
4
+
5
+ ## Table of Contents
6
+
7
+ * [Command Line Client](#command-line-client)
8
+ * [Non-API Commands](#non-api-commands)
9
+ * [`help`](#help)
10
+ * [`version`](#version)
11
+ * [General API Commands](#general-api-commands)
12
+ * [`console`](#console)
13
+ * [`endpoint`](#endpoint)
14
+ * [`login`](#login)
15
+ * [`raw`](#raw)
16
+ * [`sync`](#sync)
17
+ * [`whatsup`](#whatsup)
18
+ * [`whoami`](#whoami)
19
+ * [Repository Commands](#repository-commands)
20
+ * [`disable`](#disable)
21
+ * [`enable`](#enable)
22
+ * [`encrypt`](#encrypt)
23
+ * [`history`](#history)
24
+ * [`logs`](#logs)
25
+ * [`open`](#open)
26
+ * [`restart`](#restart)
27
+ * [`show`](#show)
28
+ * [`status`](#status)
29
+ * [Ruby Library](#ruby-library)
30
+ * [Authentication](#authentication)
31
+ * [Using Pro](#using-pro)
32
+ * [Entities](#entities)
33
+ * [Stateful Entities](#stateful-entities)
34
+ * [Repositories](#repositories)
35
+ * [Builds](#builds)
36
+ * [Jobs](#jobs)
37
+ * [Artifacts](#artifacts)
38
+ * [Users](#users)
39
+ * [Commits](#commits)
40
+ * [Dealing with Sessions](#dealing-with-sessions)
41
+ * [Using Namespaces](#using-namespaces)
42
+ * [Installation](#installation)
43
+ * [Upgrading from travis-cli](#upgrading-from-travis-cli)
44
+ * [Version History](#version-history)
4
45
 
5
46
  ## Command Line Client
6
47
 
7
- Command line usage is pretty simple:
48
+ There are three types of commands: [Non-API Commands](#non-api-commands), [General API Commands](#general-api-commands) and [Repository Commands](#repository-commands). All commands take the form of `travis COMMAND [ARGUMENTS] [OPTIONS]`. You can get a list of commands by running [`help`](#help).
49
+
50
+ ### Non-API Commands
51
+
52
+ Every Travis command takes three global options:
53
+
54
+ -h, --help Display help
55
+ -i, --[no-]interactive be interactive and colorful
56
+ -E, --[no-]explode don't rescue exceptions
57
+
58
+ The `--help` option is equivalent to running `travis help COMMAND`.
59
+
60
+ The `--interactive` options determines wether to include additional information and colors in the output or not (except on Windows, we never display colors on Windows, sorry). If you don't set this option explicitly, you will run in interactive mode if you invoke the command directly in a shell and in non-interactive mode if you pipe it somewhere.
61
+
62
+ You probably want to use `--explode` if you are working on a patch for the Travis client, as it will give you the Ruby exception instead of a nice error message.
63
+
64
+ #### `help`
65
+
66
+ The `help` command will inform you about the arguments and options that the commands take, for instance:
67
+
68
+ $ travis help help
69
+ Usage: travis help [command] [options]
70
+ -h, --help Display help
71
+ -i, --[no-]interactive be interactive and colorful
72
+ -E, --[no-]explode don't rescue exceptions
73
+
74
+ Running `help` without a command name will give you a list of all available commands.
75
+
76
+ #### `version`
77
+
78
+ As you might have guessed, this command prints out the client's version.
79
+
80
+ ### General API Commands
81
+
82
+ API commands inherit all options from [Non-API Commands](#non-api-commands).
83
+
84
+ Additionally, every API command understands the following options:
85
+
86
+ -e, --api-endpoint URL Travis API server to talk to
87
+ --pro short-cut for --api-endpoint 'https://api.travis-ci.com/'
88
+ --org short-cut for --api-endpoint 'https://api.travis-ci.org/'
89
+ -t, --token [ACCESS_TOKEN] access token to use
90
+ --debug show API requests
91
+
92
+ 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.
93
+
94
+ You can supply an access token via `--token` if you want to make an authenticated call. If you don't have an access token stored for the API endpoint, it will remember it for subsequent requests. Keep in mind, this is not the "Travis token" used when setting up GitHub hooks (due to security). You probably don't have an access token handy right now. Don't worry, usually you won't use this option but instead just do a [`travis login`](#login).
95
+
96
+ The `--debug` option will print HTTP requests to STDERR. Like `--explode`, this is really helpful when contributing to this project.
97
+
98
+ #### `console`
99
+
100
+ Running `travis console` gives you an interactive Ruby session with all the [entities](#entities) imported into global namespace.
101
+
102
+ But why use this over just `irb -r travis`? For one, it will take care of authentication, setting the correct endpoint, etc, and it also allows you to pass in `--debug` if you are curious as to what's actually going on.
103
+
104
+ $ travis console
105
+ >> User.current
106
+ => #<User: rkh>
107
+ >> Repository.find('sinatra/sinatra')
108
+ => #<Repository: sinatra/sinatra>
109
+ >> _.last_build
110
+ => #<Travis::Client::Build: sinatra/sinatra#360>
111
+
112
+ #### `endpoint`
113
+
114
+ Just prints out the API endpoint you're talking to.
115
+
116
+ $ travis endpoint
117
+ API endpoint: https://api.travis-ci.org/
118
+
119
+ Handy for using it when working with shell scripts:
120
+
121
+ $ curl "$(travis endpoint)/docs" > docs.html
122
+
123
+ #### `login`
124
+
125
+ The `login` command will, well, log you in. That way, all subsequent commands that run against the same endpoint will be authenticated.
126
+
127
+ $ travis login
128
+ We need your GitHub login to identify you.
129
+ This information will not be sent to Travis CI, only to GitHub.
130
+ The password will not be displayed.
131
+
132
+ Try running with --github-token or --auto if you don't want to enter your password anyways.
133
+
134
+ Username: rkh
135
+ Password: *******************
136
+
137
+ Successfully logged in!
138
+
139
+ As you can see above, it will ask you for your GitHub user name and password, but not send these to Travis CI. Instead, it will use them to create a GitHub API token, show the token to Travis, which then on its own checks if you really are who you say you are, and gives you an access token for the Travis API in return. The client will then delete the GitHub token again, just to be sure. But don't worry, all that happens under the hood and fully automatic.
140
+
141
+ If you don't want it to send your credentials to GitHub, you can create a GitHub token on your own and supply it via `--github-token`. In that case, the client will not delete the GitHub token (as it can't, it needs your password to do this). Travis CI will not store the token, though - after all, it already should have a valid token for you in the database.
142
+
143
+ A third option is for the really lazy: `--auto`. In this mode the client will try to find a GitHub token for you and just use that. This will only work if you have a [global GitHub token](https://help.github.com/articles/git-over-https-using-oauth-token) stored in your [.netrc](http://blogdown.io/c4d42f87-80dd-45d5-8927-4299cbdf261c/posts/574baa68-f663-4dcf-88b9-9d41310baf2f). If you haven't heard of this, it's worth looking into in general. Again: Travis CI will not store that token.
144
+
145
+ #### `raw`
146
+
147
+ This is really helpful both when working on this client and when exploring the [Travis API](https://api.travis-ci.org). It will simply fire a request against the API endpoint, parse the output and pretty print it. Keep in mind that the client takes care of authentication for you:
148
+
149
+ $ travis raw /repos/travis-ci/travis
150
+ {"repo"=>
151
+ {"id"=>409371,
152
+ "slug"=>"travis-ci/travis",
153
+ "description"=>"Travis CI Client (CLI and Ruby library)",
154
+ "last_build_id"=>4251410,
155
+ "last_build_number"=>"77",
156
+ "last_build_state"=>"passed",
157
+ "last_build_duration"=>351,
158
+ "last_build_language"=>nil,
159
+ "last_build_started_at"=>"2013-01-19T18:00:49Z",
160
+ "last_build_finished_at"=>"2013-01-19T18:02:17Z"}}
161
+
162
+ Use `--json` if you'd rather prefer the output to be JSON.
163
+
164
+ ### `sync`
165
+
166
+ Usage: travis sync [options]
167
+ -h, --help Display help
168
+ -i, --[no-]interactive be interactive and colorful
169
+ -E, --[no-]explode don't rescue exceptions
170
+ -e, --api-endpoint URL Travis API server to talk to
171
+ --pro short-cut for --api-endpoint 'https://api.travis-ci.com/'
172
+ --org short-cut for --api-endpoint 'https://api.travis-ci.org/'
173
+ -t, --token [ACCESS_TOKEN] access token to use
174
+ --debug show API requests
175
+ -c, --check only check the sync status
176
+ -b, --background will trigger sync but not block until sync is done
177
+ -f, --force will force sync, even if one is already running
178
+
179
+ Sometimes the infos Travis CI has about users and repositories become out of date. If that should happen, you can manually trigger a sync:
180
+
181
+ $ travis sync
182
+ synchronizing: ........... done
183
+
184
+ The command blocks until the synchronization is done. You can avoid that with `--background`:
185
+
186
+ $ travis sync --background
187
+ starting synchronization
188
+
189
+ If you just want to know if your account is being synchronized right now, use `--check`:
190
+
191
+ $ travis sync --check
192
+ rkh is currently syncing
193
+
194
+ #### `whatsup`
195
+
196
+ It's just a tiny feature, but it allows you to take a look at repositories that have recently seen some action (ie the left hand sidebar on [travis-ci.org](https://travis-ci.org)):
197
+
198
+ $ travis whatsup
199
+ mysociety/fixmystreet started: #154
200
+ eloquent/typhoon started: #228
201
+ Pajk/apipie-rails started: #84
202
+ qcubed/framework failed: #21
203
+ ...
204
+
205
+ #### `whoami`
206
+
207
+ This command is useful to verify that you're in fact logged in:
208
+
209
+ $ travis whoami
210
+ You are rkh (Konstantin Haase)
211
+
212
+ Again, like most other commands, goes well with shell scripting:
213
+
214
+ $ git clone "https://github.com/$(travis whoami)/some_project"
215
+
216
+ ### Repository Commands
217
+
218
+ -h, --help Display help
219
+ -i, --[no-]interactive be interactive and colorful
220
+ -E, --[no-]explode don't rescue exceptions
221
+ -e, --api-endpoint URL Travis API server to talk to
222
+ --pro short-cut for --api-endpoint 'https://api.travis-ci.com/'
223
+ --org short-cut for --api-endpoint 'https://api.travis-ci.org/'
224
+ -t, --token [ACCESS_TOKEN] access token to use
225
+ --debug show API requests
226
+ -r, --repo SLUG
227
+
228
+ Repository commands have all the options [General API Commands](#general-api-commands) have.
229
+
230
+ Additionally, you can specify the Repository to talk to by providing `--repo owner/name`. However, if you invoke the command inside a clone of the project, the client will figure out this option on its own. Note that it uses the [git remote](http://www.kernel.org/pub/software/scm/git/docs/git-remote.html) "origin" to do so.
231
+
232
+ It will also automatically pick [Travis Pro](https://travis-ci.com) if it is a private project. You can of course override this decission with `--pro`, `--org` or `--api-endpoint URL`
233
+
234
+ #### `disable`
235
+
236
+ If you want to turn of a repository temporarily or indefinitely, you can do so with the `disable` command:
237
+
238
+ $ travis disable
239
+ travis-ci/travis: disabled :(
240
+
241
+ #### `enable`
242
+
243
+ With the `enable` command, you can easily activate a project on Travis CI:
244
+
245
+ $ travis enable
246
+ travis-ci/travis: enabled :)
247
+
248
+ It even works when enabling a repo Travis didn't know existed by triggering a sync:
249
+
250
+ $ travis enable -r rkh/test
251
+ repository not known to Travis CI (or no access?)
252
+ triggering sync: ............. done
253
+ rkh/test: enabled
254
+
255
+ If you don't want the sync to be triggered, use `--skip-sync`.
256
+
257
+ #### `encrypt`
258
+
259
+ Usage: travis encrypt [args..] [options]
260
+ -h, --help Display help
261
+ -i, --[no-]interactive be interactive and colorful
262
+ -E, --[no-]explode don't rescue exceptions
263
+ -e, --api-endpoint URL Travis API server to talk to
264
+ --pro short-cut for --api-endpoint 'https://api.travis-ci.com/'
265
+ --org short-cut for --api-endpoint 'https://api.travis-ci.org/'
266
+ -t, --token [ACCESS_TOKEN] access token to use
267
+ --debug show API requests
268
+ -r, --repo SLUG
269
+ --add [KEY] adds it to .travis.yml under KEY (default: env.global)
270
+ -s, --[no-]split treat each line as a separate input
271
+
272
+ This command is useful to encrypt [environment variables](http://about.travis-ci.org/docs/user/encryption-keys/) or deploy keys for private dependencies.
273
+
274
+ $ travis encrypt FOO=bar
275
+ Please add the following to your .travis.yml file:
276
+
277
+ secure: "gSly+Kvzd5uSul15CVaEV91ALwsGSU7yJLHSK0vk+oqjmLm0jp05iiKfs08j\n/Wo0DG8l4O9WT0mCEnMoMBwX4GiK4mUmGdKt0R2/2IAea+M44kBoKsiRM7R3\n+62xEl0q9Wzt8Aw3GCDY4XnoCyirO49DpCH6a9JEAfILY/n6qF8="
278
+
279
+ Pro Tip™: You can add it automatically by running with --add.
280
+
281
+ For deploy keys, it is really handy to pipe them into the command:
282
+
283
+ $ cat id_rsa | travis encrypt
284
+
285
+ Another use case for piping files into it: If you have a file with sensitive environment variables, like foreman's [.env](http://ddollar.github.com/foreman/#ENVIRONMENT) file, you can add tell the client to encrypt every line separately via `--split`:
286
+
287
+ $ cat .env | travis encrypt --split
288
+ Please add the following to your .travis.yml file:
289
+
290
+ secure: "KmMdcwTWGubXVRu93/lY1NtyHxrjHK4TzCfemgwjsYzPcZuPmEA+pz+umQBN\n1ZhzUHZwDNsDd2VnBgYq27ZdcS2cRvtyI/IFuM/xJoRi0jpdTn/KsXR47zeE\nr2bFxRqrdY0fERVHSMkBiBrN/KV5T70js4Y6FydsWaQgXCg+WEU="
291
+ secure: "jAglFtDjncy4E3upL/RF0ZOcmJ2UMrqHFCLQwU8PBdurhTMBeTw+IO6cXx5z\nU5zqvPYo/ghZ8mMuUhvHiGDM6m6OlMP7+l10VTxH1CoVew2NcQvRdfK3P+4S\nZJ43Hyh/ZLCjft+JK0tBwoa3VbH2+ZTzkRZQjdg54bE16C7Mf1A="
292
+
293
+ Pro Tip™: You can add it automatically by running with --add.
294
+
295
+ As suggested, the client can also add them to your `.travis.yml` for you:
296
+
297
+ $ travis encrypt FOO=bar --add
298
+
299
+ This will by default add it as global variables for every job. You can also add it as matrix entries by providing a key:
300
+
301
+ $ travis encrypt FOO=bar --add env.matrix
302
+
303
+ #### `history`
304
+
305
+ Usage: travis history [options]
306
+ -h, --help Display help
307
+ -i, --[no-]interactive be interactive and colorful
308
+ -E, --[no-]explode don't rescue exceptions
309
+ -e, --api-endpoint URL Travis API server to talk to
310
+ --pro short-cut for --api-endpoint 'https://api.travis-ci.com/'
311
+ --org short-cut for --api-endpoint 'https://api.travis-ci.org/'
312
+ -t, --token [ACCESS_TOKEN] access token to use
313
+ --debug show API requests
314
+ -r, --repo SLUG
315
+ -a, --after BUILD Only show history after a given build number
316
+ -p, --pull-request NUMBER Only show history for the given Pull Request
317
+ -b, --branch BRANCH Only show history for the given branch
318
+ -l, --limit LIMIT Maximum number of history items
319
+ --[no-]all Display all history items
320
+
321
+ You can check out what the recent builds look like:
322
+
323
+ $ travis history
324
+ #77 passed: master fix name clash
325
+ #76 failed: master Merge pull request #11 from travis-ci/rkh-show-logs-history
326
+ #75 passed: rkh-debug what?
327
+ #74 passed: rkh-debug all tests pass locally and on the travis vm I spin up :(
328
+ #73 failed: Pull Request #11 regenerate gemspec
329
+ #72 passed: rkh-show-logs-history regenerate gemspec
330
+ #71 failed: Pull Request #11 spec fix for (older) rubinius
331
+ #70 passed: rkh-show-logs-history spec fix for (older) rubinius
332
+ #69 failed: Pull Request #11 strange fix for rubinius
333
+ #68 failed: rkh-show-logs-history strange fix for rubinius
334
+
335
+ By default, it will display the last 10 builds. You can limit (or extend) the number of builds with `--limit`:
336
+
337
+ $ travis history --limit 2
338
+ #77 passed: master fix name clash
339
+ #76 failed: master Merge pull request #11 from travis-ci/rkh-show-logs-history
340
+
341
+ You can use `--after` to display builds after a certain build number (or, well, before, but it's called after to use the same phrases as the API):
342
+
343
+ $ travis history --limit 2 --after 76
344
+ #75 passed: rkh-debug what?
345
+ #74 passed: rkh-debug all tests pass locally and on the travis vm I spin up :(
346
+
347
+ You can also limit the history to builds for a certain branch:
348
+
349
+ $ travis history --limit 3 --branch master
350
+ #77 passed: master fix name clash
351
+ #76 failed: master Merge pull request #11 from travis-ci/rkh-show-logs-history
352
+ #57 passed: master Merge pull request #5 from travis-ci/hh-multiline-encrypt
353
+
354
+ Or a certain Pull Request:
355
+
356
+ $ travis history --limit 3 --pull-request 5
357
+ #56 passed: Pull Request #5 Merge branch 'master' into hh-multiline-encrypt
358
+ #49 passed: Pull Request #5 improve output
359
+ #48 passed: Pull Request #5 let it generate accessor for line splitting automatically
360
+
361
+ #### `logs`
362
+
363
+ Given a job number, logs simply prints out that job's logs.
364
+
365
+ $ travis logs 77.1
366
+ [... more logs ...]
367
+ Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
368
+ $ bundle exec rake
369
+ /home/travis/.rvm/rubies/ruby-1.8.7-p371/bin/ruby -S rspec spec -c
370
+ Faraday: you may want to install system_timer for reliable timeouts
371
+ ...................................................................................................................................................................
372
+
373
+ Finished in 6.48 seconds
374
+ 163 examples, 0 failures
375
+
376
+ Done. Build script exited with: 0
377
+
378
+ #### `open`
379
+
380
+ Opens the project view in the Travis CI web interface. If you pass it a build or job number, it will open that specific view:
381
+
382
+ $ travis open
383
+
384
+ If you just want the URL printed out instead of opened in a browser, pass `--print`.
385
+
386
+ If instead you want to open the repository, compare or pull request view on GitHub, use `--github`.
387
+
388
+ $ travis open 56 --print --github
389
+ web view: https://github.com/travis-ci/travis/pull/5
390
+
391
+ #### `restart`
392
+
393
+ This command will restart the latest build:
394
+
395
+ $ travis restart
396
+ build #85 has been restarted
397
+
398
+ You can also restart any build by giving a build number:
399
+
400
+ $ travis restart 57
401
+ build #57 has been restarted
402
+
403
+ Or a single job:
404
+
405
+ $ travis restart 57.1
406
+ job #57.1 has been restarted
407
+
408
+ #### `show`
409
+
410
+ Displays general infos about the latest build:
411
+
412
+ $ travis show
413
+ Build #77: fix name clash
414
+ State: passed
415
+ Type: push
416
+ Compare URL: https://github.com/travis-ci/travis/compare/7cc9b739b0b6...39b66ee24abe
417
+ Duration: 5 min 51 sec
418
+ Started: 2013-01-19 19:00:49
419
+ Finished: 2013-01-19 19:02:17
420
+
421
+ #77.1 passed: 45 sec rvm: 1.8.7
422
+ #77.2 passed: 50 sec rvm: 1.9.2
423
+ #77.3 passed: 45 sec rvm: 1.9.3
424
+ #77.4 passed: 46 sec rvm: 2.0.0
425
+ #77.5 failed: 1 min 18 sec rvm: jruby (failure allowed)
426
+ #77.6 passed: 1 min 27 sec rvm: rbx
427
+
428
+ Any other build:
429
+
430
+ $ travis show 1
431
+ Build #1: add .travis.yml
432
+ State: failed
433
+ Type: push
434
+ Compare URL: https://github.com/travis-ci/travis/compare/ad817bc37c76...b8c5d3b463e2
435
+ Duration: 3 min 16 sec
436
+ Started: 2013-01-13 23:15:22
437
+ Finished: 2013-01-13 23:21:38
438
+
439
+ #1.1 failed: 21 sec rvm: 1.8.7
440
+ #1.2 failed: 34 sec rvm: 1.9.2
441
+ #1.3 failed: 24 sec rvm: 1.9.3
442
+ #1.4 failed: 52 sec rvm: 2.0.0
443
+ #1.5 failed: 38 sec rvm: jruby
444
+ #1.6 failed: 27 sec rvm: rbx
445
+
446
+ Or a job:
447
+
448
+ $ travis show 77.3
449
+ Job #77.3: fix name clash
450
+ State: passed
451
+ Type: push
452
+ Compare URL: https://github.com/travis-ci/travis/compare/7cc9b739b0b6...39b66ee24abe
453
+ Duration: 45 sec
454
+ Started: 2013-01-19 19:00:49
455
+ Finished: 2013-01-19 19:01:34
456
+ Allow Failure: false
457
+ Config: rvm: 1.9.3
458
+
459
+ #### `status`
460
+
461
+ Usage: travis status [options]
462
+ -h, --help Display help
463
+ -i, --[no-]interactive be interactive and colorful
464
+ -E, --[no-]explode don't rescue exceptions
465
+ -e, --api-endpoint URL Travis API server to talk to
466
+ --pro short-cut for --api-endpoint 'https://api.travis-ci.com/'
467
+ --org short-cut for --api-endpoint 'https://api.travis-ci.org/'
468
+ -t, --token [ACCESS_TOKEN] access token to use
469
+ --debug show API requests
470
+ -r, --repo SLUG
471
+ -x, --[no-]exit-code sets the exit code to 1 if the build failed
472
+ -q, --[no-]quiet does not print anything
473
+ -p, --[no-]fail-pending sets the status code to 1 if the build is pending
474
+
475
+ Outputs a one line status message about the project's last build. With `-q` that line will even not be printed out. How's that useful? Combine it with `-x` and the exit code will be 1 if the build failed, with `-p` and it will be 1 for a pending build.
476
+
477
+ $ travis status -qpx && cap deploy
478
+
479
+ ## Ruby Library
480
+
481
+ There are two approaches of using the Ruby library, one straight forward with one global session:
482
+
483
+ ``` ruby
484
+ require 'travis'
485
+
486
+ rails = Travis::Repository.find('rails/rails')
487
+ puts "oh no" unless rails.green?
488
+ ```
489
+
490
+ And one where you have to instantiate your own session:
8
491
 
492
+ ``` ruby
493
+ require 'travis/client'
494
+
495
+ client = Travis::Client.new
496
+ rails = client.repo('rails/rails')
497
+ puts "oh no" unless rails.green?
9
498
  ```
10
- $ cd my_awesome_project
11
- $ travis encrypt FOO=BAR
499
+
500
+ For most parts, those are pretty much the same, the entities you get back look the same, etc, except one offers nice constants as part of the API, the other doesn't. In fact the "global" session style uses `Travis::Client` internally.
501
+
502
+ So, which one to choose? The global style has one session, whereas with the client style, you have one session per client instance. Each session has it's own cache and identity map. This might matter for log running processes. If you use a new session for separate units of work, you can be pretty sure to not leak any objects. On the other hand using the constants or reusing the same session might save you from unnecessary HTTP requests.
503
+
504
+ In either way, if you should use the first approach or long living clients, here is how you make sure not to have stale data around:
505
+
506
+ ``` ruby
507
+ Travis.clear_cache
508
+ client.clear_cache
12
509
  ```
13
510
 
14
- The client will try its best at figuring out which API endpoint to talk to. But you can always explicitly state which one it is by adding `--pro` or `--org` (or `-e URL` if you run your own).
511
+ Note that this will still keep the identity map around, it will only drop all attributes. To clear the identity map, you can use the `clear_cache!` method. However, if you do that, you should not keep old instances of any entities (like repositories, etc) around.
15
512
 
16
- ### Available commands
513
+ ### Authentication
17
514
 
18
- Currently the following commands are available:
515
+ Authentication is pretty easy, you just need to set an access token:
19
516
 
20
- * `endpoint` - displays the API endpoint used
21
- * `encrypt` - encrypts data with a repos public key (useful for secure env vars etc)
22
- * `help` - displays general or command specific help
23
- * `login` - authenticates for subsequent commands
24
- * `whoami` - displays the user name you are logged in with
517
+ ``` ruby
518
+ require 'travis'
25
519
 
26
- ### Unix friendly
520
+ Travis.access_token = "..."
521
+ puts "Hello #{Travis::User.current.name}!"
522
+ ```
27
523
 
28
- All the commands are written with Unix in mind:
524
+ Or with your own client instance:
29
525
 
526
+ ``` ruby
527
+ require 'travis/client'
528
+
529
+ client = Travis::Client.new
530
+ puts "Hello #{client.user.name}"
30
531
  ```
31
- $ curl "$(travis endpoint)/docs" > docs.html
32
- $ cat secret.txt | travis encrypt
532
+
533
+ If you don't have an access token for Travis CI, you can use a GitHub access token to get one:
534
+
535
+ ``` ruby
536
+ require 'travis'
537
+
538
+ Travis.github_auth("...")
539
+ puts "Hello #{Travis::User.current.name}!"
33
540
  ```
34
541
 
35
- ### Windows friendly
542
+ Travis CI will not store that token.
36
543
 
37
- It should work on Windows. However, we do not yet run our CI on Windows and only tried on Windows 7 so far.
544
+ ### Using Pro
38
545
 
39
- ### Invoking from Ruby
546
+ Using the library with private projects pretty much works the same, except you use `Travis::Pro`.
40
547
 
41
- You can also invoke the commands from within Ruby:
548
+ Keep in mind that you need to authenticate.
42
549
 
43
550
  ``` ruby
44
- require 'travis/cli'
45
- Travis::CLI.run(:encrypt, "my secret")
551
+ require 'travis/pro'
552
+
553
+ Travis::Pro.access_token = '...'
554
+ user = Travis::Pro::User.current
555
+
556
+ puts "Hello #{user.name}!"
46
557
  ```
47
558
 
48
- Note that you should probably use `Travis::Client` instead.
559
+ ### Entities
49
560
 
50
- ## Ruby Library
561
+ Entities are like the models in the Travis Client land. They keep the data and it's usually them you talk to if you want something.
562
+ They are pretty much normal Ruby objects.
563
+
564
+ The Travis session will cache all entities, so don't worry about loading the same one twice.
565
+ Once you got a hold of one, you can easily reload it at any time if you want to make sure the data is fresh:
566
+
567
+ ``` ruby
568
+ rails = Travis::Repository.find('rails/rails')
569
+ sleep 1.hour
570
+ rails.reload
571
+ ```
51
572
 
52
- ### Basic Example
573
+ The travis gem supports lazy and partial loading, so if you want to make sure you have all the data, just call load.
574
+
575
+ ``` ruby
576
+ rails.load
577
+ ```
578
+
579
+ This is not something you should usually do, as partial loading is actually your friend (keeps requests to a minimum).
580
+
581
+
582
+ #### Stateful Entities
583
+
584
+ [Repositories](#repositories), [Builds](#builds) and [Jobs](#jobs) all are basically state machines, which means the implement the following methods:
53
585
 
54
586
  ``` ruby
55
587
  require 'travis'
588
+ build = Travis::Repository.find('rails/rails').last_build
589
+
590
+ p build.canceled?
591
+ p build.created?
592
+ p build.errored?
593
+ p build.failed?
594
+ p build.finished?
595
+ p build.green?
596
+ p build.passed?
597
+ p build.pending?
598
+ p build.queued?
599
+ p build.red?
600
+ p build.running?
601
+ p build.started?
602
+ p build.successful?
603
+ p build.unsuccessful?
604
+ p build.yellow?
605
+ p build.color
606
+ ```
56
607
 
57
- rails = Travis::Repository.find('rails/rails')
58
- puts "The last Rails build #{rails.last_build_state}."
608
+ Builds and jobs also have a `state` method. For repositories, use `last_build.state`.
609
+
610
+ #### Repositories
611
+
612
+ Repositories are probably one of the first entities you'll load. It's pretty straight forward, too.
613
+
614
+ ``` ruby
615
+ require 'travis'
616
+
617
+ Travis::Repository.find('rails/rails') # find by slug
618
+ Travis::Repository.find(891) # find by id
619
+ Travis::Repository.find_all(owner_name: 'rails') # all repos in the rails organization
620
+ Travis::Repository.current # repos that see some action right now
59
621
  ```
60
622
 
61
- Output:
623
+ Once you have a repository, you can for instance encrypt some strings with its private key:
62
624
 
625
+ ``` ruby
626
+ require 'travis'
627
+
628
+ Travis::Repository.find('rails/rails')
629
+ puts repo.encrypt('FOO=bar')
63
630
  ```
64
- The last Rails build passed.
631
+
632
+ Repositories are [stateful](#stateful-entities).
633
+
634
+ You can enable or disable a repository with the methods that go by the same name.
635
+
636
+ ``` ruby
637
+ rails.disable
638
+ system "push all the things"
639
+ rails.enable
65
640
  ```
66
641
 
67
- Field names correspond to field names in JSON payload returned from [Travis API](https://api.travis-ci.org).
642
+ If you want to enable a new project, you might have to do a sync first.
68
643
 
69
- ### Reloading Entities
644
+ #### Builds
70
645
 
71
- You can reload a single entity by calling `reload` on it:
646
+ You could load a build by its id using `Travis::Build.find`. But most of the time you won't have the id handy, so you'd usually start with a repository.
72
647
 
73
648
  ``` ruby
74
- loop do
75
- sleep 1
76
- repo.reload
77
- puts "Current Status: #{repo.last_build_state}"
649
+ require 'travis'
650
+ rails = Travis::Repository.find('rails/rails')
651
+
652
+ rails.last_build # the latest build
653
+ rails.recent_builds # the last 20 or so builds (don't rely on that number)
654
+ rails.builds(after_number: 42) # the last 20 or so builds *before* 42
655
+ rails.build(42) # build with the number 42 (not the id!)
656
+ rails.builds # Enumerator for #each_build
657
+
658
+ # this will loop through all builds
659
+ rails.each_build do |build|
660
+ puts "#{build.number}: #{build.state}"
661
+ end
662
+
663
+ # this will loop through all builds before build 42
664
+ rails.each_build(after_number: 42) do |build|
665
+ puts "#{build.number}: #{build.state}"
78
666
  end
79
667
  ```
80
668
 
81
- You can also reload *all* entities by calling:
669
+ Note that `each_build` (and thus `builds` without and argument) is lazy and uses pagination, so you can safely do things like this:
82
670
 
83
671
  ``` ruby
84
- Travis.session.clear_cache
672
+ build = rails.builds.detect { |b| b.failed? }
673
+ puts "Last failing Rails build: #{build.number}"
85
674
  ```
86
675
 
87
- ### Using Pro
676
+ Without having to load more than 6000 builds.
677
+
678
+ You can restart a build, if the current user has sufficient permissions on the repository:
88
679
 
89
680
  ``` ruby
90
- require 'travis/pro'
681
+ rails.last_build.restart
682
+ ```
91
683
 
92
- Travis::Pro.access_token = '...'
93
- Travis::Pro::Repository.find('secret/repo')
684
+ #### Jobs
685
+
686
+ Jobs behave a lot like [builds](#builds), and similar to them, you probably don't have the id ready. You can get the jobs from a build:
687
+
688
+ ``` ruby
689
+ rails.last_build.jobs.each do |job|
690
+ puts "#{job.number} took #{job.duration} seconds"
691
+ end
94
692
  ```
95
693
 
96
- ### No global state
694
+ If you have the job number, you can also reach a job directly from the repository:
97
695
 
98
- If you use the library in a long running process, like a daemon, it is recommended to create a new session for every piece of work, as every session uses its own cache and is not guaranteed to be thread-safe.
696
+ ``` ruby
697
+ rails.job('5000.1')
698
+ ```
699
+
700
+ Like builds, you can also restart singe jobs:
99
701
 
100
702
  ``` ruby
101
- require 'travis/client'
703
+ rails.job('5000.1').restart
704
+ ```
705
+
706
+ #### Artifacts
707
+
708
+ The artifacts you usually care for are probably logs. You can reach them directly from a build:
709
+
710
+ ``` ruby
711
+ require 'travis'
712
+
713
+ repo = Travis::Repository.find('travis-ci/travis')
714
+ job = repo.last_build.jobs.first
715
+ puts job.log.body
716
+ ```
717
+
718
+ If you plan to print our the body, be aware that it might contain malicious escape codes. For this reason, we added `colorized_body`, which removes all the unprintable characters, except for ANSI color codes, and `clean_body` which also removes the color codes.
719
+
720
+ ``` ruby
721
+ puts job.log.colorized_body
722
+ ````
723
+
724
+ #### Users
102
725
 
103
- session = Travis::Client.new(uri: 'http://localhost:3000', access_token: 'foobar')
104
- session.repo('foo/bar')
726
+ The only user you usually get access to is the currently authenticated one.
727
+
728
+ ``` ruby
729
+ require 'travis'
730
+
731
+ Travis.access_token = '...'
732
+ user = Travis::User.current
733
+
734
+ puts "Hello, #{user.login}! Or should I call you... #{user.name.upcase}!?"
105
735
  ```
106
736
 
107
- You can also create a namespace to get the look and feel of `Travis` and `Travis::Pro`:
737
+ If some data gets out of sync between GitHub and Travis, you can use the user object to trigger a new sync.
108
738
 
109
739
  ``` ruby
110
- MyTravis = Travis::Namespace.new('http://localhost:3000')
111
- MyTravis::Repository.find('foo/bar')
740
+ Travis::User.current.sync
112
741
  ```
113
742
 
114
- ## Installation
743
+ #### Commits
744
+
745
+ Commits cannot be loaded directly. They come as a byproduct of [jobs](#jobs) and [builds](#builds).
746
+
747
+ ``` ruby
748
+ require 'travis'
749
+
750
+ repo = Travis::Repository.find('travis-ci/travis')
751
+ commit = repo.last_build.commit
752
+
753
+ puts "Last tested commit: #{commit.short_sha} on #{commit.branch} by #{commit.author_name} - #{commit.subject}"
754
+ ```
755
+
756
+ ### Dealing with Sessions
757
+
758
+ 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.
759
+
760
+ There are two levels of session methods, the higher level methods from the `Travis::Client::Methods` mixin, which are also available from `Travis`, `Travis::Pro` or any custom [Namespace](#using-namespaces).
761
+
762
+ ``` ruby
763
+ require 'travis/client/session'
764
+ session = Travis::Client::Session.new
765
+
766
+ session.access_token = "secret_token" # access token to use
767
+ session.api_endpoint = "http://localhost:3000/" # api endpoint to talk to
768
+ session.github_auth("github_token") # log in with a github token
769
+ session.repos(owner_name: 'travis-ci') # all travis-ci/* projects
770
+ session.repo('travis-ci/travis') # this project
771
+ session.repo(409371) # same as the one above
772
+ session.build(4266036) # build with id 4266036
773
+ session.job(4266037) # job with id 4266037
774
+ session.artifact(42) # artifact with id 42
775
+ session.log(42) # same as above
776
+ session.user # the current user, if logged in
777
+ session.restart(session.build(4266036)) # restart some build
778
+ ```
779
+
780
+ You can add these methods to any object responding to `session` via said mixin.
781
+
782
+ Below this, there is a second API, close to the HTTP level:
783
+
784
+ ``` ruby
785
+ require 'travis/client/session'
786
+ session = Travis::Client::Session.new
787
+
788
+ session.instrument do |description, block|
789
+ time = Time.now
790
+ block.call
791
+ puts "#{description} took #{Time.now - time} seconds"
792
+ end
793
+
794
+ session.connection = Faraday::Connection.new
795
+
796
+ session.get_raw('/repos/rails/rails') # => {"repo" => {"id" => 891, "slug" => "rails/rails", ...}}
797
+ session.get('/repos/rails/rails') # => {"repo" => #<Travis::Client::Repository: rails/rails>}
798
+ session.headers['Foo'] = 'Bar' # send a custom HTTP header with every request
799
+
800
+ rails = session.find_one(Travis::Client::Repository, 'rails/rails')
801
+
802
+ session.find_many(Travis::Client::Repository) # repositories with the latest builds
803
+ session.find_one_or_many(Travis::Client::User) # the current user (you could also use find_one here)
804
+
805
+ session.reload(rails)
806
+ session.reset(rails) # lazy reload
807
+
808
+ session.clear_cache # empty cached attributes
809
+ session.clear_cache! # empty identity map
810
+ ```
811
+
812
+ ### Using Namespaces
813
+
814
+ `Travis` and `Travis::Pro` are just two different namespaces for two different Travis sessions. A namespace is a Module, exposing the higher level [session methods](#dealing-with-sessions). It also has a dummy constant for every [entity](#entities), wrapping `find_one` (aliased to `find`) and `find_many` (aliased to `find_all`) for you, so you don't have to keep track of the session or hand in the entity class. You can easily create your own namespace:
115
815
 
116
- Make sure you have Ruby installed (duh!), it should work with any Ruby starting from version 1.8.7, including 2.0, Rubinius and JRuby:
816
+ ``` ruby
817
+ require 'travis/client'
818
+ MyTravis = Travis::Namespaces.new("http://localhost:3000")
117
819
 
820
+ MyTravis.access_token = "..."
821
+ MyTravis::Repository.find("foo/bar")
118
822
  ```
119
- $ gem install travis --no-rdoc --no-ri
823
+
824
+ Since namespaces are Modules, you can also include them.
825
+
826
+ ``` ruby
827
+ require 'travis/client'
828
+
829
+ class MyTravis
830
+ include Travis::Namespaces.new
831
+ end
832
+
833
+ MyTravis::Repository.find('rails/rails')
120
834
  ```
121
835
 
122
- ### Upgrading from travis-cli (now travis-deploy)
836
+ ## Installation
837
+
838
+ Make sure you have at least [Ruby](http://www.ruby-lang.org/en/downloads/) 1.8.7 (1.9.3 recommended) installed. Then run:
839
+
840
+ $ gem install travis --no-rdoc --no-ri
841
+
842
+ ### Upgrading from travis-cli
123
843
 
124
844
  If you have the old `travis-cli` gem installed, you should `gem uninstall travis-cli`, just to be sure, as it ships with an executable that is also named `travis`.
125
845
 
126
846
  ## Version History
127
847
 
848
+ **v1.1.0** (not yet released)
849
+
850
+ * New commands: `console`, `status`, `show`, `logs`, `history`, `restart`, `sync`, `enable`, `disable`, `open` and `whatsup`.
851
+ * `--debug` option for all API commands.
852
+ * `--split` option for `encrypt`.
853
+ * Fix `--add` option for `encrypt` (was naming key `secret` instead of `secure`).
854
+ * First class representation for builds, commits and jobs in the Ruby library.
855
+ * Print warning when running "encrypt owner/project data", as it's not supported by the new client.
856
+ * Improved documentation.
857
+
128
858
  **v1.0.3** (January 15, 2013)
129
859
 
130
860
  * Fix `-r slug` for repository commands. (#3)
@@ -151,33 +881,3 @@ If you have the old `travis-cli` gem installed, you should `gem uninstall travis
151
881
  **v1.0.0pre** (January 13, 2013)
152
882
 
153
883
  * Initial public prerelease.
154
-
155
- ## TODO
156
-
157
- ### Command Line Client
158
-
159
- * Enabling/disabling projects
160
- * Build status inspection
161
- * Log streaming
162
- * Rebuild builds/jobs
163
- * Requeue projects
164
- * List projects, maybe
165
- * Broadcasts
166
- * Events?
167
- * Workers?
168
- * Artifacts?
169
- * Integrate travis-lint?
170
- * What about deploy/config?
171
-
172
- ### Ruby Client
173
-
174
- * Artifacts
175
- * Branches
176
- * Broadcasts
177
- * Builds
178
- * Commits
179
- * Events
180
- * Hooks
181
- * Jobs
182
- * Requests
183
- * Workers