Compare commits
242 Commits
sf-squash-
...
master
Author | SHA1 | Date | |
---|---|---|---|
![]() |
542592ae41 | ||
![]() |
c2c1952d40 | ||
![]() |
ca80c7f0a2 | ||
![]() |
a9f84c27b0 | ||
![]() |
65aece922c | ||
![]() |
17ccc22fbe | ||
![]() |
51575bdb89 | ||
![]() |
b3e8b9d43b | ||
![]() |
ba6b5b7cba | ||
![]() |
8afaeb10c0 | ||
![]() |
c7161cec81 | ||
![]() |
8a14ef827f | ||
![]() |
32503b0731 | ||
![]() |
178122e247 | ||
![]() |
7655d0edd2 | ||
![]() |
885ae009f4 | ||
![]() |
614b1f5338 | ||
![]() |
8655579a94 | ||
![]() |
77e47bc41a | ||
![]() |
779b6a569e | ||
![]() |
abe7b13605 | ||
![]() |
0dc7e2743c | ||
![]() |
d42362eacc | ||
![]() |
1788e0c0fb | ||
![]() |
20d4df8af3 | ||
![]() |
d41ddd7171 | ||
![]() |
6ca063cf3d | ||
![]() |
f787a96b96 | ||
![]() |
d0a143d76a | ||
![]() |
cdce95a508 | ||
![]() |
0f2b1edae1 | ||
![]() |
f09e9931b2 | ||
![]() |
75bd65e56c | ||
![]() |
f4cb24c4b4 | ||
![]() |
4888c2c905 | ||
![]() |
edf889b55f | ||
![]() |
0dc1009ab4 | ||
![]() |
255640fd4f | ||
![]() |
bcf08e0e7e | ||
![]() |
89eea1682f | ||
![]() |
9e1c6933f5 | ||
![]() |
3f97b40914 | ||
![]() |
90e5d968ea | ||
![]() |
7d70f161a1 | ||
![]() |
7f3fb70ec7 | ||
![]() |
175e266a6d | ||
![]() |
e037127a9c | ||
![]() |
5293919f3a | ||
![]() |
c6a1eda572 | ||
![]() |
cb89cae39f | ||
![]() |
bcbf0abf60 | ||
![]() |
9e2fff6e0a | ||
![]() |
5dd513f79b | ||
![]() |
9b5893b07c | ||
![]() |
8bd4d7db5e | ||
![]() |
4254b181d4 | ||
![]() |
8eb9811b30 | ||
![]() |
93cfcadeef | ||
![]() |
9e61d5e636 | ||
![]() |
c112c56664 | ||
![]() |
3a1b1a591f | ||
![]() |
72be42b88f | ||
![]() |
291fea3e07 | ||
![]() |
1733ea69d5 | ||
![]() |
543998feea | ||
![]() |
e31976974c | ||
![]() |
c90991e10a | ||
![]() |
c00cdbaff7 | ||
![]() |
5e798aca6f | ||
![]() |
7107f4378c | ||
![]() |
1e04b52f5f | ||
![]() |
20be47698a | ||
![]() |
185067265c | ||
![]() |
27dbe9a75a | ||
![]() |
cafe40a4c3 | ||
![]() |
e5492f77ce | ||
![]() |
2df85a5068 | ||
![]() |
22a26580d9 | ||
![]() |
b471b92b60 | ||
![]() |
89c96ecb95 | ||
![]() |
0647dcdcb2 | ||
![]() |
11594487fb | ||
![]() |
476e944c55 | ||
![]() |
65f1a29d86 | ||
![]() |
e9b3ed308a | ||
![]() |
bfd44e1d77 | ||
![]() |
155767ea37 | ||
![]() |
70adc93a8f | ||
![]() |
9ab4111f33 | ||
![]() |
0ee949a846 | ||
![]() |
8c512677f1 | ||
![]() |
510fb8b146 | ||
![]() |
75ef3a6367 | ||
![]() |
a45d53f73c | ||
![]() |
652439226a | ||
![]() |
b31301ac1f | ||
![]() |
48e4a2c589 | ||
![]() |
58cd17158c | ||
![]() |
01893ba62b | ||
![]() |
42b1661107 | ||
![]() |
16968f445f | ||
![]() |
c10145cc93 | ||
![]() |
35ae19c3a0 | ||
![]() |
8cdbca925b | ||
![]() |
2783a69f89 | ||
![]() |
40bff028f3 | ||
![]() |
8b7a589018 | ||
![]() |
87a069863a | ||
![]() |
14ea592cd7 | ||
![]() |
54e9d2fd06 | ||
![]() |
f544f3b15a | ||
![]() |
a5480fb097 | ||
![]() |
b234ad73be | ||
![]() |
2ab8af6659 | ||
![]() |
564e95be6b | ||
![]() |
1a36fc6195 | ||
![]() |
f8b8ef54a9 | ||
![]() |
3fb7c35286 | ||
![]() |
f63bb1c6a2 | ||
![]() |
f1d7305e9d | ||
![]() |
b94d9c8637 | ||
![]() |
f7f6478fa4 | ||
![]() |
21f445ad64 | ||
![]() |
1ec8dba7e4 | ||
![]() |
1d7bc10ed9 | ||
![]() |
ac7e610510 | ||
![]() |
db193cb541 | ||
![]() |
ff7d1dbfdd | ||
![]() |
237f270708 | ||
![]() |
50b78a1458 | ||
![]() |
79c14d697e | ||
![]() |
d84d3983b8 | ||
![]() |
a210cf8661 | ||
![]() |
0d90c21dbd | ||
![]() |
7e8b65a311 | ||
![]() |
e6d7607916 | ||
![]() |
c1de919852 | ||
![]() |
7d52b06533 | ||
![]() |
829366a554 | ||
![]() |
4b14f17cc5 | ||
![]() |
f5bc526f25 | ||
![]() |
1a07e199b5 | ||
![]() |
91e9fcebf7 | ||
![]() |
871b915515 | ||
![]() |
77dcdaa482 | ||
![]() |
09806a5f93 | ||
![]() |
b5fe8f1884 | ||
![]() |
b9d65ff30f | ||
![]() |
34fbfc2ccf | ||
![]() |
bed317b109 | ||
![]() |
0156671fc8 | ||
![]() |
1f56dcc645 | ||
![]() |
14625ff7cb | ||
![]() |
69f0a9d33e | ||
![]() |
0e5aa2fb7a | ||
![]() |
bfb68bf931 | ||
![]() |
69cc2eef7d | ||
![]() |
16a7da54c2 | ||
![]() |
0aeec35935 | ||
![]() |
769ae71076 | ||
![]() |
32dd8d9f93 | ||
![]() |
fcb0e7cde4 | ||
![]() |
88d9000042 | ||
![]() |
81e93ca710 | ||
![]() |
00fb01bd7a | ||
![]() |
cae6da540f | ||
![]() |
026dc4cb98 | ||
![]() |
cf5ea374d4 | ||
![]() |
dc176e0c0e | ||
![]() |
25f74defe5 | ||
![]() |
7250656de0 | ||
![]() |
6603990fe4 | ||
![]() |
da4c7f26e6 | ||
![]() |
060dd8aced | ||
![]() |
84ebb6b24e | ||
![]() |
734a7b9566 | ||
![]() |
eb78d9df30 | ||
![]() |
fb0493a33c | ||
![]() |
04cd5bea24 | ||
![]() |
c6f6dd5f5a | ||
![]() |
0f1e697abd | ||
![]() |
a6658fa4d3 | ||
![]() |
a26c188822 | ||
![]() |
51c6c8f58f | ||
![]() |
81d8c64e98 | ||
![]() |
4e858e3949 | ||
![]() |
bf20506e09 | ||
![]() |
41c274b222 | ||
![]() |
3cfac6a5c1 | ||
![]() |
3508df01a9 | ||
![]() |
c0e57cc890 | ||
![]() |
4155c8ebcd | ||
![]() |
5949429f75 | ||
![]() |
a2d1322b60 | ||
![]() |
bb7260bc9e | ||
![]() |
91ca0efe03 | ||
![]() |
b36a6f8358 | ||
![]() |
06de527c63 | ||
![]() |
8f9d5e41b7 | ||
![]() |
2624bd9e72 | ||
![]() |
56a59e4cc3 | ||
![]() |
c4e58c3e63 | ||
![]() |
341adbae21 | ||
![]() |
feb4bcd90f | ||
![]() |
0077b6414a | ||
![]() |
489c404bbb | ||
![]() |
e467fa3e6d | ||
![]() |
ce071ad728 | ||
![]() |
5776e13385 | ||
![]() |
62f0bf7081 | ||
![]() |
1ca54b361f | ||
![]() |
4b6c177311 | ||
![]() |
7691d04de0 | ||
![]() |
a02995e357 | ||
![]() |
7c3c6bd1a9 | ||
![]() |
e097c8889e | ||
![]() |
0f2c7e0307 | ||
![]() |
cecc501255 | ||
![]() |
5a8c1e63c4 | ||
![]() |
692308837d | ||
![]() |
3b490b58cb | ||
![]() |
e77be8210f | ||
![]() |
9ed43941fd | ||
![]() |
e1f7921223 | ||
![]() |
ae133e649a | ||
![]() |
3b6ab6fb71 | ||
![]() |
75460b2427 | ||
![]() |
777e42374c | ||
![]() |
b67c226515 | ||
![]() |
5fee54b91b | ||
![]() |
1c99216e23 | ||
![]() |
eb0eab5967 | ||
![]() |
daf534edb7 | ||
![]() |
fba9a87c39 | ||
![]() |
2303db9f4f | ||
![]() |
68daabafa0 | ||
![]() |
00bae7a945 | ||
![]() |
29f80ab31b | ||
![]() |
ef7811ead9 | ||
![]() |
c3e0d6d6bb | ||
![]() |
428422d569 | ||
![]() |
1863f5bd0c |
|
@ -1,3 +1,2 @@
|
|||
https://github.com/heroku/heroku-buildpack-ruby.git
|
||||
https://github.com/drogus/last-commit-sha-buildpack.git
|
||||
https://dl.signalsciences.net/heroku/sigsci-buildpack-nginx.tgz
|
||||
https://github.com/ryandotsmith/nginx-buildpack.git
|
||||
|
|
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -4,10 +4,7 @@ config/nginx.conf
|
|||
config/skylight.yml
|
||||
|
||||
tmp/
|
||||
log/
|
||||
logs/
|
||||
!vendor/travis-core/lib/travis/logs/
|
||||
!vendor/travis-core/lib/travis/model/log/
|
||||
|
||||
.yardoc
|
||||
.coverage
|
||||
|
|
7
Gemfile
7
Gemfile
|
@ -1,14 +1,12 @@
|
|||
source 'https://rubygems.org'
|
||||
gemspec
|
||||
|
||||
ruby '2.2.3' if ENV.key?('DYNO')
|
||||
|
||||
gem 's3', github: 'travis-ci/s3'
|
||||
|
||||
gem 'travis-core', path: 'vendor'
|
||||
gem 'travis-support', github: 'travis-ci/travis-support'
|
||||
gem 'travis-amqp', github: 'travis-ci/travis-amqp'
|
||||
gem 'travis-config', '~> 0.1.0'
|
||||
gem 'travis-settings', github: 'travis-ci/travis-settings'
|
||||
gem 'travis-sidekiqs', github: 'travis-ci/travis-sidekiqs'
|
||||
|
||||
gem 'travis-yaml', github: 'travis-ci/travis-yaml'
|
||||
|
@ -22,7 +20,7 @@ gem 'sentry-raven'
|
|||
gem 'yard-sinatra', github: 'rkh/yard-sinatra'
|
||||
gem 'rack-contrib'
|
||||
gem 'rack-cache', github: 'rtomayko/rack-cache'
|
||||
gem 'rack-attack'
|
||||
gem 'rack-attack', '5.0.0.beta1'
|
||||
gem 'gh'
|
||||
gem 'bunny', '~> 0.8.0'
|
||||
gem 'dalli'
|
||||
|
@ -33,6 +31,7 @@ gem 'micro_migrations'
|
|||
gem 'simplecov'
|
||||
gem 'skylight', '~> 0.6.0.beta.1'
|
||||
gem 'stackprof'
|
||||
gem 'netaddr'
|
||||
|
||||
gem 'jemalloc'
|
||||
gem 'customerio'
|
||||
|
|
66
Gemfile.lock
66
Gemfile.lock
|
@ -45,6 +45,14 @@ GIT
|
|||
specs:
|
||||
travis-migrations (0.0.2)
|
||||
|
||||
GIT
|
||||
remote: git://github.com/travis-ci/travis-settings.git
|
||||
revision: d510e63b6c6f059cccae141c265e7a0c7236d1fd
|
||||
specs:
|
||||
travis-settings (0.0.1)
|
||||
activemodel
|
||||
virtus
|
||||
|
||||
GIT
|
||||
remote: git://github.com/travis-ci/travis-sidekiqs.git
|
||||
revision: c5d4a4abc6c3737f9c43d3333efb94daa18b9fbb
|
||||
|
@ -69,49 +77,33 @@ PATH
|
|||
remote: .
|
||||
specs:
|
||||
travis-api (0.0.1)
|
||||
composite_primary_keys (~> 5.0)
|
||||
memcachier
|
||||
mustermann (~> 0.4)
|
||||
pg
|
||||
rack-contrib (~> 1.1)
|
||||
rack-ssl (~> 1.3, >= 1.3.3)
|
||||
redcarpet (~> 2.1)
|
||||
sinatra (~> 1.3)
|
||||
sinatra-contrib (~> 1.3)
|
||||
travis-core
|
||||
travis-support
|
||||
useragent
|
||||
|
||||
PATH
|
||||
remote: vendor
|
||||
specs:
|
||||
travis-core (0.0.1)
|
||||
actionmailer (~> 3.2.19)
|
||||
activerecord (~> 3.2.19)
|
||||
coder (~> 0.4.0)
|
||||
data_migrations (~> 0.0.1)
|
||||
gh
|
||||
composite_primary_keys (~> 5.0)
|
||||
google-api-client (~> 0.9.4)
|
||||
hashr
|
||||
metriks (~> 0.9.7)
|
||||
memcachier
|
||||
multi_json
|
||||
mustermann (~> 0.4)
|
||||
pg
|
||||
pusher (~> 0.14.0)
|
||||
rack-contrib (~> 1.1)
|
||||
rack-ssl (~> 1.3, >= 1.3.3)
|
||||
railties (~> 3.2.19)
|
||||
rake
|
||||
redcarpet (~> 2.1)
|
||||
redis (~> 3.0)
|
||||
rollout (~> 1.1.0)
|
||||
s3 (~> 0.3)
|
||||
simple_states (~> 1.0.0)
|
||||
thor
|
||||
travis-config (~> 0.1.0)
|
||||
sinatra (~> 1.3)
|
||||
sinatra-contrib (~> 1.3)
|
||||
tool
|
||||
travis-support
|
||||
useragent
|
||||
virtus (~> 1.0.0)
|
||||
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
actionmailer (3.2.22.2)
|
||||
actionpack (= 3.2.22.2)
|
||||
mail (~> 2.5.4)
|
||||
actionpack (3.2.22.2)
|
||||
activemodel (= 3.2.22.2)
|
||||
activesupport (= 3.2.22.2)
|
||||
|
@ -157,9 +149,6 @@ GEM
|
|||
customerio (1.0.0)
|
||||
multi_json (~> 1.0)
|
||||
dalli (2.7.6)
|
||||
data_migrations (0.0.1)
|
||||
activerecord
|
||||
rake
|
||||
database_cleaner (0.8.0)
|
||||
descendants_tracker (0.0.4)
|
||||
thread_safe (~> 0.3, >= 0.3.1)
|
||||
|
@ -220,9 +209,6 @@ GEM
|
|||
logging (2.1.0)
|
||||
little-plugger (~> 1.1)
|
||||
multi_json (~> 1.10)
|
||||
mail (2.5.4)
|
||||
mime-types (~> 1.16)
|
||||
treetop (~> 1.4.8)
|
||||
memcachier (0.0.2)
|
||||
memoist (0.14.0)
|
||||
metaclass (0.0.4)
|
||||
|
@ -241,9 +227,9 @@ GEM
|
|||
multipart-post (2.0.0)
|
||||
net-http-persistent (2.9.4)
|
||||
net-http-pipeline (1.0.1)
|
||||
netaddr (1.5.1)
|
||||
os (0.9.6)
|
||||
pg (0.18.4)
|
||||
polyglot (0.3.5)
|
||||
proxies (0.2.1)
|
||||
pry (0.10.3)
|
||||
coderay (~> 1.1.0)
|
||||
|
@ -255,7 +241,7 @@ GEM
|
|||
pusher-signature (~> 0.1.8)
|
||||
pusher-signature (0.1.8)
|
||||
rack (1.4.7)
|
||||
rack-attack (4.4.1)
|
||||
rack-attack (5.0.0.beta1)
|
||||
rack
|
||||
rack-contrib (1.4.0)
|
||||
git-version-bump (~> 0.15)
|
||||
|
@ -348,9 +334,6 @@ GEM
|
|||
tool (0.2.3)
|
||||
travis-config (0.1.4)
|
||||
hashr (~> 0.0)
|
||||
treetop (1.4.15)
|
||||
polyglot
|
||||
polyglot (>= 0.3.1)
|
||||
tzinfo (0.3.49)
|
||||
uber (0.0.15)
|
||||
unicorn (5.1.0)
|
||||
|
@ -382,8 +365,9 @@ DEPENDENCIES
|
|||
micro_migrations
|
||||
mocha (~> 0.12)
|
||||
mustermann!
|
||||
netaddr
|
||||
pry
|
||||
rack-attack
|
||||
rack-attack (= 5.0.0.beta1)
|
||||
rack-cache!
|
||||
rack-contrib
|
||||
rake (~> 0.9.2)
|
||||
|
@ -402,8 +386,8 @@ DEPENDENCIES
|
|||
travis-amqp!
|
||||
travis-api!
|
||||
travis-config (~> 0.1.0)
|
||||
travis-core!
|
||||
travis-migrations!
|
||||
travis-settings!
|
||||
travis-sidekiqs!
|
||||
travis-support!
|
||||
travis-yaml!
|
||||
|
|
|
@ -77,5 +77,4 @@ If you have problems with Nginx because the websocket is already in use, try res
|
|||
|
||||
### API documentation
|
||||
|
||||
We use source code comments to add documentation. If the server is running, you
|
||||
can browse an HTML documentation at [`/docs`](http://localhost:5000/docs).
|
||||
v3 documentation can be found at https://developer.travis-ci.org which is a repository that can be found at https://github.com/travis-pro/developer
|
||||
|
|
56
Rakefile
56
Rakefile
|
@ -9,44 +9,26 @@ namespace :db do
|
|||
end
|
||||
end
|
||||
|
||||
begin
|
||||
require 'rspec'
|
||||
require 'rspec/core/rake_task'
|
||||
RSpec::Core::RakeTask.new(:spec)
|
||||
# begin
|
||||
# require 'rspec'
|
||||
# require 'rspec/core/rake_task'
|
||||
# RSpec::Core::RakeTask.new(:spec)
|
||||
#
|
||||
# RSpec::Core::RakeTask.new(:spec_core) do |t|
|
||||
# t.pattern = 'spec_core/**{,/*/**}/*_spec.rb'
|
||||
# end
|
||||
#
|
||||
# task :default => [:spec]
|
||||
# rescue LoadError => e
|
||||
# puts e.inspect
|
||||
# end
|
||||
|
||||
task :core_specs do
|
||||
RSpec::Core::RakeTask.new(:core_spec) do |t|
|
||||
t.pattern = 'core_specs/**{,/*/**}/*_spec.rb'
|
||||
end
|
||||
Rake::Task["core_spec"].execute
|
||||
# not sure how else to include the spec_helper
|
||||
namespace :spec do
|
||||
desc 'Run all specs'
|
||||
task :all do
|
||||
sh 'bundle exec rspec -r spec_helper spec'
|
||||
end
|
||||
|
||||
task :default => [:spec, :core_specs]
|
||||
rescue LoadError => e
|
||||
puts e.inspect
|
||||
end
|
||||
|
||||
desc "generate gemspec"
|
||||
task 'travis-api.gemspec' do
|
||||
content = File.read 'travis-api.gemspec'
|
||||
|
||||
fields = {
|
||||
authors: `git shortlog -sn`.scan(/[^\d\s].*/),
|
||||
email: `git shortlog -sne`.scan(/[^<]+@[^>]+/),
|
||||
files: `git ls-files`.split("\n").reject { |f| f =~ /^(\.|Gemfile)/ }
|
||||
}
|
||||
|
||||
fields.each do |field, values|
|
||||
updated = " s.#{field} = ["
|
||||
updated << values.map { |v| "\n %p" % v }.join(',')
|
||||
updated << "\n ]"
|
||||
content.sub!(/ s\.#{field} = \[\n( .*\n)* \]/, updated)
|
||||
end
|
||||
|
||||
File.open('travis-api.gemspec', 'w') { |f| f << content }
|
||||
end
|
||||
task default: 'travis-api.gemspec'
|
||||
|
||||
## can this be removed? what other rakefiles need to be included?
|
||||
# tasks_path = File.expand_path('../lib/tasks/*.rake', __FILE__)
|
||||
# Dir.glob(tasks_path).each { |r| import r }
|
||||
task :default => :'spec:all'
|
||||
|
|
|
@ -13,10 +13,6 @@ http {
|
|||
gzip_comp_level 2;
|
||||
gzip_min_length 512;
|
||||
|
||||
<% unless ENV['SIGSCI_ENABLED'].nil? || ENV['SIGSCI_ENABLED'].empty? %>
|
||||
include "../sigsci-module-nginx/sigsci.conf";
|
||||
<% end %>
|
||||
|
||||
server_tokens off;
|
||||
|
||||
log_format l2met 'measure#nginx.service=$request_time request_id=$http_x_request_id';
|
||||
|
|
BIN
heroku-buildpack-sigsci.tgz
Normal file
BIN
heroku-buildpack-sigsci.tgz
Normal file
Binary file not shown.
|
@ -1,34 +1,12 @@
|
|||
require 'pusher'
|
||||
require 'travis/support'
|
||||
require 'travis/support/database'
|
||||
require 'travis_core/version'
|
||||
require 'travis/redis_pool'
|
||||
require 'travis/errors'
|
||||
|
||||
# travis-core holds the central parts of the model layer used in both travis-ci
|
||||
# (i.e. the web application) as well as travis-hub (a non-rails ui-less JRuby
|
||||
# application that receives, processes and distributes messages from/to the
|
||||
# workers and issues various events like email, pusher, irc notifications and
|
||||
# so on).
|
||||
#
|
||||
# travis/model - contains ActiveRecord models that and model the main
|
||||
# parts of the domain logic (e.g. repository, build, job
|
||||
# etc.) and issue events on state changes (e.g.
|
||||
# build:created, job:test:finished etc.)
|
||||
# travis/event - contains event handlers that register for certain
|
||||
# events and send out such things as email, pusher, irc
|
||||
# notifications, archive builds or queue jobs for the
|
||||
# workers.
|
||||
# travis/mailer - contains ActionMailers for sending out email
|
||||
# notifications
|
||||
#
|
||||
# travis-core also contains some helper classes and modules like Travis::Database
|
||||
# (needed in travis-hub in order to connect to the database) and Travis::Renderer
|
||||
# (our inferior layer on top of Rabl).
|
||||
module Travis
|
||||
class << self
|
||||
def services=(services)
|
||||
# Travis.logger.info("Using services: #{services}")
|
||||
@services = services
|
||||
end
|
||||
|
||||
|
@ -40,17 +18,11 @@ module Travis
|
|||
require 'travis/model'
|
||||
require 'travis/task'
|
||||
require 'travis/event'
|
||||
require 'travis/addons'
|
||||
require 'travis/api'
|
||||
require 'travis/api/serialize'
|
||||
require 'travis/config/defaults'
|
||||
require 'travis/commit_command'
|
||||
require 'travis/enqueue'
|
||||
require 'travis/features'
|
||||
require 'travis/github'
|
||||
require 'travis/logs'
|
||||
require 'travis/mailer'
|
||||
require 'travis/notification'
|
||||
require 'travis/requests'
|
||||
require 'travis/services'
|
||||
|
||||
class UnknownRepository < StandardError; end
|
||||
|
@ -69,12 +41,8 @@ module Travis
|
|||
Travis.logger.info('Setting up Travis::Core')
|
||||
|
||||
Github.setup
|
||||
Addons.register
|
||||
Services.register
|
||||
Enqueue::Services.register
|
||||
Github::Services.register
|
||||
Logs::Services.register
|
||||
Requests::Services.register
|
||||
end
|
||||
|
||||
attr_accessor :redis, :config
|
|
@ -26,10 +26,15 @@ require 'metriks/reporter/logger'
|
|||
require 'metriks/librato_metrics_reporter'
|
||||
require 'travis/support/log_subscriber/active_record_metrics'
|
||||
require 'fileutils'
|
||||
require 'securerandom'
|
||||
|
||||
module Travis::Api
|
||||
end
|
||||
|
||||
require 'travis/api/app/endpoint'
|
||||
require 'travis/api/app/middleware'
|
||||
require 'travis/api/instruments'
|
||||
require 'travis/api/v2/http'
|
||||
require 'travis/api/serialize/v2'
|
||||
require 'travis/api/v3'
|
||||
require 'travis/api/app/stack_instrumentation'
|
||||
require 'travis/api/app/error_handling'
|
||||
|
@ -77,25 +82,20 @@ module Travis::Api
|
|||
end
|
||||
|
||||
def self.deploy_sha
|
||||
@deploy_sha ||= File.exist?(deploy_sha_path) ? File.read(deploy_sha_path)[0..7] : 'deploy-sha'
|
||||
end
|
||||
|
||||
def self.deploy_sha_path
|
||||
File.expand_path('../../../../.deploy-sha', __FILE__)
|
||||
@deploy_sha ||= ENV['HEROKU_SLUG_COMMIT'] || SecureRandom.hex(5)
|
||||
end
|
||||
|
||||
attr_accessor :app
|
||||
|
||||
def initialize
|
||||
@app = Rack::Builder.app do
|
||||
|
||||
if stackprof = ENV['STACKPROF']
|
||||
require 'stackprof'
|
||||
modes = ['wall', 'cpu', 'object', 'custom']
|
||||
mode = modes.include?(stackprof) ? stackprof.to_sym : :cpu
|
||||
Travis.logger.info "Setting up profiler: #{mode}"
|
||||
use StackProf::Middleware, enabled: true, save_every: 1, mode: mode
|
||||
end
|
||||
# if stackprof = ENV['STACKPROF']
|
||||
# require 'stackprof'
|
||||
# modes = ['wall', 'cpu', 'object', 'custom']
|
||||
# mode = modes.include?(stackprof) ? stackprof.to_sym : :cpu
|
||||
# Travis.logger.info "Setting up profiler: #{mode}"
|
||||
# use StackProf::Middleware, enabled: true, save_every: 1, mode: mode
|
||||
# end
|
||||
|
||||
extend StackInstrumentation
|
||||
use Travis::Api::App::Middleware::Skylight
|
||||
|
@ -129,7 +129,7 @@ module Travis::Api
|
|||
use Travis::Api::App::Middleware::UserAgentTracker
|
||||
|
||||
# make sure this is below ScopeCheck so we have the token
|
||||
use Rack::Attack if Endpoint.production?
|
||||
use Rack::Attack if Endpoint.production? and not Travis.config.enterprise
|
||||
|
||||
# if this is a v3 API request, ignore everything after
|
||||
use Travis::API::V3::OptIn
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
require 'travis/api/app'
|
||||
require 'addressable/uri'
|
||||
require 'faraday'
|
||||
require 'securerandom'
|
||||
require 'customerio'
|
||||
require 'travis/api/app'
|
||||
require 'travis/github/education'
|
||||
require 'travis/github/oauth'
|
||||
|
||||
class Travis::Api::App
|
||||
class Endpoint
|
||||
|
@ -112,7 +114,7 @@ class Travis::Api::App
|
|||
# access token and user payload to the parent window via postMessage.
|
||||
#
|
||||
# However, the endpoint to send the payload to has to be explicitely
|
||||
# whitelisted in production, as this is endpoint is only meant to be used
|
||||
# safelisted in production, as this is endpoint is only meant to be used
|
||||
# with the official Travis CI client at the moment.
|
||||
#
|
||||
# Example usage:
|
||||
|
@ -177,7 +179,8 @@ class Travis::Api::App
|
|||
:created_at => user.created_at.to_i,
|
||||
:github_id => user.github_id,
|
||||
:education => user.education,
|
||||
:first_logged_in_at => user.first_logged_in_at.to_i
|
||||
:first_logged_in_at => user.first_logged_in_at.to_i,
|
||||
:travis_domain => Travis.config.client_domain
|
||||
}
|
||||
|
||||
customerio.identify(payload)
|
||||
|
@ -186,7 +189,7 @@ class Travis::Api::App
|
|||
end
|
||||
|
||||
def serialize_user(user)
|
||||
rendered = Travis::Api.data(user, version: :v2)
|
||||
rendered = Travis::Api::Serialize.data(user, version: :v2)
|
||||
rendered['user'].merge('token' => user.tokens.first.try(:token).to_s)
|
||||
end
|
||||
|
||||
|
@ -287,8 +290,11 @@ class Travis::Api::App
|
|||
user.update_attributes info
|
||||
else
|
||||
self.user = ::User.create! info
|
||||
Travis.run_service(:sync_user, user)
|
||||
end
|
||||
|
||||
Travis::Github::Oauth.update_scopes(user) # unless Travis.env == 'test'
|
||||
|
||||
nullify_logins(user.github_id, user.login)
|
||||
end
|
||||
|
||||
|
@ -340,7 +346,7 @@ class Travis::Api::App
|
|||
end
|
||||
|
||||
def acceptable?(scopes, lossy = false)
|
||||
User::Oauth.wanted_scopes.all? do |scope|
|
||||
Travis::Github::Oauth.wanted_scopes.all? do |scope|
|
||||
acceptable_scopes_for(scope, lossy).any? { |s| scopes.include? s }
|
||||
end
|
||||
end
|
||||
|
@ -403,7 +409,7 @@ __END__
|
|||
|
||||
@@ invalid_target
|
||||
<script>
|
||||
console.log('refusing to send a token to <%= target_origin.inspect %>, not whitelisted!');
|
||||
console.log('refusing to send a token to <%= target_origin.inspect %>, not safelisted!');
|
||||
</script>
|
||||
|
||||
@@ common
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
require 'travis/api/app'
|
||||
require 'travis/api/workers/build_cancellation'
|
||||
require 'travis/api/workers/build_restart'
|
||||
require 'travis/api/enqueue/services/enqueue_build'
|
||||
require 'travis/api/enqueue/services/restart_model'
|
||||
require 'travis/api/enqueue/services/cancel_model'
|
||||
|
||||
class Travis::Api::App
|
||||
class Endpoint
|
||||
|
@ -21,7 +22,8 @@ class Travis::Api::App
|
|||
post '/:id/cancel' do
|
||||
Metriks.meter("api.request.cancel_build").mark
|
||||
|
||||
service = self.service(:cancel_build, params.merge(source: 'api'))
|
||||
service = Travis::Enqueue::Services::CancelModel.new(current_user, { build_id: params[:id] })
|
||||
|
||||
if !service.authorized?
|
||||
json = { error: {
|
||||
message: "You don't have access to cancel build(#{params[:id]})"
|
||||
|
@ -40,7 +42,9 @@ class Travis::Api::App
|
|||
status 422
|
||||
respond_with json
|
||||
else
|
||||
Travis::Sidekiq::BuildCancellation.perform_async(id: params[:id], user_id: current_user.id, source: 'api')
|
||||
payload = { id: params[:id], user_id: current_user.id, source: 'api' }
|
||||
|
||||
service.push("build:cancel", payload)
|
||||
|
||||
Metriks.meter("api.request.cancel_build.success").mark
|
||||
status 204
|
||||
|
@ -49,27 +53,16 @@ class Travis::Api::App
|
|||
|
||||
post '/:id/restart' do
|
||||
Metriks.meter("api.request.restart_build").mark
|
||||
if Travis::Features.owner_active?(:enqueue_to_hub, current_user)
|
||||
service = Travis::Enqueue::Services::EnqueueBuild.new(current_user, params[:id])
|
||||
if !service.accept?
|
||||
status 400
|
||||
result = false
|
||||
else
|
||||
payload = {id: params[:id], user_id: current_user.id}
|
||||
service.push("build:restart", payload)
|
||||
status 202
|
||||
result = true
|
||||
end
|
||||
service = Travis::Enqueue::Services::RestartModel.new(current_user, build_id: params[:id])
|
||||
|
||||
result = if !service.accept?
|
||||
status 400
|
||||
false
|
||||
else
|
||||
service = self.service(:reset_model, build_id: params[:id])
|
||||
if !service.accept?
|
||||
status 400
|
||||
result = false
|
||||
else
|
||||
Travis::Sidekiq::BuildRestart.perform_async(id: params[:id], user_id: current_user.id)
|
||||
status 202
|
||||
result = true
|
||||
end
|
||||
payload = { id: params[:id], user_id: current_user.id }
|
||||
service.push("build:restart", payload)
|
||||
status 202
|
||||
true
|
||||
end
|
||||
|
||||
respond_with(result: result, flash: service.messages)
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
require 'travis/api/app'
|
||||
require 'travis/api/workers/job_cancellation'
|
||||
require 'travis/api/workers/job_restart'
|
||||
require 'travis/api/enqueue/services/restart_model'
|
||||
require 'travis/api/enqueue/services/cancel_model'
|
||||
|
||||
class Travis::Api::App
|
||||
class Endpoint
|
||||
|
@ -27,7 +29,8 @@ class Travis::Api::App
|
|||
post '/:id/cancel' do
|
||||
Metriks.meter("api.request.cancel_job").mark
|
||||
|
||||
service = self.service(:cancel_job, params.merge(source: 'api'))
|
||||
service = Travis::Enqueue::Services::CancelModel.new(current_user, { job_id: params[:id] })
|
||||
|
||||
if !service.authorized?
|
||||
json = { error: {
|
||||
message: "You don't have access to cancel job(#{params[:id]})"
|
||||
|
@ -46,7 +49,8 @@ class Travis::Api::App
|
|||
status 422
|
||||
respond_with json
|
||||
else
|
||||
Travis::Sidekiq::JobCancellation.perform_async(id: params[:id], user_id: current_user.id, source: 'api')
|
||||
payload = { id: params[:id], user_id: current_user.id, source: 'api' }
|
||||
service.push("job:cancel", payload)
|
||||
|
||||
Metriks.meter("api.request.cancel_job.success").mark
|
||||
status 204
|
||||
|
@ -56,15 +60,18 @@ class Travis::Api::App
|
|||
post '/:id/restart' do
|
||||
Metriks.meter("api.request.restart_job").mark
|
||||
|
||||
service = self.service(:reset_model, job_id: params[:id])
|
||||
if !service.accept?
|
||||
service = Travis::Enqueue::Services::RestartModel.new(current_user, { job_id: params[:id] })
|
||||
|
||||
result = if !service.accept?
|
||||
status 400
|
||||
result = false
|
||||
false
|
||||
else
|
||||
Travis::Sidekiq::JobRestart.perform_async(id: params[:id], user_id: current_user.id)
|
||||
payload = {id: params[:id], user_id: current_user.id}
|
||||
service.push("job:restart", payload)
|
||||
status 202
|
||||
result = true
|
||||
true
|
||||
end
|
||||
|
||||
respond_with(result: result, flash: service.messages)
|
||||
end
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
require 'travis/api/app'
|
||||
require 'travis/api/app/services/schedule_request'
|
||||
require 'travis/api/enqueue/services/restart_model'
|
||||
|
||||
class Travis::Api::App
|
||||
class Endpoint
|
||||
|
@ -22,11 +23,22 @@ class Travis::Api::App
|
|||
status 404
|
||||
else
|
||||
# DEPRECATED: this will be removed by 1st of December
|
||||
#
|
||||
# TODO It seems this endpoint is still in use, quite a bit:
|
||||
# https://metrics.librato.com/s/metrics/api.request.restart?duration=2419200&q=api.request.restart
|
||||
#
|
||||
# I think we need to properly deprecate this by publishing a blog post.
|
||||
Metriks.meter("api.request.restart").mark
|
||||
respond_with service(:reset_model, params)
|
||||
service = Travis::Enqueue::Services::RestartModel.new(current_user, params)
|
||||
params[:user_id] = service.target.repository.owner.id
|
||||
|
||||
type = params[:build_id] ? 'build' : 'job'
|
||||
params[:id] = params[:build_id] || params[:job_id]
|
||||
|
||||
service.push("#{type}:restart", params)
|
||||
respond_with(result: true, flash: service.messages)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ module Travis::Api::App::Responders
|
|||
<updated><%= ::DateTime.parse(build.updated_at.to_s).rfc3339 %></updated>
|
||||
<summary type="html">
|
||||
<p>
|
||||
<%= build.commit.message.encode(:xml => :text) %> (<%= build.commit.committer_name %>)
|
||||
<%= build.commit.message.encode(:xml => :text) if build.commit.message %> (<%= build.commit.committer_name %>)
|
||||
<br/><br/>
|
||||
State: <%= build.state %>
|
||||
<br/>
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
require 'travis/api/serialize'
|
||||
|
||||
class Travis::Api::App
|
||||
module Responders
|
||||
class Json < Base
|
||||
|
@ -46,7 +48,7 @@ class Travis::Api::App
|
|||
if defined?(@builder)
|
||||
@builder
|
||||
else
|
||||
@builder = Travis::Api.builder(resource, { :version => version }.merge(options))
|
||||
@builder = Travis::Api::Serialize.builder(resource, { :version => version }.merge(options))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
require 'rack/attack'
|
||||
require 'netaddr'
|
||||
|
||||
class Rack::Attack
|
||||
class Request
|
||||
|
@ -25,31 +26,44 @@ class Rack::Attack
|
|||
end
|
||||
end
|
||||
|
||||
POST_WHITELISTED = [
|
||||
POST_SAFELIST = [
|
||||
"/auth/handshake",
|
||||
"/auth/post_message",
|
||||
"/auth/post_message/iframe"
|
||||
]
|
||||
|
||||
GITHUB_CIDR = NetAddr::CIDR.create('192.30.252.0/22')
|
||||
|
||||
safelist('safelist build status images') do |request|
|
||||
/\.(png|svg)$/.match(request.path)
|
||||
end
|
||||
|
||||
# https://help.github.com/articles/what-ip-addresses-does-github-use-that-i-should-safelist/
|
||||
safelist('safelist anything coming from github') do |request|
|
||||
request.ip && GITHUB_CIDR.contains?(request.ip)
|
||||
end
|
||||
|
||||
####
|
||||
# Whitelisted IP addresses
|
||||
whitelist('whitelist client requesting from redis') do |request|
|
||||
Travis.redis.sismember(:api_whitelisted_ips, request.ip)
|
||||
safelist('safelist client requesting from redis') do |request|
|
||||
# TODO: deprecate :api_whitelisted_ips in favour of api_safelisted_ips
|
||||
Travis.redis.sismember(:api_whitelisted_ips, request.ip) || Travis.redis.sismember(:api_safelisted_ips, request.ip)
|
||||
end
|
||||
|
||||
####
|
||||
# Ban based on: IP address
|
||||
# Ban time: indefinite
|
||||
# Ban after: manually banned
|
||||
blacklist('block client requesting from redis') do |request|
|
||||
Travis.redis.sismember(:api_blacklisted_ips, request.ip)
|
||||
blocklist('block client requesting from redis') do |request|
|
||||
# TODO: deprecate :api_blacklisted_ips in favour of api_blocklisted_ips
|
||||
Travis.redis.sismember(:api_blacklisted_ips, request.ip) || Travis.redis.sismember(:api_blocklisted_ips, request.ip)
|
||||
end
|
||||
|
||||
####
|
||||
# Ban based on: IP address or access token
|
||||
# Ban time: 5 hours
|
||||
# Ban after: 10 POST requests within five minutes to /auth/github
|
||||
blacklist('hammering /auth/github') do |request|
|
||||
blocklist('hammering /auth/github') do |request|
|
||||
Rack::Attack::Allow2Ban.filter(request.identifier, maxretry: 2, findtime: 5.minutes, bantime: bantime(5.hours)) do
|
||||
request.post? and request.path == '/auth/github'
|
||||
end
|
||||
|
@ -59,9 +73,9 @@ class Rack::Attack
|
|||
# Ban based on: IP address or access token
|
||||
# Ban time: 1 hour
|
||||
# Ban after: 10 POST requests within 30 seconds
|
||||
blacklist('spamming with POST requests') do |request|
|
||||
blocklist('spamming with POST requests') do |request|
|
||||
Rack::Attack::Allow2Ban.filter(request.identifier, maxretry: 10, findtime: 30.seconds, bantime: bantime(1.hour)) do
|
||||
request.post? and not POST_WHITELISTED.include? request.path
|
||||
request.post? and not POST_SAFELIST.include? request.path
|
||||
end
|
||||
end
|
||||
|
||||
|
|
59
lib/travis/api/enqueue/services/cancel_model.rb
Normal file
59
lib/travis/api/enqueue/services/cancel_model.rb
Normal file
|
@ -0,0 +1,59 @@
|
|||
module Travis
|
||||
module Enqueue
|
||||
module Services
|
||||
|
||||
class CancelModel
|
||||
|
||||
attr_reader :current_user, :target
|
||||
|
||||
def initialize(current_user, params)
|
||||
@current_user = current_user
|
||||
@params = params
|
||||
target
|
||||
end
|
||||
|
||||
def messages
|
||||
messages = []
|
||||
messages << { :notice => "The #{type} was successfully cancelled." } if can_cancel?
|
||||
messages << { :error => "You are not authorized to cancel this #{type}." } unless authorized?
|
||||
messages << { :error => "The #{type} could not be cancelled." } unless build.cancelable?
|
||||
messages
|
||||
end
|
||||
|
||||
def push(event, payload)
|
||||
# target may have been retrieved with a :join query, so we need to reset the readonly status
|
||||
if can_cancel?
|
||||
::Sidekiq::Client.push(
|
||||
'queue' => 'hub',
|
||||
'class' => 'Travis::Hub::Sidekiq::Worker',
|
||||
#'args' => ["#{type}:cancel", @params]
|
||||
'args' => [event, payload]
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
def type
|
||||
@type ||= @params[:build_id] ? :build : :job
|
||||
end
|
||||
|
||||
def target
|
||||
if type == :build
|
||||
@target = Build.find(@params[:build_id])
|
||||
else
|
||||
@target = Job.find(@params[:job_id])
|
||||
end
|
||||
end
|
||||
|
||||
def can_cancel?
|
||||
authorized? && target.cancelable?
|
||||
end
|
||||
|
||||
# check on web
|
||||
def authorized?
|
||||
current_user.permission?(:pull, :repository_id => target.repository_id)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,49 +0,0 @@
|
|||
module Travis
|
||||
module Enqueue
|
||||
module Services
|
||||
|
||||
class EnqueueBuild
|
||||
attr_reader :current_user, :build
|
||||
|
||||
def initialize(current_user, build_id)
|
||||
@current_user = current_user
|
||||
@build = Build.find(build_id)
|
||||
end
|
||||
|
||||
def push(event, payload)
|
||||
::Sidekiq::Client.push(
|
||||
'queue' => 'hub',
|
||||
'class' => 'Travis::Hub::Sidekiq::Worker',
|
||||
'args' => [event, payload]
|
||||
)
|
||||
end
|
||||
|
||||
def accept?
|
||||
current_user && permission? && resetable?
|
||||
end
|
||||
|
||||
def messages
|
||||
messages = []
|
||||
messages << { notice: "The build was successfully restarted." } if accept?
|
||||
messages << { error: 'You do not seem to have sufficient permissions.' } unless permission?
|
||||
messages << { error: "This build currently can not be restarted." } unless resetable?
|
||||
messages
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def permission?
|
||||
current_user.permission?(required_role, repository_id: build.repository_id)
|
||||
end
|
||||
|
||||
def resetable?
|
||||
build.resetable?
|
||||
end
|
||||
|
||||
def required_role
|
||||
Travis.config.roles.reset_model
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
64
lib/travis/api/enqueue/services/restart_model.rb
Normal file
64
lib/travis/api/enqueue/services/restart_model.rb
Normal file
|
@ -0,0 +1,64 @@
|
|||
module Travis
|
||||
module Enqueue
|
||||
module Services
|
||||
|
||||
class RestartModel
|
||||
attr_reader :current_user, :target
|
||||
|
||||
def initialize(current_user, params)
|
||||
@current_user = current_user
|
||||
@params = params
|
||||
target
|
||||
end
|
||||
|
||||
def push(event, payload)
|
||||
if current_user && target && accept?
|
||||
::Sidekiq::Client.push(
|
||||
'queue' => 'hub',
|
||||
'class' => 'Travis::Hub::Sidekiq::Worker',
|
||||
'args' => [event, payload]
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
def accept?
|
||||
current_user && permission? && resetable?
|
||||
end
|
||||
|
||||
def messages
|
||||
messages = []
|
||||
messages << { notice: "The #{type} was successfully restarted." } if accept?
|
||||
messages << { error: 'You do not seem to have sufficient permissions.' } unless permission?
|
||||
messages << { error: "This #{type} currently can not be restarted." } unless resetable?
|
||||
messages
|
||||
end
|
||||
|
||||
def type
|
||||
@type ||= @params[:build_id] ? :build : :job
|
||||
end
|
||||
|
||||
def target
|
||||
if type == :build
|
||||
@target = Build.find(@params[:build_id])
|
||||
else
|
||||
@target = Job.find(@params[:job_id])
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def permission?
|
||||
current_user.permission?(required_role, repository_id: target.repository_id)
|
||||
end
|
||||
|
||||
def resetable?
|
||||
target.resetable?
|
||||
end
|
||||
|
||||
def required_role
|
||||
Travis.config.roles.reset_model
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
68
lib/travis/api/serialize.rb
Normal file
68
lib/travis/api/serialize.rb
Normal file
|
@ -0,0 +1,68 @@
|
|||
require 'travis/api/serialize/formats'
|
||||
require 'travis/api/serialize/v0'
|
||||
require 'travis/api/serialize/v1'
|
||||
|
||||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
DEFAULT_VERSION = 'v2'
|
||||
|
||||
class << self
|
||||
def data(resource, options = {})
|
||||
new(resource, options).data
|
||||
end
|
||||
|
||||
def builder(resource, options = {})
|
||||
target = (options[:for] || 'http').to_s.camelize
|
||||
version = (options[:version] || default_version(options)).to_s.camelize
|
||||
type = (options[:type] || type_for(resource)).to_s.camelize.split('::')
|
||||
([version, target] + type).inject(self) do |const, name|
|
||||
begin
|
||||
if const && const.const_defined?(name.to_s.camelize, false)
|
||||
const.const_get(name, false)
|
||||
else
|
||||
nil
|
||||
end
|
||||
rescue NameError
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def new(resource, options = {})
|
||||
builder = builder(resource, options) || raise(ArgumentError, "cannot serialize #{resource.inspect}, options: #{options.inspect}")
|
||||
builder.new(resource, options[:params] || {})
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def type_for(resource)
|
||||
if arel_relation?(resource)
|
||||
type = resource.klass.name.pluralize
|
||||
else
|
||||
type = resource.class
|
||||
type = type.base_class if active_record?(type)
|
||||
type = type.name
|
||||
end
|
||||
type.split('::').last
|
||||
end
|
||||
|
||||
def arel_relation?(object)
|
||||
object.respond_to?(:klass)
|
||||
end
|
||||
|
||||
def active_record?(object)
|
||||
object.respond_to?(:base_class)
|
||||
end
|
||||
|
||||
def default_version(options)
|
||||
if options[:for].to_s.downcase == "pusher"
|
||||
"v0"
|
||||
else
|
||||
DEFAULT_VERSION
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
11
lib/travis/api/serialize/formats.rb
Normal file
11
lib/travis/api/serialize/formats.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
module Formats
|
||||
def format_date(date)
|
||||
date && date.strftime('%Y-%m-%dT%H:%M:%SZ')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
25
lib/travis/api/serialize/serializer.rb
Normal file
25
lib/travis/api/serialize/serializer.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
require 'active_model_serializers'
|
||||
|
||||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
class ObjectSerializer < ActiveModel::Serializer
|
||||
def data
|
||||
as_json
|
||||
end
|
||||
end
|
||||
|
||||
class ArraySerializer < ActiveModel::ArraySerializer
|
||||
def data
|
||||
as_json
|
||||
end
|
||||
|
||||
def initialize(resource, options)
|
||||
options[:each_serializer] ||= V2::Http.const_get(options[:root].to_s.singularize.camelize)
|
||||
super(resource, options)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
6
lib/travis/api/serialize/v0.rb
Normal file
6
lib/travis/api/serialize/v0.rb
Normal file
|
@ -0,0 +1,6 @@
|
|||
# V0 is an internal api that we can change at any time
|
||||
|
||||
require 'travis/api/serialize/v0/event'
|
||||
require 'travis/api/serialize/v0/notification'
|
||||
require 'travis/api/serialize/v0/pusher'
|
||||
require 'travis/api/serialize/v0/worker'
|
2
lib/travis/api/serialize/v0/event.rb
Normal file
2
lib/travis/api/serialize/v0/event.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
require 'travis/api/serialize/v0/event/build'
|
||||
require 'travis/api/serialize/v0/event/job'
|
96
lib/travis/api/serialize/v0/event/build.rb
Normal file
96
lib/travis/api/serialize/v0/event/build.rb
Normal file
|
@ -0,0 +1,96 @@
|
|||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
module V0
|
||||
module Event
|
||||
class Build
|
||||
include Formats
|
||||
|
||||
attr_reader :build, :repository, :request, :commit, :options
|
||||
|
||||
def initialize(build, options = {})
|
||||
@build = build
|
||||
@repository = build.repository
|
||||
@request = build.request
|
||||
@commit = build.commit
|
||||
# @options = options
|
||||
end
|
||||
|
||||
def data(extra = {})
|
||||
{
|
||||
'repository' => repository_data,
|
||||
'request' => request_data,
|
||||
'commit' => commit_data,
|
||||
'build' => build_data,
|
||||
'jobs' => build.matrix.map { |job| job_data(job) }
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def build_data
|
||||
{
|
||||
'id' => build.id,
|
||||
'repository_id' => build.repository_id,
|
||||
'commit_id' => build.commit_id,
|
||||
'number' => build.number,
|
||||
'pull_request' => build.pull_request?,
|
||||
'pull_request_number' => build.pull_request_number,
|
||||
'config' => build.config.try(:except, :source_key),
|
||||
'state' => build.state.to_s,
|
||||
'previous_state' => build.previous_state.to_s,
|
||||
'started_at' => format_date(build.started_at),
|
||||
'finished_at' => format_date(build.finished_at),
|
||||
'duration' => build.duration,
|
||||
'job_ids' => build.matrix_ids
|
||||
}
|
||||
end
|
||||
|
||||
def repository_data
|
||||
{
|
||||
'id' => repository.id,
|
||||
'key' => repository.key.try(:public_key),
|
||||
'slug' => repository.slug,
|
||||
'name' => repository.name,
|
||||
'owner_email' => repository.owner_email,
|
||||
'owner_avatar_url' => repository.owner.try(:avatar_url)
|
||||
}
|
||||
end
|
||||
|
||||
def request_data
|
||||
{
|
||||
'token' => request.token,
|
||||
'head_commit' => (request.head_commit || '')
|
||||
}
|
||||
end
|
||||
|
||||
def commit_data
|
||||
{
|
||||
'id' => commit.id,
|
||||
'sha' => commit.commit,
|
||||
'branch' => commit.branch,
|
||||
'message' => commit.message,
|
||||
'committed_at' => format_date(commit.committed_at),
|
||||
'author_name' => commit.author_name,
|
||||
'author_email' => commit.author_email,
|
||||
'committer_name' => commit.committer_name,
|
||||
'committer_email' => commit.committer_email,
|
||||
'compare_url' => commit.compare_url,
|
||||
}
|
||||
end
|
||||
|
||||
def job_data(job)
|
||||
{
|
||||
'id' => job.id,
|
||||
'number' => job.number,
|
||||
'state' => job.state.to_s,
|
||||
'tags' => job.tags
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
37
lib/travis/api/serialize/v0/event/job.rb
Normal file
37
lib/travis/api/serialize/v0/event/job.rb
Normal file
|
@ -0,0 +1,37 @@
|
|||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
module V0
|
||||
module Event
|
||||
class Job
|
||||
include Formats
|
||||
|
||||
attr_reader :job
|
||||
|
||||
def initialize(job, options = {})
|
||||
@job = job
|
||||
# @options = options
|
||||
end
|
||||
|
||||
def data(extra = {})
|
||||
{
|
||||
'job' => job_data,
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def job_data
|
||||
{
|
||||
'queue' => job.queue,
|
||||
'created_at' => job.created_at,
|
||||
'started_at' => job.started_at,
|
||||
'finished_at' => job.finished_at,
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
3
lib/travis/api/serialize/v0/notification.rb
Normal file
3
lib/travis/api/serialize/v0/notification.rb
Normal file
|
@ -0,0 +1,3 @@
|
|||
require 'travis/api/serialize/v0/notification/build'
|
||||
require 'travis/api/serialize/v0/notification/repository'
|
||||
require 'travis/api/serialize/v0/notification/user'
|
29
lib/travis/api/serialize/v0/notification/build.rb
Normal file
29
lib/travis/api/serialize/v0/notification/build.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
module V0
|
||||
module Notification
|
||||
class Build
|
||||
attr_reader :build
|
||||
|
||||
def initialize(build, options = {})
|
||||
@build = build
|
||||
end
|
||||
|
||||
def data
|
||||
{
|
||||
'build' => build_data
|
||||
}
|
||||
end
|
||||
|
||||
def build_data
|
||||
{
|
||||
'id' => build.id
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
30
lib/travis/api/serialize/v0/notification/repository.rb
Normal file
30
lib/travis/api/serialize/v0/notification/repository.rb
Normal file
|
@ -0,0 +1,30 @@
|
|||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
module V0
|
||||
module Notification
|
||||
class Repository
|
||||
attr_reader :repository
|
||||
|
||||
def initialize(repository, options = {})
|
||||
@repository = repository
|
||||
end
|
||||
|
||||
def data
|
||||
{
|
||||
'repository' => repository_data
|
||||
}
|
||||
end
|
||||
|
||||
def repository_data
|
||||
{
|
||||
'id' => repository.id,
|
||||
'slug' => repository.slug
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
30
lib/travis/api/serialize/v0/notification/user.rb
Normal file
30
lib/travis/api/serialize/v0/notification/user.rb
Normal file
|
@ -0,0 +1,30 @@
|
|||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
module V0
|
||||
module Notification
|
||||
class User
|
||||
attr_reader :user
|
||||
|
||||
def initialize(user, options = {})
|
||||
@user = user
|
||||
end
|
||||
|
||||
def data
|
||||
{
|
||||
'user' => user_data
|
||||
}
|
||||
end
|
||||
|
||||
def user_data
|
||||
{
|
||||
'id' => user.id,
|
||||
'login' => user.login
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
3
lib/travis/api/serialize/v0/pusher.rb
Normal file
3
lib/travis/api/serialize/v0/pusher.rb
Normal file
|
@ -0,0 +1,3 @@
|
|||
require 'travis/api/serialize/v0/pusher/annotation'
|
||||
require 'travis/api/serialize/v0/pusher/build'
|
||||
require 'travis/api/serialize/v0/pusher/job'
|
35
lib/travis/api/serialize/v0/pusher/annotation.rb
Normal file
35
lib/travis/api/serialize/v0/pusher/annotation.rb
Normal file
|
@ -0,0 +1,35 @@
|
|||
require 'travis/api/serialize/v0/pusher/annotation/created'
|
||||
require 'travis/api/serialize/v0/pusher/annotation/updated'
|
||||
|
||||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
module V0
|
||||
module Pusher
|
||||
class Annotation
|
||||
include Formats
|
||||
|
||||
attr_reader :annotation
|
||||
|
||||
def initialize(annotation, options = {})
|
||||
@annotation = annotation
|
||||
end
|
||||
|
||||
def data
|
||||
{
|
||||
"annotation" => {
|
||||
"id" => annotation.id,
|
||||
"job_id" => annotation.job_id,
|
||||
"description" => annotation.description,
|
||||
"url" => annotation.url,
|
||||
"status" => annotation.status,
|
||||
"provider_name" => annotation.annotation_provider.name,
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
14
lib/travis/api/serialize/v0/pusher/annotation/created.rb
Normal file
14
lib/travis/api/serialize/v0/pusher/annotation/created.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
module V0
|
||||
module Pusher
|
||||
class Annotation
|
||||
class Created < Annotation
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
14
lib/travis/api/serialize/v0/pusher/annotation/updated.rb
Normal file
14
lib/travis/api/serialize/v0/pusher/annotation/updated.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
module V0
|
||||
module Pusher
|
||||
class Annotation
|
||||
class Updated < Annotation
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
112
lib/travis/api/serialize/v0/pusher/build.rb
Normal file
112
lib/travis/api/serialize/v0/pusher/build.rb
Normal file
|
@ -0,0 +1,112 @@
|
|||
require 'travis/api/serialize/v0/pusher/build/canceled'
|
||||
require 'travis/api/serialize/v0/pusher/build/created'
|
||||
require 'travis/api/serialize/v0/pusher/build/received'
|
||||
require 'travis/api/serialize/v0/pusher/build/started'
|
||||
require 'travis/api/serialize/v0/pusher/build/finished'
|
||||
|
||||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
module V0
|
||||
module Pusher
|
||||
class Build
|
||||
include Formats
|
||||
|
||||
attr_reader :build, :options
|
||||
|
||||
def initialize(build, options = {})
|
||||
@build = build
|
||||
@options = options
|
||||
end
|
||||
|
||||
def data
|
||||
{
|
||||
'build' => build_data(build),
|
||||
'commit' => commit_data(build.commit),
|
||||
'repository' => repository_data(build.repository)
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def build_data(build)
|
||||
commit = build.commit
|
||||
{
|
||||
'id' => build.id,
|
||||
'repository_id' => build.repository_id,
|
||||
'commit_id' => build.commit_id,
|
||||
'number' => build.number,
|
||||
'pull_request' => build.pull_request?,
|
||||
'pull_request_title' => build.pull_request_title,
|
||||
'pull_request_number' => build.pull_request_number,
|
||||
'state' => build.state.to_s,
|
||||
'started_at' => format_date(build.started_at),
|
||||
'finished_at' => format_date(build.finished_at),
|
||||
'duration' => build.duration,
|
||||
'job_ids' => build.matrix_ids,
|
||||
'event_type' => build.event_type,
|
||||
|
||||
# this is a legacy thing, we should think about removing it
|
||||
'commit' => commit.commit,
|
||||
'branch' => commit.branch,
|
||||
'message' => commit.message,
|
||||
'compare_url' => commit.compare_url,
|
||||
'committed_at' => format_date(commit.committed_at),
|
||||
'author_name' => commit.author_name,
|
||||
'author_email' => commit.author_email,
|
||||
'committer_name' => commit.committer_name,
|
||||
'committer_email' => commit.committer_email
|
||||
}
|
||||
end
|
||||
|
||||
def commit_data(commit)
|
||||
{
|
||||
'id' => commit.id,
|
||||
'sha' => commit.commit,
|
||||
'branch' => commit.branch,
|
||||
'message' => commit.message,
|
||||
'committed_at' => format_date(commit.committed_at),
|
||||
'author_name' => commit.author_name,
|
||||
'author_email' => commit.author_email,
|
||||
'committer_name' => commit.committer_name,
|
||||
'committer_email' => commit.committer_email,
|
||||
'compare_url' => commit.compare_url,
|
||||
}
|
||||
end
|
||||
|
||||
def repository_data(repository)
|
||||
{
|
||||
'id' => repository.id,
|
||||
'slug' => repository.slug,
|
||||
'description' => repository.description,
|
||||
'private' => repository.private,
|
||||
'last_build_id' => repository.last_build_id,
|
||||
'last_build_number' => repository.last_build_number,
|
||||
'last_build_state' => repository.last_build_state.to_s,
|
||||
'last_build_duration' => repository.last_build_duration,
|
||||
'last_build_language' => nil,
|
||||
'last_build_started_at' => format_date(repository.last_build_started_at),
|
||||
'last_build_finished_at' => format_date(repository.last_build_finished_at),
|
||||
'github_language' => repository.github_language,
|
||||
'default_branch' => {
|
||||
'name' => repository.default_branch,
|
||||
'last_build_id' => last_build_on_default_branch_id(repository)
|
||||
},
|
||||
'active' => repository.active,
|
||||
'current_build_id' => repository.current_build_id
|
||||
}
|
||||
end
|
||||
|
||||
def last_build_on_default_branch_id(repository)
|
||||
default_branch = Branch.where(repository_id: repository.id, name: repository.default_branch).first
|
||||
|
||||
if default_branch
|
||||
default_branch.last_build_id
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
14
lib/travis/api/serialize/v0/pusher/build/canceled.rb
Normal file
14
lib/travis/api/serialize/v0/pusher/build/canceled.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
module V0
|
||||
module Pusher
|
||||
class Build
|
||||
class Canceled < Build
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
14
lib/travis/api/serialize/v0/pusher/build/created.rb
Normal file
14
lib/travis/api/serialize/v0/pusher/build/created.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
module V0
|
||||
module Pusher
|
||||
class Build
|
||||
class Created < Build
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
14
lib/travis/api/serialize/v0/pusher/build/finished.rb
Normal file
14
lib/travis/api/serialize/v0/pusher/build/finished.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
module V0
|
||||
module Pusher
|
||||
class Build
|
||||
class Finished < Build
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
14
lib/travis/api/serialize/v0/pusher/build/received.rb
Normal file
14
lib/travis/api/serialize/v0/pusher/build/received.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
module V0
|
||||
module Pusher
|
||||
class Build
|
||||
class Received < Build
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
49
lib/travis/api/serialize/v0/pusher/build/received/job.rb
Normal file
49
lib/travis/api/serialize/v0/pusher/build/received/job.rb
Normal file
|
@ -0,0 +1,49 @@
|
|||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
module V0
|
||||
module Pusher
|
||||
class Build
|
||||
class Received < Build
|
||||
class Job
|
||||
include Formats, V1::Helpers::Legacy
|
||||
|
||||
attr_reader :job, :commit
|
||||
|
||||
def initialize(job)
|
||||
@job = job
|
||||
@commit = job.commit
|
||||
end
|
||||
|
||||
def data
|
||||
{
|
||||
'id' => job.id,
|
||||
'repository_id' => job.repository_id,
|
||||
'repository_private' => repository.private,
|
||||
'parent_id' => job.source_id,
|
||||
'number' => job.number,
|
||||
'state' => job.state.to_s,
|
||||
'result' => legacy_job_result(job),
|
||||
'config' => job.obfuscated_config,
|
||||
'commit' => commit.commit,
|
||||
'branch' => commit.branch,
|
||||
'message' => commit.message,
|
||||
'compare_url' => commit.compare_url,
|
||||
'started_at' => format_date(job.started_at),
|
||||
'finished_at' => format_date(job.finished_at),
|
||||
'committed_at' => format_date(commit.committed_at),
|
||||
'author_name' => commit.author_name,
|
||||
'author_email' => commit.author_email,
|
||||
'committer_name' => commit.committer_name,
|
||||
'committer_email' => commit.committer_email,
|
||||
'allow_failure' => job.allow_failure
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
14
lib/travis/api/serialize/v0/pusher/build/started.rb
Normal file
14
lib/travis/api/serialize/v0/pusher/build/started.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
module V0
|
||||
module Pusher
|
||||
class Build
|
||||
class Started < Build
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
49
lib/travis/api/serialize/v0/pusher/build/started/job.rb
Normal file
49
lib/travis/api/serialize/v0/pusher/build/started/job.rb
Normal file
|
@ -0,0 +1,49 @@
|
|||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
module V0
|
||||
module Pusher
|
||||
class Build
|
||||
class Started < Build
|
||||
class Job
|
||||
include Formats, V1::Helpers::Legacy
|
||||
|
||||
attr_reader :job, :commit
|
||||
|
||||
def initialize(job)
|
||||
@job = job
|
||||
@commit = job.commit
|
||||
end
|
||||
|
||||
def data
|
||||
{
|
||||
'id' => job.id,
|
||||
'repository_id' => job.repository_id,
|
||||
'repository_private' => repository.private,
|
||||
'parent_id' => job.source_id,
|
||||
'number' => job.number,
|
||||
'state' => job.state.to_s,
|
||||
'result' => legacy_job_result(job),
|
||||
'config' => job.obfuscated_config,
|
||||
'commit' => commit.commit,
|
||||
'branch' => commit.branch,
|
||||
'message' => commit.message,
|
||||
'compare_url' => commit.compare_url,
|
||||
'started_at' => format_date(job.started_at),
|
||||
'finished_at' => format_date(job.finished_at),
|
||||
'committed_at' => format_date(commit.committed_at),
|
||||
'author_name' => commit.author_name,
|
||||
'author_email' => commit.author_email,
|
||||
'committer_name' => commit.committer_name,
|
||||
'committer_email' => commit.committer_email,
|
||||
'allow_failure' => job.allow_failure
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
69
lib/travis/api/serialize/v0/pusher/job.rb
Normal file
69
lib/travis/api/serialize/v0/pusher/job.rb
Normal file
|
@ -0,0 +1,69 @@
|
|||
require 'travis/api/serialize/v0/pusher/job/canceled'
|
||||
require 'travis/api/serialize/v0/pusher/job/created'
|
||||
require 'travis/api/serialize/v0/pusher/job/log'
|
||||
require 'travis/api/serialize/v0/pusher/job/received'
|
||||
require 'travis/api/serialize/v0/pusher/job/started'
|
||||
require 'travis/api/serialize/v0/pusher/job/finished'
|
||||
|
||||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
module V0
|
||||
module Pusher
|
||||
class Job
|
||||
include Formats
|
||||
|
||||
attr_reader :job, :options
|
||||
|
||||
def initialize(job, options = {})
|
||||
@job = job
|
||||
@options = options
|
||||
end
|
||||
|
||||
def data
|
||||
job_data(job).merge(
|
||||
'commit' => commit_data(job.commit)
|
||||
)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def job_data(job)
|
||||
{
|
||||
'id' => job.id,
|
||||
'repository_id' => job.repository_id,
|
||||
'repository_slug' => job.repository.slug,
|
||||
'repository_private' => job.repository.private,
|
||||
'build_id' => job.source_id,
|
||||
'commit_id' => job.commit_id,
|
||||
'log_id' => job.log_id,
|
||||
'number' => job.number,
|
||||
'state' => job.state.to_s,
|
||||
'started_at' => format_date(job.started_at),
|
||||
'finished_at' => format_date(job.finished_at),
|
||||
'queue' => job.queue,
|
||||
'allow_failure' => job.allow_failure,
|
||||
'annotation_ids' => job.annotation_ids
|
||||
}
|
||||
end
|
||||
|
||||
def commit_data(commit)
|
||||
{
|
||||
'id' => commit.id,
|
||||
'sha' => commit.commit,
|
||||
'branch' => commit.branch,
|
||||
'message' => commit.message,
|
||||
'committed_at' => format_date(commit.committed_at),
|
||||
'author_name' => commit.author_name,
|
||||
'author_email' => commit.author_email,
|
||||
'committer_name' => commit.committer_name,
|
||||
'committer_email' => commit.committer_email,
|
||||
'compare_url' => commit.compare_url,
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
14
lib/travis/api/serialize/v0/pusher/job/canceled.rb
Normal file
14
lib/travis/api/serialize/v0/pusher/job/canceled.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
module V0
|
||||
module Pusher
|
||||
class Job
|
||||
class Canceled < Job
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
14
lib/travis/api/serialize/v0/pusher/job/created.rb
Normal file
14
lib/travis/api/serialize/v0/pusher/job/created.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
module V0
|
||||
module Pusher
|
||||
class Job
|
||||
class Created < Job
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
14
lib/travis/api/serialize/v0/pusher/job/finished.rb
Normal file
14
lib/travis/api/serialize/v0/pusher/job/finished.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
module V0
|
||||
module Pusher
|
||||
class Job
|
||||
class Finished < Job
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
32
lib/travis/api/serialize/v0/pusher/job/log.rb
Normal file
32
lib/travis/api/serialize/v0/pusher/job/log.rb
Normal file
|
@ -0,0 +1,32 @@
|
|||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
module V0
|
||||
module Pusher
|
||||
class Job
|
||||
class Log
|
||||
attr_reader :job, :options
|
||||
|
||||
def initialize(job, options = {})
|
||||
@job = job
|
||||
@options = options
|
||||
end
|
||||
|
||||
def data
|
||||
{
|
||||
'id' => job.id,
|
||||
'build_id' => job.source_id,
|
||||
'repository_id' => job.repository_id,
|
||||
'repository_private' => repository.private,
|
||||
'_log' => options[:_log],
|
||||
'number' => options[:number],
|
||||
'final' => options[:final]
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
14
lib/travis/api/serialize/v0/pusher/job/received.rb
Normal file
14
lib/travis/api/serialize/v0/pusher/job/received.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
module V0
|
||||
module Pusher
|
||||
class Job
|
||||
class Received < Job
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
14
lib/travis/api/serialize/v0/pusher/job/started.rb
Normal file
14
lib/travis/api/serialize/v0/pusher/job/started.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
module V0
|
||||
module Pusher
|
||||
class Job
|
||||
class Started < Job
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
1
lib/travis/api/serialize/v0/worker.rb
Normal file
1
lib/travis/api/serialize/v0/worker.rb
Normal file
|
@ -0,0 +1 @@
|
|||
require 'travis/api/serialize/v0/worker/job'
|
35
lib/travis/api/serialize/v0/worker/job.rb
Normal file
35
lib/travis/api/serialize/v0/worker/job.rb
Normal file
|
@ -0,0 +1,35 @@
|
|||
require 'travis/api/serialize/v0/worker/job/test'
|
||||
|
||||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
module V0
|
||||
module Worker
|
||||
class Job
|
||||
attr_reader :job
|
||||
|
||||
def initialize(job, options = {})
|
||||
@job = job
|
||||
end
|
||||
|
||||
def commit
|
||||
job.commit
|
||||
end
|
||||
|
||||
def repository
|
||||
job.repository
|
||||
end
|
||||
|
||||
def request
|
||||
build.request
|
||||
end
|
||||
|
||||
def build
|
||||
job.source
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
120
lib/travis/api/serialize/v0/worker/job/test.rb
Normal file
120
lib/travis/api/serialize/v0/worker/job/test.rb
Normal file
|
@ -0,0 +1,120 @@
|
|||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
module V0
|
||||
module Worker
|
||||
class Job
|
||||
class Test < Job
|
||||
include Formats
|
||||
|
||||
def data
|
||||
{
|
||||
'type' => 'test',
|
||||
# TODO legacy. remove this once workers respond to a 'job' key
|
||||
'build' => job_data,
|
||||
'job' => job_data,
|
||||
'source' => build_data,
|
||||
'repository' => repository_data,
|
||||
'pull_request' => commit.pull_request? ? pull_request_data : false,
|
||||
'config' => job.decrypted_config,
|
||||
'queue' => job.queue,
|
||||
'uuid' => Travis.uuid,
|
||||
'ssh_key' => ssh_key,
|
||||
'env_vars' => env_vars,
|
||||
'timeouts' => timeouts
|
||||
}
|
||||
end
|
||||
|
||||
def build_data
|
||||
{
|
||||
'id' => build.id,
|
||||
'number' => build.number
|
||||
}
|
||||
end
|
||||
|
||||
def job_data
|
||||
data = {
|
||||
'id' => job.id,
|
||||
'number' => job.number,
|
||||
'commit' => commit.commit,
|
||||
'commit_range' => commit.range,
|
||||
'commit_message' => commit.message,
|
||||
'branch' => commit.branch,
|
||||
'ref' => commit.pull_request? ? commit.ref : nil,
|
||||
'state' => job.state.to_s,
|
||||
'secure_env_enabled' => job.secure_env_enabled?
|
||||
}
|
||||
data['tag'] = request.tag_name if include_tag_name?
|
||||
data['pull_request'] = commit.pull_request? ? commit.pull_request_number : false
|
||||
data
|
||||
end
|
||||
|
||||
def repository_data
|
||||
{
|
||||
'id' => repository.id,
|
||||
'slug' => repository.slug,
|
||||
'github_id' => repository.github_id,
|
||||
'source_url' => repository.source_url,
|
||||
'api_url' => repository.api_url,
|
||||
'last_build_id' => repository.last_build_id,
|
||||
'last_build_number' => repository.last_build_number,
|
||||
'last_build_started_at' => format_date(repository.last_build_started_at),
|
||||
'last_build_finished_at' => format_date(repository.last_build_finished_at),
|
||||
'last_build_duration' => repository.last_build_duration,
|
||||
'last_build_state' => repository.last_build_state.to_s,
|
||||
'description' => repository.description,
|
||||
'default_branch' => repository.default_branch
|
||||
}
|
||||
end
|
||||
|
||||
def pull_request_data
|
||||
{
|
||||
'number' => commit.pull_request_number,
|
||||
'head_repo' => request.head_repo,
|
||||
'base_repo' => request.base_repo,
|
||||
'head_branch' => request.head_branch,
|
||||
'base_branch' => request.base_branch
|
||||
}
|
||||
end
|
||||
|
||||
def ssh_key
|
||||
nil
|
||||
end
|
||||
|
||||
def env_vars
|
||||
vars = settings.env_vars
|
||||
vars = vars.public unless job.secure_env_enabled?
|
||||
|
||||
vars.map do |var|
|
||||
{
|
||||
'name' => var.name,
|
||||
'value' => var.value.decrypt,
|
||||
'public' => var.public
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def timeouts
|
||||
{ 'hard_limit' => timeout(:hard_limit), 'log_silence' => timeout(:log_silence) }
|
||||
end
|
||||
|
||||
def timeout(type)
|
||||
timeout = settings.send(:"timeout_#{type}")
|
||||
timeout = timeout * 60 if timeout # worker handles timeouts in seconds
|
||||
timeout
|
||||
end
|
||||
|
||||
def include_tag_name?
|
||||
Travis.config.include_tag_name_in_worker_payload && request.tag_name.present?
|
||||
end
|
||||
|
||||
def settings
|
||||
repository.settings
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
4
lib/travis/api/serialize/v1.rb
Normal file
4
lib/travis/api/serialize/v1.rb
Normal file
|
@ -0,0 +1,4 @@
|
|||
require 'travis/api/serialize/v1/archive'
|
||||
require 'travis/api/serialize/v1/http'
|
||||
require 'travis/api/serialize/v1/helpers'
|
||||
require 'travis/api/serialize/v1/webhook'
|
1
lib/travis/api/serialize/v1/archive.rb
Normal file
1
lib/travis/api/serialize/v1/archive.rb
Normal file
|
@ -0,0 +1 @@
|
|||
require 'travis/api/serialize/v1/archive/build'
|
52
lib/travis/api/serialize/v1/archive/build.rb
Normal file
52
lib/travis/api/serialize/v1/archive/build.rb
Normal file
|
@ -0,0 +1,52 @@
|
|||
require 'travis/api/serialize/v1/archive/build/job'
|
||||
|
||||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
module V1
|
||||
module Archive
|
||||
class Build
|
||||
include Formats
|
||||
|
||||
attr_reader :build, :commit, :repository
|
||||
|
||||
def initialize(build, options = {})
|
||||
@build = build
|
||||
@commit = build.commit
|
||||
@repository = build.repository
|
||||
end
|
||||
|
||||
def data
|
||||
{
|
||||
'id' => build.id,
|
||||
'number' => build.number,
|
||||
'config' => build.obfuscated_config.stringify_keys,
|
||||
'result' => 0,
|
||||
'started_at' => format_date(build.started_at),
|
||||
'finished_at' => format_date(build.finished_at),
|
||||
'duration' => build.duration,
|
||||
'commit' => commit.commit,
|
||||
'branch' => commit.branch,
|
||||
'message' => commit.message,
|
||||
'committed_at' => format_date(commit.committed_at),
|
||||
'author_name' => commit.author_name,
|
||||
'author_email' => commit.author_email,
|
||||
'committer_name' => commit.committer_name,
|
||||
'committer_email' => commit.committer_email,
|
||||
'matrix' => build.matrix.map { |job| Job.new(job).data },
|
||||
'repository' => repository_data
|
||||
}
|
||||
end
|
||||
|
||||
def repository_data
|
||||
{
|
||||
'id' => repository.id,
|
||||
'slug' => repository.slug
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
33
lib/travis/api/serialize/v1/archive/build/job.rb
Normal file
33
lib/travis/api/serialize/v1/archive/build/job.rb
Normal file
|
@ -0,0 +1,33 @@
|
|||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
module V1
|
||||
module Archive
|
||||
class Build
|
||||
class Job
|
||||
include Formats
|
||||
|
||||
attr_reader :job, :commit
|
||||
|
||||
def initialize(job)
|
||||
@job = job
|
||||
@commit = job.commit
|
||||
end
|
||||
|
||||
def data
|
||||
{
|
||||
'id' => job.id,
|
||||
'number' => job.number,
|
||||
'config' => job.obfuscated_config,
|
||||
'started_at' => format_date(job.started_at),
|
||||
'finished_at' => format_date(job.finished_at),
|
||||
'log' => job.log_content
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
1
lib/travis/api/serialize/v1/helpers.rb
Normal file
1
lib/travis/api/serialize/v1/helpers.rb
Normal file
|
@ -0,0 +1 @@
|
|||
require 'travis/api/serialize/v1/helpers/legacy'
|
36
lib/travis/api/serialize/v1/helpers/legacy.rb
Normal file
36
lib/travis/api/serialize/v1/helpers/legacy.rb
Normal file
|
@ -0,0 +1,36 @@
|
|||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
module V1
|
||||
module Helpers
|
||||
module Legacy
|
||||
RESULTS = {
|
||||
passed: 0,
|
||||
failed: 1
|
||||
}
|
||||
|
||||
def legacy_repository_last_build_result(repository)
|
||||
RESULTS[repository.last_build_state.try(:to_sym)]
|
||||
end
|
||||
|
||||
def legacy_build_state(build)
|
||||
build.finished? ? 'finished' : build.state.to_s
|
||||
end
|
||||
|
||||
def legacy_build_result(build)
|
||||
RESULTS[build.state.try(:to_sym)]
|
||||
end
|
||||
|
||||
def legacy_job_state(job)
|
||||
job.finished? ? 'finished' : job.state.to_s
|
||||
end
|
||||
|
||||
def legacy_job_result(job)
|
||||
RESULTS[job.state.try(:to_sym)]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
9
lib/travis/api/serialize/v1/http.rb
Normal file
9
lib/travis/api/serialize/v1/http.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
require 'travis/api/serialize/v1/http/branches'
|
||||
require 'travis/api/serialize/v1/http/build'
|
||||
require 'travis/api/serialize/v1/http/builds'
|
||||
require 'travis/api/serialize/v1/http/hooks'
|
||||
require 'travis/api/serialize/v1/http/job'
|
||||
require 'travis/api/serialize/v1/http/jobs'
|
||||
require 'travis/api/serialize/v1/http/repositories'
|
||||
require 'travis/api/serialize/v1/http/repository'
|
||||
require 'travis/api/serialize/v1/http/user'
|
45
lib/travis/api/serialize/v1/http/branches.rb
Normal file
45
lib/travis/api/serialize/v1/http/branches.rb
Normal file
|
@ -0,0 +1,45 @@
|
|||
require 'travis/api/serialize/v1/helpers/legacy'
|
||||
|
||||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
module V1
|
||||
module Http
|
||||
class Branches
|
||||
include Formats, Helpers::Legacy
|
||||
|
||||
attr_reader :builds, :options
|
||||
|
||||
def initialize(builds, options = {})
|
||||
builds = builds.last_finished_builds_by_branches if builds.is_a?(Repository) # TODO remove, bc
|
||||
@builds = builds
|
||||
end
|
||||
|
||||
def cache_key
|
||||
"branches-#{builds.map(&:id).join('-')}"
|
||||
end
|
||||
|
||||
def updated_at
|
||||
builds.compact.map(&:finished_at).compact.sort.first
|
||||
end
|
||||
|
||||
def data
|
||||
builds.compact.map do |build|
|
||||
{
|
||||
'repository_id' => build.repository_id,
|
||||
'build_id' => build.id,
|
||||
'commit' => build.commit.commit,
|
||||
'branch' => build.commit.branch,
|
||||
'message' => build.commit.message,
|
||||
'result' => legacy_build_result(build),
|
||||
'finished_at' => format_date(build.finished_at),
|
||||
'started_at' => format_date(build.started_at)
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
49
lib/travis/api/serialize/v1/http/build.rb
Normal file
49
lib/travis/api/serialize/v1/http/build.rb
Normal file
|
@ -0,0 +1,49 @@
|
|||
require 'travis/api/serialize/v1/http/build/job'
|
||||
|
||||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
module V1
|
||||
module Http
|
||||
class Build
|
||||
include Formats, Helpers::Legacy
|
||||
|
||||
attr_reader :build, :commit, :request
|
||||
|
||||
def initialize(build, options = {})
|
||||
@build = build
|
||||
@commit = build.commit
|
||||
@request = build.request
|
||||
end
|
||||
|
||||
def data
|
||||
{
|
||||
'id' => build.id,
|
||||
'repository_id' => build.repository_id,
|
||||
'number' => build.number,
|
||||
'config' => build.obfuscated_config.stringify_keys,
|
||||
'state' => legacy_build_state(build),
|
||||
'result' => legacy_build_result(build),
|
||||
'status' => legacy_build_result(build),
|
||||
'started_at' => format_date(build.started_at),
|
||||
'finished_at' => format_date(build.finished_at),
|
||||
'duration' => build.duration,
|
||||
'commit' => commit.commit,
|
||||
'branch' => commit.branch,
|
||||
'message' => commit.message,
|
||||
'committed_at' => format_date(commit.committed_at),
|
||||
'author_name' => commit.author_name,
|
||||
'author_email' => commit.author_email,
|
||||
'committer_name' => commit.committer_name,
|
||||
'committer_email' => commit.committer_email,
|
||||
'compare_url' => commit.compare_url,
|
||||
'event_type' => build.event_type,
|
||||
'matrix' => build.matrix.map { |job| Job.new(job).data },
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
34
lib/travis/api/serialize/v1/http/build/job.rb
Normal file
34
lib/travis/api/serialize/v1/http/build/job.rb
Normal file
|
@ -0,0 +1,34 @@
|
|||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
module V1
|
||||
module Http
|
||||
class Build
|
||||
class Job
|
||||
include Formats, Helpers::Legacy
|
||||
|
||||
attr_reader :job
|
||||
|
||||
def initialize(job)
|
||||
@job = job
|
||||
end
|
||||
|
||||
def data
|
||||
{
|
||||
'id' => job.id,
|
||||
'repository_id' => job.repository_id,
|
||||
'number' => job.number,
|
||||
'config' => job.obfuscated_config.stringify_keys,
|
||||
'result' => legacy_job_result(job),
|
||||
'started_at' => format_date(job.started_at),
|
||||
'finished_at' => format_date(job.finished_at),
|
||||
'allow_failure' => job.allow_failure
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
40
lib/travis/api/serialize/v1/http/builds.rb
Normal file
40
lib/travis/api/serialize/v1/http/builds.rb
Normal file
|
@ -0,0 +1,40 @@
|
|||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
module V1
|
||||
module Http
|
||||
class Builds
|
||||
include Formats, Helpers::Legacy
|
||||
|
||||
attr_reader :builds
|
||||
|
||||
def initialize(builds, options = {})
|
||||
@builds = builds
|
||||
end
|
||||
|
||||
def data
|
||||
builds.map { |build| build_data(build) }
|
||||
end
|
||||
|
||||
def build_data(build)
|
||||
{
|
||||
'id' => build.id,
|
||||
'repository_id' => build.repository_id,
|
||||
'number' => build.number,
|
||||
'state' => legacy_build_state(build),
|
||||
'result' => legacy_build_result(build),
|
||||
'started_at' => format_date(build.started_at),
|
||||
'finished_at' => format_date(build.finished_at),
|
||||
'duration' => build.duration,
|
||||
'commit' => build.commit.commit,
|
||||
'branch' => build.commit.branch,
|
||||
'message' => build.commit.message,
|
||||
'event_type' => build.event_type,
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
36
lib/travis/api/serialize/v1/http/hooks.rb
Normal file
36
lib/travis/api/serialize/v1/http/hooks.rb
Normal file
|
@ -0,0 +1,36 @@
|
|||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
module V1
|
||||
module Http
|
||||
class Hooks
|
||||
attr_reader :repos, :options
|
||||
|
||||
def initialize(repos, options = {})
|
||||
@repos = repos
|
||||
@options = options
|
||||
end
|
||||
|
||||
def data
|
||||
repos.map { |repo| repo_data(repo) }
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def repo_data(repo)
|
||||
{
|
||||
'uid' => [repo.owner_name, repo.name].join(':'),
|
||||
'url' => "https://github.com/#{repo.owner_name}/#{repo.name}",
|
||||
'name' => repo.name,
|
||||
'owner_name' => repo.owner_name,
|
||||
'description' => repo.description,
|
||||
'active' => repo.active,
|
||||
'private' => repo.private
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,49 +1,32 @@
|
|||
module Travis
|
||||
module Api
|
||||
module V2
|
||||
module Http
|
||||
class Jobs
|
||||
include Formats
|
||||
module Serialize
|
||||
module V1
|
||||
module Http
|
||||
class Job
|
||||
include Formats, Helpers::Legacy
|
||||
|
||||
attr_reader :jobs, :options
|
||||
attr_reader :job, :commit
|
||||
|
||||
def initialize(jobs, options = {})
|
||||
@jobs = jobs
|
||||
@options = options
|
||||
end
|
||||
|
||||
def data
|
||||
{
|
||||
'jobs' => jobs.map { |job| job_data(job) },
|
||||
'commits' => jobs.map { |job| commit_data(job.commit) }
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def job_data(job)
|
||||
{
|
||||
'id' => job.id,
|
||||
'repository_id' => job.repository_id,
|
||||
'repository_slug' => job.repository.slug,
|
||||
'build_id' => job.source_id,
|
||||
'commit_id' => job.commit_id,
|
||||
'log_id' => job.log_id,
|
||||
'number' => job.number,
|
||||
'config' => job.obfuscated_config.stringify_keys,
|
||||
'state' => job.state.to_s,
|
||||
'started_at' => format_date(job.started_at),
|
||||
'finished_at' => format_date(job.finished_at),
|
||||
'queue' => job.queue,
|
||||
'allow_failure' => job.allow_failure,
|
||||
'tags' => job.tags
|
||||
}
|
||||
def initialize(job, options = {})
|
||||
@job = job
|
||||
@commit = job.commit
|
||||
end
|
||||
|
||||
def commit_data(commit)
|
||||
def data
|
||||
{
|
||||
'id' => commit.id,
|
||||
'sha' => commit.commit,
|
||||
'id' => job.id,
|
||||
'number' => job.number,
|
||||
'config' => job.obfuscated_config.stringify_keys,
|
||||
'repository_id' => job.repository_id,
|
||||
'build_id' => job.source_id,
|
||||
'state' => job.finished? ? 'finished' : job.state.to_s,
|
||||
'result' => legacy_job_result(job),
|
||||
'status' => legacy_job_result(job),
|
||||
'started_at' => format_date(job.started_at),
|
||||
'finished_at' => format_date(job.finished_at),
|
||||
'log' => job.log_content,
|
||||
'commit' => commit.commit,
|
||||
'branch' => commit.branch,
|
||||
'message' => commit.message,
|
||||
'committed_at' => format_date(commit.committed_at),
|
||||
|
@ -52,8 +35,10 @@ module Travis
|
|||
'committer_name' => commit.committer_name,
|
||||
'committer_email' => commit.committer_email,
|
||||
'compare_url' => commit.compare_url,
|
||||
'worker' => job.worker
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
36
lib/travis/api/serialize/v1/http/jobs.rb
Normal file
36
lib/travis/api/serialize/v1/http/jobs.rb
Normal file
|
@ -0,0 +1,36 @@
|
|||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
module V1
|
||||
module Http
|
||||
class Jobs
|
||||
include Formats, Helpers::Legacy
|
||||
|
||||
attr_reader :jobs
|
||||
|
||||
def initialize(jobs, options = {})
|
||||
@jobs = jobs
|
||||
end
|
||||
|
||||
def data
|
||||
jobs.map { |job| job_data(job) }
|
||||
end
|
||||
|
||||
def job_data(job)
|
||||
commit = job.commit
|
||||
{
|
||||
'id' => job.id,
|
||||
'repository_id' => job.repository_id,
|
||||
'number' => job.number,
|
||||
'state' => legacy_job_state(job),
|
||||
'queue' => job.queue,
|
||||
'allow_failure' => job.allow_failure
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -1,24 +1,20 @@
|
|||
module Travis
|
||||
module Api
|
||||
module V2
|
||||
module Http
|
||||
class Repositories
|
||||
include Formats
|
||||
module Serialize
|
||||
module V1
|
||||
module Http
|
||||
class Repositories
|
||||
include Formats, Helpers::Legacy
|
||||
|
||||
attr_reader :repositories, :options
|
||||
attr_reader :repositories
|
||||
|
||||
def initialize(repositories, options = {})
|
||||
@repositories = repositories
|
||||
@options = options
|
||||
end
|
||||
def initialize(repositories, options = {})
|
||||
@repositories = repositories
|
||||
end
|
||||
|
||||
def data
|
||||
{
|
||||
'repos' => repositories.map { |repository| repository_data(repository) }
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
def data
|
||||
repositories.map { |repository| repository_data(repository) }
|
||||
end
|
||||
|
||||
def repository_data(repository)
|
||||
{
|
||||
|
@ -27,15 +23,15 @@ module Travis
|
|||
'description' => repository.description,
|
||||
'last_build_id' => repository.last_build_id,
|
||||
'last_build_number' => repository.last_build_number,
|
||||
'last_build_state' => repository.last_build_state.to_s,
|
||||
'last_build_status' => legacy_repository_last_build_result(repository),
|
||||
'last_build_result' => legacy_repository_last_build_result(repository),
|
||||
'last_build_duration' => repository.last_build_duration,
|
||||
'last_build_language' => nil,
|
||||
'last_build_started_at' => format_date(repository.last_build_started_at),
|
||||
'last_build_finished_at' => format_date(repository.last_build_finished_at),
|
||||
'active' => repository.active,
|
||||
'github_language' => repository.github_language
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,44 +1,36 @@
|
|||
module Travis
|
||||
module Api
|
||||
module V2
|
||||
module Http
|
||||
class Repository
|
||||
include Formats
|
||||
module Serialize
|
||||
module V1
|
||||
module Http
|
||||
class Repository
|
||||
include Formats, Helpers::Legacy
|
||||
|
||||
attr_reader :repository, :options
|
||||
attr_reader :repository, :options
|
||||
|
||||
def initialize(repository, options = {})
|
||||
@repository = repository
|
||||
end
|
||||
def initialize(repository, options = {})
|
||||
@repository = repository
|
||||
end
|
||||
|
||||
def data
|
||||
{
|
||||
'repo' => repository_data(repository)
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# TODO why does this not include the last build? (i.e. 'builds' => { last build here })
|
||||
def repository_data(repository)
|
||||
def data
|
||||
{
|
||||
'id' => repository.id,
|
||||
'slug' => repository.slug,
|
||||
'active' => repository.active,
|
||||
'description' => repository.description,
|
||||
'public_key' => repository.key.public_key,
|
||||
'last_build_id' => repository.last_build_id,
|
||||
'last_build_number' => repository.last_build_number,
|
||||
'last_build_state' => repository.last_build_state.to_s,
|
||||
'last_build_status' => legacy_repository_last_build_result(repository),
|
||||
'last_build_result' => legacy_repository_last_build_result(repository),
|
||||
'last_build_duration' => repository.last_build_duration,
|
||||
'last_build_language' => nil,
|
||||
'last_build_started_at' => format_date(repository.last_build_started_at),
|
||||
'last_build_finished_at' => format_date(repository.last_build_finished_at),
|
||||
'github_language' => repository.github_language
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
33
lib/travis/api/serialize/v1/http/user.rb
Normal file
33
lib/travis/api/serialize/v1/http/user.rb
Normal file
|
@ -0,0 +1,33 @@
|
|||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
module V1
|
||||
module Http
|
||||
class User
|
||||
include Formats
|
||||
|
||||
attr_reader :user, :options
|
||||
|
||||
def initialize(user, options = {})
|
||||
@user = user
|
||||
@options = options
|
||||
end
|
||||
|
||||
def data
|
||||
{
|
||||
'login' => user.login,
|
||||
'name' => user.name,
|
||||
'email' => user.email,
|
||||
'gravatar_id' => user.gravatar_id,
|
||||
'locale' => user.locale,
|
||||
'is_syncing' => user.is_syncing,
|
||||
'synced_at' => format_date(user.synced_at)
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
1
lib/travis/api/serialize/v1/webhook.rb
Normal file
1
lib/travis/api/serialize/v1/webhook.rb
Normal file
|
@ -0,0 +1 @@
|
|||
require 'travis/api/serialize/v1/webhook/build'
|
29
lib/travis/api/serialize/v1/webhook/build.rb
Normal file
29
lib/travis/api/serialize/v1/webhook/build.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
require 'travis/api/serialize/v1/webhook/build/finished'
|
||||
|
||||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
module V1
|
||||
module Webhook
|
||||
class Build
|
||||
attr_reader :build, :commit, :request, :repository, :options
|
||||
|
||||
def initialize(build, options = {})
|
||||
@build = build
|
||||
@commit = build.commit
|
||||
@request = build.request
|
||||
@repository = build.repository
|
||||
@options = options
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def build_url
|
||||
["https://#{Travis.config.host}", repository.slug, 'builds', build.id].join('/')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
72
lib/travis/api/serialize/v1/webhook/build/finished.rb
Normal file
72
lib/travis/api/serialize/v1/webhook/build/finished.rb
Normal file
|
@ -0,0 +1,72 @@
|
|||
require 'travis/api/serialize/v1/webhook/build/finished/job'
|
||||
|
||||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
module V1
|
||||
module Webhook
|
||||
class Build
|
||||
class Finished < Build
|
||||
include Formats
|
||||
|
||||
def data
|
||||
data = {
|
||||
'id' => build.id,
|
||||
'repository' => repository_data,
|
||||
'number' => build.number,
|
||||
'config' => build.obfuscated_config.stringify_keys,
|
||||
'status' => build.result,
|
||||
'result' => build.result,
|
||||
'status_message' => result_message,
|
||||
'result_message' => result_message,
|
||||
'started_at' => format_date(build.started_at),
|
||||
'finished_at' => format_date(build.finished_at),
|
||||
'duration' => build.duration,
|
||||
'build_url' => build_url,
|
||||
'commit_id' => commit.id,
|
||||
'commit' => commit.commit,
|
||||
'base_commit' => request.base_commit,
|
||||
'head_commit' => request.head_commit,
|
||||
'branch' => commit.branch,
|
||||
'message' => commit.message,
|
||||
'compare_url' => commit.compare_url,
|
||||
'committed_at' => format_date(commit.committed_at),
|
||||
'author_name' => commit.author_name,
|
||||
'author_email' => commit.author_email,
|
||||
'committer_name' => commit.committer_name,
|
||||
'committer_email' => commit.committer_email,
|
||||
'matrix' => build.matrix.map { |job| Job.new(job, options).data },
|
||||
'type' => build.event_type,
|
||||
'state' => build.state.to_s,
|
||||
'pull_request' => build.pull_request?,
|
||||
'pull_request_number' => build.pull_request_number,
|
||||
'pull_request_title' => build.pull_request_title,
|
||||
'tag' => request.tag_name
|
||||
}
|
||||
|
||||
if commit.pull_request?
|
||||
data['pull_request_number'] = commit.pull_request_number
|
||||
end
|
||||
|
||||
data
|
||||
end
|
||||
|
||||
def repository_data
|
||||
{
|
||||
'id' => repository.id,
|
||||
'name' => repository.name,
|
||||
'owner_name' => repository.owner_name,
|
||||
'url' => repository.url
|
||||
}
|
||||
end
|
||||
|
||||
def result_message
|
||||
@result_message ||= ::Build::ResultMessage.new(build).short
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
52
lib/travis/api/serialize/v1/webhook/build/finished/job.rb
Normal file
52
lib/travis/api/serialize/v1/webhook/build/finished/job.rb
Normal file
|
@ -0,0 +1,52 @@
|
|||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
module V1
|
||||
module Webhook
|
||||
class Build
|
||||
class Finished < Build
|
||||
class Job
|
||||
include Formats
|
||||
|
||||
attr_reader :job, :commit, :options
|
||||
|
||||
def initialize(job, options = {})
|
||||
@job = job
|
||||
@commit = job.commit
|
||||
@options = options
|
||||
end
|
||||
|
||||
def data
|
||||
data = {
|
||||
'id' => job.id,
|
||||
'repository_id' => job.repository_id,
|
||||
'parent_id' => job.source_id,
|
||||
'number' => job.number,
|
||||
'state' => job.finished? ? 'finished' : job.state.to_s,
|
||||
'config' => job.obfuscated_config,
|
||||
'status' => job.result,
|
||||
'result' => job.result,
|
||||
'commit' => commit.commit,
|
||||
'branch' => commit.branch,
|
||||
'message' => commit.message,
|
||||
'compare_url' => commit.compare_url,
|
||||
'committed_at' => format_date(commit.committed_at),
|
||||
'author_name' => commit.author_name,
|
||||
'author_email' => commit.author_email,
|
||||
'committer_name' => commit.committer_name,
|
||||
'committer_email' => commit.committer_email,
|
||||
'allow_failure' => job.allow_failure
|
||||
}
|
||||
data['log'] = job.log_content || '' if options[:include_logs]
|
||||
data['started_at'] = format_date(job.started_at) if job.started?
|
||||
data['finished_at'] = format_date(job.finished_at) if job.finished?
|
||||
data
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
1
lib/travis/api/serialize/v2.rb
Normal file
1
lib/travis/api/serialize/v2.rb
Normal file
|
@ -0,0 +1 @@
|
|||
require 'travis/api/serialize/v2/http'
|
24
lib/travis/api/serialize/v2/http.rb
Normal file
24
lib/travis/api/serialize/v2/http.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
require 'travis/api/serialize/serializer'
|
||||
require 'travis/api/serialize/v2/http/accounts'
|
||||
require 'travis/api/serialize/v2/http/annotations'
|
||||
require 'travis/api/serialize/v2/http/broadcasts'
|
||||
require 'travis/api/serialize/v2/http/branch'
|
||||
require 'travis/api/serialize/v2/http/branches'
|
||||
require 'travis/api/serialize/v2/http/build'
|
||||
require 'travis/api/serialize/v2/http/builds'
|
||||
require 'travis/api/serialize/v2/http/caches'
|
||||
require 'travis/api/serialize/v2/http/hooks'
|
||||
require 'travis/api/serialize/v2/http/job'
|
||||
require 'travis/api/serialize/v2/http/jobs'
|
||||
require 'travis/api/serialize/v2/http/log'
|
||||
require 'travis/api/serialize/v2/http/permissions'
|
||||
require 'travis/api/serialize/v2/http/repositories'
|
||||
require 'travis/api/serialize/v2/http/repository'
|
||||
require 'travis/api/serialize/v2/http/requests'
|
||||
require 'travis/api/serialize/v2/http/request'
|
||||
require 'travis/api/serialize/v2/http/ssl_key'
|
||||
require 'travis/api/serialize/v2/http/env_var'
|
||||
require 'travis/api/serialize/v2/http/env_vars'
|
||||
require 'travis/api/serialize/v2/http/user'
|
||||
require 'travis/api/serialize/v2/http/validation_error'
|
||||
require 'travis/api/serialize/v2/http/ssh_key'
|
44
lib/travis/api/serialize/v2/http/accounts.rb
Normal file
44
lib/travis/api/serialize/v2/http/accounts.rb
Normal file
|
@ -0,0 +1,44 @@
|
|||
require 'travis/api/serialize/formats'
|
||||
|
||||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
module V2
|
||||
module Http
|
||||
class Accounts
|
||||
include Formats
|
||||
|
||||
attr_reader :accounts, :options
|
||||
|
||||
def initialize(accounts, options = {})
|
||||
@accounts = accounts
|
||||
@options = options
|
||||
end
|
||||
|
||||
def data
|
||||
{
|
||||
:accounts => accounts.map { |account| account_data(account) }
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def account_data(account)
|
||||
data = {
|
||||
'id' => account.id,
|
||||
'name' => account.name,
|
||||
'login' => account.login,
|
||||
'type' => account.type.underscore,
|
||||
'repos_count' => account.repos_count
|
||||
}
|
||||
|
||||
data['avatar_url'] = account.avatar_url if account.respond_to?(:avatar_url)
|
||||
|
||||
data
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
38
lib/travis/api/serialize/v2/http/annotations.rb
Normal file
38
lib/travis/api/serialize/v2/http/annotations.rb
Normal file
|
@ -0,0 +1,38 @@
|
|||
require 'travis/api/serialize/formats'
|
||||
|
||||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
module V2
|
||||
module Http
|
||||
class Annotations
|
||||
include Formats
|
||||
|
||||
def initialize(annotations, options = {})
|
||||
@annotations = annotations
|
||||
end
|
||||
|
||||
def data
|
||||
{
|
||||
"annotations" => @annotations.map { |annotation| build_annotation(annotation) },
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def build_annotation(annotation)
|
||||
{
|
||||
"id" => annotation.id,
|
||||
"job_id" => annotation.job_id,
|
||||
"description" => annotation.description,
|
||||
"url" => annotation.url,
|
||||
"status" => annotation.status,
|
||||
"provider_name" => annotation.annotation_provider.name,
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
31
lib/travis/api/serialize/v2/http/branch.rb
Normal file
31
lib/travis/api/serialize/v2/http/branch.rb
Normal file
|
@ -0,0 +1,31 @@
|
|||
require 'travis/api/serialize/formats'
|
||||
require 'travis/api/serialize/v2/http/branches'
|
||||
|
||||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
module V2
|
||||
module Http
|
||||
class Branch < Branches
|
||||
include Formats
|
||||
|
||||
attr_reader :build, :commit, :options
|
||||
|
||||
def initialize(build, options = {})
|
||||
@build = build
|
||||
@commit = build.commit
|
||||
@options = options
|
||||
end
|
||||
|
||||
def data
|
||||
{
|
||||
'branch' => build_data(build),
|
||||
'commit' => commit_data(commit)
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
64
lib/travis/api/serialize/v2/http/branches.rb
Normal file
64
lib/travis/api/serialize/v2/http/branches.rb
Normal file
|
@ -0,0 +1,64 @@
|
|||
require 'travis/api/serialize/formats'
|
||||
|
||||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
module V2
|
||||
module Http
|
||||
class Branches
|
||||
include Formats
|
||||
|
||||
attr_reader :builds, :commits, :options
|
||||
|
||||
def initialize(builds, options = {})
|
||||
builds = builds.last_finished_builds_by_branches if builds.is_a?(Repository) # TODO remove, bc
|
||||
@builds = builds
|
||||
@commits = builds.map(&:commit)
|
||||
@options = options
|
||||
end
|
||||
|
||||
def data
|
||||
{
|
||||
'branches' => builds.map { |build| build_data(build) },
|
||||
'commits' => commits.map { |commit| commit_data(commit) }
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def build_data(build)
|
||||
{
|
||||
'id' => build.id,
|
||||
'repository_id' => build.repository_id,
|
||||
'commit_id' => build.commit_id,
|
||||
'number' => build.number,
|
||||
'config' => build.obfuscated_config.stringify_keys,
|
||||
'state' => build.state.to_s,
|
||||
'started_at' => format_date(build.started_at),
|
||||
'finished_at' => format_date(build.finished_at),
|
||||
'duration' => build.duration,
|
||||
'job_ids' => build.matrix.map { |job| job.id },
|
||||
'pull_request' => build.pull_request?
|
||||
}
|
||||
end
|
||||
|
||||
def commit_data(commit)
|
||||
{
|
||||
'id' => commit.id,
|
||||
'sha' => commit.commit,
|
||||
'branch' => commit.branch,
|
||||
'message' => commit.message,
|
||||
'committed_at' => format_date(commit.committed_at),
|
||||
'author_name' => commit.author_name,
|
||||
'author_email' => commit.author_email,
|
||||
'committer_name' => commit.committer_name,
|
||||
'committer_email' => commit.committer_email,
|
||||
'compare_url' => commit.compare_url,
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
33
lib/travis/api/serialize/v2/http/broadcasts.rb
Normal file
33
lib/travis/api/serialize/v2/http/broadcasts.rb
Normal file
|
@ -0,0 +1,33 @@
|
|||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
module V2
|
||||
module Http
|
||||
class Broadcasts
|
||||
attr_reader :broadcasts, :options
|
||||
|
||||
def initialize(broadcasts, options = {})
|
||||
@broadcasts = broadcasts
|
||||
@options = options
|
||||
end
|
||||
|
||||
def data
|
||||
{
|
||||
'broadcasts' => broadcasts.map { |broadcast| broadcast_data(broadcast) }
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def broadcast_data(broadcast)
|
||||
{
|
||||
'id' => broadcast.id,
|
||||
'message' => broadcast.message
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
97
lib/travis/api/serialize/v2/http/build.rb
Normal file
97
lib/travis/api/serialize/v2/http/build.rb
Normal file
|
@ -0,0 +1,97 @@
|
|||
require 'travis/api/serialize/formats'
|
||||
|
||||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
module V2
|
||||
module Http
|
||||
class Build
|
||||
include Formats
|
||||
|
||||
attr_reader :build, :options
|
||||
|
||||
def initialize(build, options = {})
|
||||
options[:include_jobs] = true unless options.key?(:include_jobs)
|
||||
|
||||
@build = build
|
||||
@options = options
|
||||
end
|
||||
|
||||
def data
|
||||
{
|
||||
'build' => build_data(build),
|
||||
'commit' => commit_data(build.commit, build.repository),
|
||||
'jobs' => options[:include_jobs] ? build.matrix.map { |job| job_data(job) } : [],
|
||||
'annotations' => options[:include_jobs] ? Annotations.new(annotations(build), @options).data["annotations"] : [],
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def build_data(build)
|
||||
{
|
||||
'id' => build.id,
|
||||
'repository_id' => build.repository_id,
|
||||
'commit_id' => build.commit_id,
|
||||
'number' => build.number,
|
||||
'event_type' => build.event_type,
|
||||
'pull_request' => build.pull_request?,
|
||||
'pull_request_title' => build.pull_request_title,
|
||||
'pull_request_number' => build.pull_request_number,
|
||||
'config' => build.obfuscated_config.stringify_keys,
|
||||
'state' => build.state.to_s,
|
||||
'started_at' => format_date(build.started_at),
|
||||
'finished_at' => format_date(build.finished_at),
|
||||
'duration' => build.duration,
|
||||
'job_ids' => build.matrix_ids
|
||||
}
|
||||
end
|
||||
|
||||
def commit_data(commit, repository)
|
||||
{
|
||||
'id' => commit.id,
|
||||
'sha' => commit.commit,
|
||||
'branch' => commit.branch,
|
||||
'branch_is_default' => branch_is_default(commit, repository),
|
||||
'message' => commit.message,
|
||||
'committed_at' => format_date(commit.committed_at),
|
||||
'author_name' => commit.author_name,
|
||||
'author_email' => commit.author_email,
|
||||
'committer_name' => commit.committer_name,
|
||||
'committer_email' => commit.committer_email,
|
||||
'compare_url' => commit.compare_url,
|
||||
}
|
||||
end
|
||||
|
||||
def job_data(job)
|
||||
{
|
||||
'id' => job.id,
|
||||
'repository_id' => job.repository_id,
|
||||
'build_id' => job.source_id,
|
||||
'commit_id' => job.commit_id,
|
||||
'log_id' => job.log_id,
|
||||
'state' => job.state.to_s,
|
||||
'number' => job.number,
|
||||
'config' => job.obfuscated_config.stringify_keys,
|
||||
'started_at' => format_date(job.started_at),
|
||||
'finished_at' => format_date(job.finished_at),
|
||||
'queue' => job.queue,
|
||||
'allow_failure' => job.allow_failure,
|
||||
'tags' => job.tags,
|
||||
'annotation_ids' => job.annotation_ids,
|
||||
}
|
||||
end
|
||||
|
||||
def branch_is_default(commit, repository)
|
||||
repository.default_branch == commit.branch
|
||||
end
|
||||
|
||||
def annotations(build)
|
||||
build.matrix.map(&:annotations).flatten
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
71
lib/travis/api/serialize/v2/http/builds.rb
Normal file
71
lib/travis/api/serialize/v2/http/builds.rb
Normal file
|
@ -0,0 +1,71 @@
|
|||
require 'travis/api/serialize/formats'
|
||||
|
||||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
module V2
|
||||
module Http
|
||||
class Builds
|
||||
include Formats
|
||||
|
||||
attr_reader :builds, :commits, :options
|
||||
|
||||
def initialize(builds, options = {})
|
||||
@builds = builds
|
||||
@commits = builds.map(&:commit)
|
||||
@options = options
|
||||
end
|
||||
|
||||
def data
|
||||
{
|
||||
'builds' => builds.map { |build| build_data(build) },
|
||||
'commits' => commits.map { |commit| commit_data(commit) }
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def build_data(build)
|
||||
{
|
||||
'id' => build.id,
|
||||
'repository_id' => build.repository_id,
|
||||
'commit_id' => build.commit_id,
|
||||
'number' => build.number,
|
||||
'event_type' => build.event_type,
|
||||
'pull_request' => build.pull_request?,
|
||||
'pull_request_title' => build.pull_request_title,
|
||||
'pull_request_number' => build.pull_request_number,
|
||||
'config' => build.obfuscated_config.stringify_keys,
|
||||
'state' => build.state.to_s,
|
||||
'started_at' => format_date(build.started_at),
|
||||
'finished_at' => format_date(build.finished_at),
|
||||
'duration' => build.duration,
|
||||
'job_ids' => matrix_ids(build)
|
||||
}
|
||||
end
|
||||
|
||||
def matrix_ids(build)
|
||||
build.cached_matrix_ids || build.matrix_ids
|
||||
end
|
||||
|
||||
def commit_data(commit)
|
||||
{
|
||||
'id' => commit.id,
|
||||
'sha' => commit.commit,
|
||||
'branch' => commit.branch,
|
||||
'message' => commit.message,
|
||||
'committed_at' => format_date(commit.committed_at),
|
||||
'author_name' => commit.author_name,
|
||||
'author_email' => commit.author_email,
|
||||
'committer_name' => commit.committer_name,
|
||||
'committer_email' => commit.committer_email,
|
||||
'compare_url' => commit.compare_url,
|
||||
'pull_request_number' => commit.pull_request_number
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
37
lib/travis/api/serialize/v2/http/caches.rb
Normal file
37
lib/travis/api/serialize/v2/http/caches.rb
Normal file
|
@ -0,0 +1,37 @@
|
|||
require 'travis/api/serialize/formats'
|
||||
|
||||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
module V2
|
||||
module Http
|
||||
class Caches
|
||||
include Formats
|
||||
attr_reader :caches, :options
|
||||
|
||||
def initialize(caches, options = {})
|
||||
@caches = caches
|
||||
@options = options
|
||||
end
|
||||
|
||||
def data
|
||||
{ 'caches' => caches.map { |cache| cache_data(cache) } }
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def cache_data(cache)
|
||||
{
|
||||
'repository_id' => cache.repository.id,
|
||||
'size' => cache.size,
|
||||
'slug' => cache.slug,
|
||||
'branch' => cache.branch,
|
||||
'last_modified' => format_date(cache.last_modified)
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
25
lib/travis/api/serialize/v2/http/env_var.rb
Normal file
25
lib/travis/api/serialize/v2/http/env_var.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
module V2
|
||||
module Http
|
||||
class EnvVar < Travis::Api::Serialize::ObjectSerializer
|
||||
attributes :id, :name, :value, :public, :repository_id
|
||||
|
||||
def value
|
||||
if object.public?
|
||||
object.value.decrypt
|
||||
end
|
||||
end
|
||||
|
||||
def serializable_hash
|
||||
hash = super
|
||||
hash.delete :value unless object.public?
|
||||
hash
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
2
lib/travis/api/serialize/v2/http/env_vars.rb
Normal file
2
lib/travis/api/serialize/v2/http/env_vars.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
class Travis::Api::Serialize::V2::Http::EnvVars < Travis::Api::Serialize::ArraySerializer
|
||||
end
|
38
lib/travis/api/serialize/v2/http/hooks.rb
Normal file
38
lib/travis/api/serialize/v2/http/hooks.rb
Normal file
|
@ -0,0 +1,38 @@
|
|||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
module V2
|
||||
module Http
|
||||
class Hooks
|
||||
attr_reader :hooks, :options
|
||||
|
||||
def initialize(hooks, options = {})
|
||||
@hooks = hooks
|
||||
@options = options
|
||||
end
|
||||
|
||||
def data
|
||||
{
|
||||
'hooks' => hooks.map { |hook| hook_data(hook) },
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def hook_data(hook)
|
||||
{
|
||||
'id' => hook.id,
|
||||
'name' => hook.name,
|
||||
'owner_name' => hook.owner_name,
|
||||
'description' => hook.description,
|
||||
'active' => hook.active,
|
||||
'private' => hook.private,
|
||||
'admin' => hook.admin?
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
72
lib/travis/api/serialize/v2/http/job.rb
Normal file
72
lib/travis/api/serialize/v2/http/job.rb
Normal file
|
@ -0,0 +1,72 @@
|
|||
require 'travis/api/serialize/formats'
|
||||
|
||||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
module V2
|
||||
module Http
|
||||
class Job
|
||||
include Formats
|
||||
|
||||
attr_reader :job, :options
|
||||
|
||||
def initialize(job, options = {})
|
||||
@job = job
|
||||
@options = options
|
||||
end
|
||||
|
||||
def data
|
||||
{
|
||||
'job' => job_data(job),
|
||||
'commit' => commit_data(job.commit, job.repository),
|
||||
'annotations' => Annotations.new(job.annotations, @options).data["annotations"],
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def job_data(job)
|
||||
{
|
||||
'id' => job.id,
|
||||
'repository_id' => job.repository_id,
|
||||
'repository_slug' => job.repository.slug,
|
||||
'build_id' => job.source_id,
|
||||
'commit_id' => job.commit_id,
|
||||
'log_id' => job.log_id,
|
||||
'number' => job.number,
|
||||
'config' => job.obfuscated_config.stringify_keys,
|
||||
'state' => job.state.to_s,
|
||||
'started_at' => format_date(job.started_at),
|
||||
'finished_at' => format_date(job.finished_at),
|
||||
'queue' => job.queue,
|
||||
'allow_failure' => job.allow_failure,
|
||||
'tags' => job.tags,
|
||||
'annotation_ids' => job.annotation_ids,
|
||||
}
|
||||
end
|
||||
|
||||
def commit_data(commit, repository)
|
||||
{
|
||||
'id' => commit.id,
|
||||
'sha' => commit.commit,
|
||||
'branch' => commit.branch,
|
||||
'branch_is_default' => branch_is_default(commit, repository),
|
||||
'message' => commit.message,
|
||||
'committed_at' => format_date(commit.committed_at),
|
||||
'author_name' => commit.author_name,
|
||||
'author_email' => commit.author_email,
|
||||
'committer_name' => commit.committer_name,
|
||||
'committer_email' => commit.committer_email,
|
||||
'compare_url' => commit.compare_url,
|
||||
}
|
||||
end
|
||||
|
||||
def branch_is_default(commit, repository)
|
||||
repository.default_branch == commit.branch
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
65
lib/travis/api/serialize/v2/http/jobs.rb
Normal file
65
lib/travis/api/serialize/v2/http/jobs.rb
Normal file
|
@ -0,0 +1,65 @@
|
|||
require 'travis/api/serialize/formats'
|
||||
|
||||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
module V2
|
||||
module Http
|
||||
class Jobs
|
||||
include Formats
|
||||
|
||||
attr_reader :jobs, :options
|
||||
|
||||
def initialize(jobs, options = {})
|
||||
@jobs = jobs
|
||||
@options = options
|
||||
end
|
||||
|
||||
def data
|
||||
{
|
||||
'jobs' => jobs.map { |job| job_data(job) },
|
||||
'commits' => jobs.map { |job| commit_data(job.commit) }
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def job_data(job)
|
||||
{
|
||||
'id' => job.id,
|
||||
'repository_id' => job.repository_id,
|
||||
'repository_slug' => job.repository.slug,
|
||||
'build_id' => job.source_id,
|
||||
'commit_id' => job.commit_id,
|
||||
'log_id' => job.log_id,
|
||||
'number' => job.number,
|
||||
'config' => job.obfuscated_config.stringify_keys,
|
||||
'state' => job.state.to_s,
|
||||
'started_at' => format_date(job.started_at),
|
||||
'finished_at' => format_date(job.finished_at),
|
||||
'queue' => job.queue,
|
||||
'allow_failure' => job.allow_failure,
|
||||
'tags' => job.tags
|
||||
}
|
||||
end
|
||||
|
||||
def commit_data(commit)
|
||||
{
|
||||
'id' => commit.id,
|
||||
'sha' => commit.commit,
|
||||
'branch' => commit.branch,
|
||||
'message' => commit.message,
|
||||
'committed_at' => format_date(commit.committed_at),
|
||||
'author_name' => commit.author_name,
|
||||
'author_email' => commit.author_email,
|
||||
'committer_name' => commit.committer_name,
|
||||
'committer_email' => commit.committer_email,
|
||||
'compare_url' => commit.compare_url,
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
80
lib/travis/api/serialize/v2/http/log.rb
Normal file
80
lib/travis/api/serialize/v2/http/log.rb
Normal file
|
@ -0,0 +1,80 @@
|
|||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
module V2
|
||||
module Http
|
||||
class Log
|
||||
attr_reader :log, :options
|
||||
|
||||
def initialize(log, options = {})
|
||||
@log = log
|
||||
@options = options
|
||||
end
|
||||
|
||||
def data
|
||||
log_hash = options[:chunked] ? chunked_log_data : log_data
|
||||
if log.removed_at
|
||||
log_hash['removed_at'] = log.removed_at
|
||||
log_hash['removed_by'] = log.removed_by.name || log.removed_by.login
|
||||
end
|
||||
|
||||
{
|
||||
'log' => log_hash,
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def log_data
|
||||
{
|
||||
'id' => log.id,
|
||||
'job_id' => log.job_id,
|
||||
'type' => log.class.name.demodulize,
|
||||
'body' => log.content
|
||||
}
|
||||
end
|
||||
|
||||
def chunked_log_data
|
||||
{
|
||||
'id' => log.id,
|
||||
'job_id' => log.job_id,
|
||||
'type' => log.class.name.demodulize,
|
||||
'parts' => log_parts
|
||||
}
|
||||
end
|
||||
|
||||
def log_parts
|
||||
if log.removed_at
|
||||
# if log is removed we don't have actual parts
|
||||
parts = [{ 'number' => 1, 'content' => log.content, 'final' => true }]
|
||||
else
|
||||
parts = log.parts
|
||||
parts = parts.where(number: part_numbers) if part_numbers
|
||||
parts = parts.where(["number > ?", after]) if after
|
||||
parts.sort_by(&:number).map do |part|
|
||||
{
|
||||
'id' => part.id,
|
||||
'number' => part.number,
|
||||
'content' => part.content,
|
||||
'final' => part.final
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def after
|
||||
after = options['after'].to_i
|
||||
after == 0 ? nil : after
|
||||
end
|
||||
|
||||
def part_numbers
|
||||
if numbers = options['part_numbers']
|
||||
numbers.is_a?(String) ? numbers.split(',').map(&:to_i) : numbers
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
52
lib/travis/api/serialize/v2/http/permissions.rb
Normal file
52
lib/travis/api/serialize/v2/http/permissions.rb
Normal file
|
@ -0,0 +1,52 @@
|
|||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
module V2
|
||||
module Http
|
||||
class Permissions
|
||||
attr_reader :permissions, :options
|
||||
|
||||
def initialize(permissions, options = {})
|
||||
@permissions = permissions
|
||||
@options = options
|
||||
end
|
||||
|
||||
def data
|
||||
{
|
||||
'permissions' => repo_ids,
|
||||
'admin' => admin_ids,
|
||||
'pull' => pull_ids,
|
||||
'push' => push_ids
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
def filtered_ids(perm = nil)
|
||||
if perm
|
||||
permissions.find_all { |p| p.send("#{perm}?") }.map { |permission| permission.repository_id }
|
||||
else
|
||||
permissions.map { |permission| permission.repository_id }
|
||||
end
|
||||
end
|
||||
|
||||
def repo_ids
|
||||
filtered_ids
|
||||
end
|
||||
|
||||
def admin_ids
|
||||
filtered_ids(:admin)
|
||||
end
|
||||
|
||||
def pull_ids
|
||||
filtered_ids(:pull)
|
||||
end
|
||||
|
||||
def push_ids
|
||||
filtered_ids(:push)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
47
lib/travis/api/serialize/v2/http/repositories.rb
Normal file
47
lib/travis/api/serialize/v2/http/repositories.rb
Normal file
|
@ -0,0 +1,47 @@
|
|||
require 'travis/api/serialize/formats'
|
||||
|
||||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
module V2
|
||||
module Http
|
||||
class Repositories
|
||||
include Formats
|
||||
|
||||
attr_reader :repositories, :options
|
||||
|
||||
def initialize(repositories, options = {})
|
||||
@repositories = repositories
|
||||
@options = options
|
||||
end
|
||||
|
||||
def data
|
||||
{
|
||||
'repos' => repositories.map { |repository| repository_data(repository) }
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def repository_data(repository)
|
||||
{
|
||||
'id' => repository.id,
|
||||
'slug' => repository.slug,
|
||||
'description' => repository.description,
|
||||
'last_build_id' => repository.last_build_id,
|
||||
'last_build_number' => repository.last_build_number,
|
||||
'last_build_state' => repository.last_build_state.to_s,
|
||||
'last_build_duration' => repository.last_build_duration,
|
||||
'last_build_language' => nil,
|
||||
'last_build_started_at' => format_date(repository.last_build_started_at),
|
||||
'last_build_finished_at' => format_date(repository.last_build_finished_at),
|
||||
'active' => repository.active,
|
||||
'github_language' => repository.github_language
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
47
lib/travis/api/serialize/v2/http/repository.rb
Normal file
47
lib/travis/api/serialize/v2/http/repository.rb
Normal file
|
@ -0,0 +1,47 @@
|
|||
require 'travis/api/serialize/formats'
|
||||
|
||||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
module V2
|
||||
module Http
|
||||
class Repository
|
||||
include Formats
|
||||
|
||||
attr_reader :repository, :options
|
||||
|
||||
def initialize(repository, options = {})
|
||||
@repository = repository
|
||||
end
|
||||
|
||||
def data
|
||||
{
|
||||
'repo' => repository_data(repository)
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# TODO why does this not include the last build? (i.e. 'builds' => { last build here })
|
||||
def repository_data(repository)
|
||||
{
|
||||
'id' => repository.id,
|
||||
'slug' => repository.slug,
|
||||
'active' => repository.active,
|
||||
'description' => repository.description,
|
||||
'last_build_id' => repository.last_build_id,
|
||||
'last_build_number' => repository.last_build_number,
|
||||
'last_build_state' => repository.last_build_state.to_s,
|
||||
'last_build_duration' => repository.last_build_duration,
|
||||
'last_build_language' => nil,
|
||||
'last_build_started_at' => format_date(repository.last_build_started_at),
|
||||
'last_build_finished_at' => format_date(repository.last_build_finished_at),
|
||||
'github_language' => repository.github_language
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
75
lib/travis/api/serialize/v2/http/request.rb
Normal file
75
lib/travis/api/serialize/v2/http/request.rb
Normal file
|
@ -0,0 +1,75 @@
|
|||
require 'travis/api/serialize/formats'
|
||||
|
||||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
module V2
|
||||
module Http
|
||||
class Request
|
||||
include Formats
|
||||
attr_reader :request, :commit, :options
|
||||
|
||||
def initialize(request, options = {})
|
||||
@request = request
|
||||
@commit = request.commit
|
||||
@options = options
|
||||
end
|
||||
|
||||
def data
|
||||
data = {
|
||||
'request' => request_data
|
||||
}
|
||||
if commit
|
||||
data['commit'] = commit_data
|
||||
end
|
||||
data
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def request_data
|
||||
data = {
|
||||
'id' => request.id,
|
||||
'repository_id' => request.repository_id,
|
||||
'commit_id' => request.commit_id,
|
||||
'created_at' => format_date(request.created_at),
|
||||
'owner_id' => request.owner_id,
|
||||
'owner_type' => request.owner_type,
|
||||
'event_type' => request.event_type,
|
||||
'base_commit' => request.base_commit,
|
||||
'head_commit' => request.head_commit,
|
||||
'result' => request.result,
|
||||
'message' => request.message,
|
||||
'pull_request' => request.pull_request?,
|
||||
'pull_request_number' => request.pull_request_number,
|
||||
'pull_request_title' => request.pull_request_title,
|
||||
'branch' => request.branch_name,
|
||||
'tag' => request.tag_name
|
||||
}
|
||||
|
||||
data['build_id'] = request.builds.first.id if request.builds.present?
|
||||
|
||||
data
|
||||
end
|
||||
|
||||
def commit_data
|
||||
{
|
||||
'id' => commit.id,
|
||||
'sha' => commit.commit,
|
||||
'branch' => commit.branch,
|
||||
'message' => commit.message,
|
||||
'committed_at' => format_date(commit.committed_at),
|
||||
'author_name' => commit.author_name,
|
||||
'author_email' => commit.author_email,
|
||||
'committer_name' => commit.committer_name,
|
||||
'committer_email' => commit.committer_email,
|
||||
'compare_url' => commit.compare_url,
|
||||
'pull_request_number' => commit.pull_request_number
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
72
lib/travis/api/serialize/v2/http/requests.rb
Normal file
72
lib/travis/api/serialize/v2/http/requests.rb
Normal file
|
@ -0,0 +1,72 @@
|
|||
require 'travis/api/serialize/formats'
|
||||
|
||||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
module V2
|
||||
module Http
|
||||
class Requests
|
||||
include Formats
|
||||
attr_reader :requests, :commits, :options
|
||||
|
||||
def initialize(requests, options = {})
|
||||
@requests = requests
|
||||
@commits = requests.map(&:commit)
|
||||
@options = options
|
||||
end
|
||||
|
||||
def data
|
||||
{
|
||||
'requests' => requests.map { |request| request_data(request) },
|
||||
'commits' => commits.compact.map { |commit| commit_data(commit) }
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def request_data(request)
|
||||
data = {
|
||||
'id' => request.id,
|
||||
'repository_id' => request.repository_id,
|
||||
'commit_id' => request.commit_id,
|
||||
'created_at' => format_date(request.created_at),
|
||||
'owner_id' => request.owner_id,
|
||||
'owner_type' => request.owner_type,
|
||||
'event_type' => request.event_type,
|
||||
'base_commit' => request.base_commit,
|
||||
'head_commit' => request.head_commit,
|
||||
'result' => request.result,
|
||||
'message' => request.message,
|
||||
'pull_request' => request.pull_request?,
|
||||
'pull_request_number' => request.pull_request_number,
|
||||
'pull_request_title' => request.pull_request_title,
|
||||
'branch' => request.branch_name,
|
||||
'tag' => request.tag_name
|
||||
}
|
||||
|
||||
data['build_id'] = request.builds.first.id if request.builds.present?
|
||||
|
||||
data
|
||||
end
|
||||
|
||||
def commit_data(commit)
|
||||
{
|
||||
'id' => commit.id,
|
||||
'sha' => commit.commit,
|
||||
'branch' => commit.branch,
|
||||
'message' => commit.message,
|
||||
'committed_at' => format_date(commit.committed_at),
|
||||
'author_name' => commit.author_name,
|
||||
'author_email' => commit.author_email,
|
||||
'committer_name' => commit.committer_name,
|
||||
'committer_email' => commit.committer_email,
|
||||
'compare_url' => commit.compare_url,
|
||||
'pull_request_number' => commit.pull_request_number
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
28
lib/travis/api/serialize/v2/http/ssh_key.rb
Normal file
28
lib/travis/api/serialize/v2/http/ssh_key.rb
Normal file
|
@ -0,0 +1,28 @@
|
|||
require 'openssl'
|
||||
require 'travis/private_key'
|
||||
|
||||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
module V2
|
||||
module Http
|
||||
class SshKey < Travis::Api::Serialize::ObjectSerializer
|
||||
attributes :id, :description, :fingerprint
|
||||
|
||||
def id
|
||||
object.repository_id
|
||||
end
|
||||
|
||||
def fingerprint
|
||||
value = object.value.decrypt
|
||||
return unless value
|
||||
PrivateKey.new(value).fingerprint
|
||||
rescue OpenSSL::PKey::RSAError
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
28
lib/travis/api/serialize/v2/http/ssl_key.rb
Normal file
28
lib/travis/api/serialize/v2/http/ssl_key.rb
Normal file
|
@ -0,0 +1,28 @@
|
|||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
module V2
|
||||
module Http
|
||||
class SslKey
|
||||
attr_reader :key
|
||||
|
||||
def initialize(key, options = {})
|
||||
@key = key
|
||||
end
|
||||
|
||||
def fingerprint
|
||||
PrivateKey.new(key.private_key).fingerprint
|
||||
end
|
||||
|
||||
def data
|
||||
{
|
||||
'key' => key.public_key,
|
||||
'fingerprint' => fingerprint
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
51
lib/travis/api/serialize/v2/http/user.rb
Normal file
51
lib/travis/api/serialize/v2/http/user.rb
Normal file
|
@ -0,0 +1,51 @@
|
|||
require 'travis/api/serialize/formats'
|
||||
require 'travis/github/oauth'
|
||||
|
||||
module Travis
|
||||
module Api
|
||||
module Serialize
|
||||
module V2
|
||||
module Http
|
||||
class User
|
||||
include Formats
|
||||
|
||||
attr_reader :user, :options
|
||||
|
||||
def initialize(user, options = {})
|
||||
@user = user
|
||||
@options = options
|
||||
end
|
||||
|
||||
def data
|
||||
{
|
||||
'user' => user_data,
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def user_data
|
||||
{
|
||||
'id' => user.id,
|
||||
'name' => user.name,
|
||||
'login' => user.login,
|
||||
'email' => user.email,
|
||||
'gravatar_id' => user.email ? Digest::MD5.hexdigest(user.email) : "",
|
||||
'locale' => user.locale,
|
||||
'is_syncing' => user.syncing?,
|
||||
'synced_at' => format_date(user.synced_at),
|
||||
'correct_scopes' => Github::Oauth.correct_scopes?(user),
|
||||
'created_at' => format_date(user.created_at),
|
||||
'channels' => channels
|
||||
}
|
||||
end
|
||||
|
||||
def channels
|
||||
["user-#{user.id}"] + user.repository_ids.map { |id| "repo-#{id}" }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user