Compare commits
140 Commits
fix_repo_c
...
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 | ||
![]() |
21f445ad64 | ||
![]() |
1ec8dba7e4 | ||
![]() |
ac7e610510 | ||
![]() |
7d52b06533 | ||
![]() |
829366a554 | ||
![]() |
4b14f17cc5 | ||
![]() |
f5bc526f25 | ||
![]() |
1a07e199b5 | ||
![]() |
91e9fcebf7 | ||
![]() |
871b915515 | ||
![]() |
77dcdaa482 | ||
![]() |
0aeec35935 | ||
![]() |
769ae71076 | ||
![]() |
88d9000042 | ||
![]() |
81e93ca710 | ||
![]() |
00fb01bd7a | ||
![]() |
cae6da540f | ||
![]() |
026dc4cb98 | ||
![]() |
2303db9f4f |
|
@ -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
|
||||
|
|
1
Gemfile
1
Gemfile
|
@ -3,7 +3,6 @@ gemspec
|
|||
|
||||
gem 's3', github: 'travis-ci/s3'
|
||||
|
||||
gem 'travis-core', path: 'vendor/travis-core'
|
||||
gem 'travis-support', github: 'travis-ci/travis-support'
|
||||
gem 'travis-amqp', github: 'travis-ci/travis-amqp'
|
||||
gem 'travis-config', '~> 0.1.0'
|
||||
|
|
28
Gemfile.lock
28
Gemfile.lock
|
@ -96,33 +96,11 @@ PATH
|
|||
simple_states (~> 1.0.0)
|
||||
sinatra (~> 1.3)
|
||||
sinatra-contrib (~> 1.3)
|
||||
tool
|
||||
travis-support
|
||||
useragent
|
||||
virtus (~> 1.0.0)
|
||||
|
||||
PATH
|
||||
remote: vendor/travis-core
|
||||
specs:
|
||||
travis-core (0.0.1)
|
||||
activerecord (~> 3.2.19)
|
||||
coder (~> 0.4.0)
|
||||
data_migrations (~> 0.0.1)
|
||||
gh
|
||||
google-api-client (~> 0.9.4)
|
||||
hashr
|
||||
metriks (~> 0.9.7)
|
||||
multi_json
|
||||
pusher (~> 0.14.0)
|
||||
railties (~> 3.2.19)
|
||||
rake
|
||||
redis (~> 3.0)
|
||||
rollout (~> 1.1.0)
|
||||
s3 (~> 0.3)
|
||||
simple_states (~> 1.0.0)
|
||||
thor
|
||||
travis-config (~> 0.1.0)
|
||||
virtus (~> 1.0.0)
|
||||
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
|
@ -171,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)
|
||||
|
@ -411,7 +386,6 @@ DEPENDENCIES
|
|||
travis-amqp!
|
||||
travis-api!
|
||||
travis-config (~> 0.1.0)
|
||||
travis-core!
|
||||
travis-migrations!
|
||||
travis-settings!
|
||||
travis-sidekiqs!
|
||||
|
|
|
@ -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
|
||||
|
|
12
Rakefile
12
Rakefile
|
@ -18,7 +18,7 @@ end
|
|||
# t.pattern = 'spec_core/**{,/*/**}/*_spec.rb'
|
||||
# end
|
||||
#
|
||||
# task :default => [:spec, :spec_core]
|
||||
# task :default => [:spec]
|
||||
# rescue LoadError => e
|
||||
# puts e.inspect
|
||||
# end
|
||||
|
@ -27,18 +27,8 @@ end
|
|||
namespace :spec do
|
||||
desc 'Run all specs'
|
||||
task :all do
|
||||
sh 'bundle exec rspec -r spec_helper spec spec_core'
|
||||
end
|
||||
|
||||
desc 'Run api specs'
|
||||
task :api do
|
||||
sh 'bundle exec rspec -r spec_helper spec'
|
||||
end
|
||||
|
||||
desc 'Run core specs'
|
||||
task :core do
|
||||
sh 'bundle exec rspec -r spec_helper spec_core'
|
||||
end
|
||||
end
|
||||
|
||||
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,7 +1,6 @@
|
|||
require 'pusher'
|
||||
require 'travis/support'
|
||||
require 'travis/support/database'
|
||||
require 'travis/version'
|
||||
require 'travis/redis_pool'
|
||||
require 'travis/errors'
|
||||
|
||||
|
@ -19,7 +18,6 @@ module Travis
|
|||
require 'travis/model'
|
||||
require 'travis/task'
|
||||
require 'travis/event'
|
||||
require 'travis/addons'
|
||||
require 'travis/api/serialize'
|
||||
require 'travis/config/defaults'
|
||||
require 'travis/features'
|
||||
|
@ -43,7 +41,6 @@ module Travis
|
|||
Travis.logger.info('Setting up Travis::Core')
|
||||
|
||||
Github.setup
|
||||
Addons.register
|
||||
Services.register
|
||||
Github::Services.register
|
||||
end
|
||||
|
|
|
@ -26,6 +26,7 @@ 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
|
||||
|
@ -81,11 +82,7 @@ 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
|
||||
|
|
|
@ -179,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)
|
||||
|
|
|
@ -23,11 +23,6 @@ class Travis::Api::App
|
|||
Metriks.meter("api.request.cancel_build").mark
|
||||
|
||||
service = Travis::Enqueue::Services::CancelModel.new(current_user, { build_id: params[:id] })
|
||||
repository_owner = service.target.repository.owner
|
||||
|
||||
if !Travis::Features.enabled_for_all?(:enqueue_to_hub) && !Travis::Features.owner_active?(:enqueue_to_hub, repository_owner)
|
||||
service = self.service(:cancel_build, params.merge(source: 'api'))
|
||||
end
|
||||
|
||||
if !service.authorized?
|
||||
json = { error: {
|
||||
|
@ -48,11 +43,8 @@ class Travis::Api::App
|
|||
respond_with json
|
||||
else
|
||||
payload = { id: params[:id], user_id: current_user.id, source: 'api' }
|
||||
if service.respond_to?(:push)
|
||||
service.push("build:cancel", payload)
|
||||
else
|
||||
Travis::Sidekiq::BuildCancellation.perform_async(payload)
|
||||
end
|
||||
|
||||
service.push("build:cancel", payload)
|
||||
|
||||
Metriks.meter("api.request.cancel_build.success").mark
|
||||
status 204
|
||||
|
@ -62,24 +54,15 @@ class Travis::Api::App
|
|||
post '/:id/restart' do
|
||||
Metriks.meter("api.request.restart_build").mark
|
||||
service = Travis::Enqueue::Services::RestartModel.new(current_user, build_id: params[:id])
|
||||
repository_owner = service.target.repository.owner
|
||||
|
||||
if !Travis::Features.enabled_for_all?(:enqueue_to_hub) && !Travis::Features.owner_active?(:enqueue_to_hub, repository_owner)
|
||||
service = self.service(:reset_model, build_id: params[:id])
|
||||
end
|
||||
|
||||
result = if !service.accept?
|
||||
status 400
|
||||
false
|
||||
elsif service.respond_to?(:push)
|
||||
else
|
||||
payload = { id: params[:id], user_id: current_user.id }
|
||||
service.push("build:restart", payload)
|
||||
status 202
|
||||
true
|
||||
else
|
||||
Travis::Sidekiq::BuildRestart.perform_async(id: params[:id], user_id: current_user.id)
|
||||
status 202
|
||||
true
|
||||
end
|
||||
|
||||
respond_with(result: result, flash: service.messages)
|
||||
|
|
|
@ -30,10 +30,6 @@ class Travis::Api::App
|
|||
Metriks.meter("api.request.cancel_job").mark
|
||||
|
||||
service = Travis::Enqueue::Services::CancelModel.new(current_user, { job_id: params[:id] })
|
||||
repository_owner = service.target.repository.owner
|
||||
if !Travis::Features.enabled_for_all?(:enqueue_to_hub) && !Travis::Features.owner_active?(:enqueue_to_hub, repository_owner)
|
||||
service = self.service(:cancel_job, params.merge(source: 'api'))
|
||||
end
|
||||
|
||||
if !service.authorized?
|
||||
json = { error: {
|
||||
|
@ -54,11 +50,7 @@ class Travis::Api::App
|
|||
respond_with json
|
||||
else
|
||||
payload = { id: params[:id], user_id: current_user.id, source: 'api' }
|
||||
if service.respond_to?(:push)
|
||||
service.push("job:cancel", payload)
|
||||
else
|
||||
Travis::Sidekiq::JobCancellation.perform_async(payload)
|
||||
end
|
||||
service.push("job:cancel", payload)
|
||||
|
||||
Metriks.meter("api.request.cancel_job.success").mark
|
||||
status 204
|
||||
|
@ -69,23 +61,15 @@ class Travis::Api::App
|
|||
Metriks.meter("api.request.restart_job").mark
|
||||
|
||||
service = Travis::Enqueue::Services::RestartModel.new(current_user, { job_id: params[:id] })
|
||||
repository_owner = service.target.repository.owner
|
||||
if !Travis::Features.enabled_for_all?(:enqueue_to_hub) && !Travis::Features.owner_active?(:enqueue_to_hub, repository_owner)
|
||||
service = self.service(:reset_model, job_id: params[:id])
|
||||
end
|
||||
|
||||
result = if !service.accept?
|
||||
status 400
|
||||
false
|
||||
elsif service.respond_to?(:push)
|
||||
else
|
||||
payload = {id: params[:id], user_id: current_user.id}
|
||||
service.push("job:restart", payload)
|
||||
status 202
|
||||
true
|
||||
else
|
||||
Travis::Sidekiq::JobRestart.perform_async(id: params[:id], user_id: current_user.id)
|
||||
status 202
|
||||
result = true
|
||||
end
|
||||
|
||||
respond_with(result: result, flash: service.messages)
|
||||
|
|
|
@ -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
|
||||
|
@ -28,18 +29,14 @@ class Travis::Api::App
|
|||
#
|
||||
# I think we need to properly deprecate this by publishing a blog post.
|
||||
Metriks.meter("api.request.restart").mark
|
||||
service = Travis::Enqueue::Services::RestartModel.new(current_user, params)
|
||||
params[:user_id] = service.target.repository.owner.id
|
||||
|
||||
service = Travis::Enqueue::Services::RestartModel.new(current_user, { build_id: params[:build_id] })
|
||||
repository_owner = service.target.repository.owner
|
||||
type = params[:build_id] ? 'build' : 'job'
|
||||
params[:id] = params[:build_id] || params[:job_id]
|
||||
|
||||
if !Travis::Features.enabled_for_all?(:enqueue_to_hub) && !Travis::Features.owner_active?(:enqueue_to_hub, repository_owner)
|
||||
respond_with service(:reset_model, params)
|
||||
elsif service.respond_to?(:push)
|
||||
payload = {id: params[:build_id], user_id: current_user.id}
|
||||
service.push("job:restart", payload)
|
||||
status 202
|
||||
true
|
||||
end
|
||||
service.push("#{type}:restart", params)
|
||||
respond_with(result: true, flash: service.messages)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,15 +4,15 @@ module Travis::Api::App::Responders
|
|||
class Atom < Base
|
||||
ATOM_FEED_ERB = ERB.new <<-EOF
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
|
||||
<feed xmlns="http://www.w3.org/2005/Atom">
|
||||
|
||||
|
||||
<title><%= resource.first.repository.slug %> Builds</title>
|
||||
<link href="<%= endpoint.url %>" type="application/atom+xml" rel = "self" />
|
||||
<id>repo:<%= resource.first.repository.id %></id>
|
||||
<rights>Copyright (c) <%= DateTime.now.strftime("%Y") %> Travis CI GmbH</rights>
|
||||
<updated><%= DateTime.now.rfc3339 %></updated>
|
||||
|
||||
|
||||
<% resource.each do |build| %>
|
||||
<entry>
|
||||
<title><%= build.repository.slug %> Build #<%= build.number %></title>
|
||||
|
@ -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/>
|
||||
|
@ -36,7 +36,7 @@ module Travis::Api::App::Responders
|
|||
</author>
|
||||
</entry>
|
||||
<% end %>
|
||||
|
||||
|
||||
</feed>
|
||||
EOF
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ module Travis
|
|||
AlreadySyncing = ClientError .create('sync already in progress', status: 409)
|
||||
BuildAlreadyRunning = ClientError .create('build already running, cannot restart', status: 409)
|
||||
BuildNotCancelable = ClientError .create('build is not running, cannot cancel', status: 409)
|
||||
DuplicateResource = ClientError .create('resource already exists', status: 409)
|
||||
EntityMissing = NotFound .create(type: 'not_found')
|
||||
InsufficientAccess = ClientError .create(status: 403)
|
||||
JobAlreadyRunning = ClientError .create('job already running, cannot restart', status: 409)
|
||||
|
|
|
@ -30,6 +30,10 @@ module Travis::API::V3
|
|||
false
|
||||
end
|
||||
|
||||
def full_access_or_logged_in?
|
||||
full_access? || logged_in?
|
||||
end
|
||||
|
||||
def visible_repositories(list)
|
||||
# naïve implementation, replaced with smart implementation in specific subclasses
|
||||
return list if full_access?
|
||||
|
@ -92,14 +96,15 @@ module Travis::API::V3
|
|||
private_repository_visible?(repository)
|
||||
end
|
||||
|
||||
def settings_visible?(settings)
|
||||
repository_visible?(settings.repository)
|
||||
end
|
||||
|
||||
def private_repository_visible?(repository)
|
||||
false
|
||||
end
|
||||
|
||||
def repository_attr_visible?(record)
|
||||
repository_visible?(record.repository)
|
||||
end
|
||||
[:settings_visible?, :env_vars_visible?, :env_var_visible?].each { |m| alias_method m, :repository_attr_visible? }
|
||||
|
||||
def public_api?
|
||||
!Travis.config.private_api
|
||||
end
|
||||
|
|
|
@ -1,109 +0,0 @@
|
|||
require 'securerandom'
|
||||
require 'base64'
|
||||
|
||||
module Travis::API::V3
|
||||
module Extensions
|
||||
class EncryptedColumn
|
||||
attr_reader :disable, :options
|
||||
alias disabled? disable
|
||||
|
||||
def initialize(options = {})
|
||||
@options = options || {}
|
||||
@disable = self.options[:disable]
|
||||
@key = self.options[:key]
|
||||
end
|
||||
|
||||
def enabled?
|
||||
!disabled?
|
||||
end
|
||||
|
||||
def load(data)
|
||||
return nil unless data
|
||||
|
||||
data = data.to_s
|
||||
|
||||
decrypt?(data) ? decrypt(data) : data
|
||||
end
|
||||
|
||||
def dump(data)
|
||||
encrypt?(data) ? encrypt(data.to_s) : data
|
||||
end
|
||||
|
||||
def key
|
||||
@key || config.key
|
||||
end
|
||||
|
||||
def iv
|
||||
SecureRandom.hex(8)
|
||||
end
|
||||
|
||||
def prefix
|
||||
'--ENCR--'
|
||||
end
|
||||
|
||||
def decrypt?(data)
|
||||
data.present? && (!use_prefix? || prefix_used?(data))
|
||||
end
|
||||
|
||||
def encrypt?(data)
|
||||
data.present? && enabled?
|
||||
end
|
||||
|
||||
def prefix_used?(data)
|
||||
data[0..7] == prefix
|
||||
end
|
||||
|
||||
def decrypt(data)
|
||||
data = data[8..-1] if prefix_used?(data)
|
||||
|
||||
data = decode data
|
||||
|
||||
iv = data[-16..-1]
|
||||
data = data[0..-17]
|
||||
|
||||
aes = create_aes :decrypt, key.to_s, iv
|
||||
|
||||
result = aes.update(data) + aes.final
|
||||
end
|
||||
|
||||
def encrypt(data)
|
||||
iv = self.iv
|
||||
|
||||
aes = create_aes :encrypt, key.to_s, iv
|
||||
|
||||
encrypted = aes.update(data) + aes.final
|
||||
|
||||
encrypted = "#{encrypted}#{iv}"
|
||||
encrypted = encode encrypted
|
||||
encrypted = "#{prefix}#{encrypted}" if use_prefix?
|
||||
encrypted
|
||||
end
|
||||
|
||||
def use_prefix?
|
||||
options.has_key?(:use_prefix) ? options[:use_prefix] : Travis::Features.feature_inactive?(:db_encryption_prefix)
|
||||
end
|
||||
|
||||
def create_aes(mode = :encrypt, key, iv)
|
||||
aes = OpenSSL::Cipher::AES.new(256, :CBC)
|
||||
|
||||
aes.send(mode)
|
||||
aes.key = key
|
||||
aes.iv = iv
|
||||
|
||||
aes
|
||||
end
|
||||
|
||||
def config
|
||||
Travis.config.encryption
|
||||
end
|
||||
|
||||
def decode(str)
|
||||
Base64.strict_decode64 str
|
||||
end
|
||||
|
||||
def encode(str)
|
||||
Base64.strict_encode64 str
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -49,5 +49,15 @@ module Travis::API::V3
|
|||
gh.post(hooks_url, payload)
|
||||
end
|
||||
end
|
||||
|
||||
def upload_key(repository)
|
||||
keys_path = "repos/#{repository.slug}/keys"
|
||||
key = gh[keys_path].
|
||||
detect { |e| e['key'] == repository.key.encoded_public_key }
|
||||
|
||||
unless key
|
||||
gh.post keys_path, title: Travis.config.host.to_s, key: repository.key.encoded_public_key
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
5
lib/travis/api/v3/models/admin_settings.rb
Normal file
5
lib/travis/api/v3/models/admin_settings.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
module Travis::API::V3
|
||||
class Models::AdminSettings < Travis::Settings::Model
|
||||
attribute :api_builds_rate_limit, Integer
|
||||
end
|
||||
end
|
|
@ -13,7 +13,7 @@ module Travis::API::V3
|
|||
elsif last_cron_build_date >= planned_time(LastBuild)
|
||||
planned_time(ThisBuild)
|
||||
else
|
||||
Time.now
|
||||
Time.now - 5.minutes
|
||||
end
|
||||
end
|
||||
|
||||
|
|
18
lib/travis/api/v3/models/env_var.rb
Normal file
18
lib/travis/api/v3/models/env_var.rb
Normal file
|
@ -0,0 +1,18 @@
|
|||
module Travis::API::V3
|
||||
class Models::EnvVar < Travis::Settings::Model
|
||||
attribute :id, Integer
|
||||
attribute :name, String
|
||||
attribute :value, Travis::Settings::EncryptedValue
|
||||
attribute :public, Boolean
|
||||
attribute :repository_id, Integer
|
||||
|
||||
def repository
|
||||
@repository ||= Models::Repository.find(repository_id)
|
||||
end
|
||||
|
||||
validates_each :id, :name do |record, attr, value|
|
||||
others = record.repository.env_vars.select { |ev| ev.id != record.id }
|
||||
record.errors.add(:base, :duplicate_resource) if others.find { |ev| ev.send(attr) == record.send(attr) }
|
||||
end
|
||||
end
|
||||
end
|
11
lib/travis/api/v3/models/env_vars.rb
Normal file
11
lib/travis/api/v3/models/env_vars.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
module Travis::API::V3
|
||||
class Models::EnvVars < Travis::Settings::Collection
|
||||
model Models::EnvVar
|
||||
|
||||
def repository
|
||||
@repository ||= Models::Repository.find(additional_attributes[:repository_id])
|
||||
end
|
||||
|
||||
undef :to_hash
|
||||
end
|
||||
end
|
|
@ -12,6 +12,7 @@ module Travis::API::V3
|
|||
belongs_to :last_build, class_name: 'Travis::API::V3::Models::Build'.freeze
|
||||
belongs_to :current_build, class_name: 'Travis::API::V3::Models::Build'.freeze
|
||||
|
||||
has_one :key, class_name: 'Travis::API::V3::Models::SSLKey'.freeze
|
||||
has_one :default_branch,
|
||||
foreign_key: [:repository_id, :name],
|
||||
primary_key: [:id, :default_branch],
|
||||
|
@ -65,7 +66,21 @@ module Travis::API::V3
|
|||
end
|
||||
|
||||
def settings
|
||||
@settings ||= JSON.load(super)
|
||||
@settings ||= JSON.load(super || '{}'.freeze)
|
||||
end
|
||||
|
||||
def user_settings
|
||||
@user_settings ||= Models::UserSettings.new(settings)
|
||||
end
|
||||
|
||||
def admin_settings
|
||||
@admin_settings ||= Models::AdminSettings.new(settings)
|
||||
end
|
||||
|
||||
def env_vars
|
||||
@env_vars ||= Models::EnvVars.new.tap do |vars|
|
||||
vars.load(settings.fetch('env_vars', []), repository_id: self.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,12 +1,5 @@
|
|||
module Travis::API::V3
|
||||
class Models::Settings
|
||||
DEFAULTS = {
|
||||
'builds_only_with_travis_yml' => false,
|
||||
'build_pushes' => true,
|
||||
'build_pull_requests' => true,
|
||||
'maximum_number_of_builds' => 0
|
||||
}.freeze
|
||||
|
||||
attr_reader :repository
|
||||
|
||||
def initialize(repository)
|
||||
|
@ -14,13 +7,11 @@ module Travis::API::V3
|
|||
end
|
||||
|
||||
def to_h
|
||||
DEFAULTS.merge(repository.settings || {})
|
||||
repository.user_settings.to_hash
|
||||
end
|
||||
|
||||
def update(settings = {})
|
||||
settings = to_h.merge(settings)
|
||||
repository.settings.clear
|
||||
settings.each { |k, v| repository.settings[k] = v }
|
||||
repository.user_settings.update(settings)
|
||||
repository.save!
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,29 @@
|
|||
module Travis::API::V3
|
||||
class Models::SSLKey < Model
|
||||
belongs_to :repository
|
||||
|
||||
serialize :private_key, Travis::Settings::EncryptedColumn.new
|
||||
|
||||
def encoded_public_key
|
||||
key = build_key.public_key
|
||||
['ssh-rsa ', "\0\0\0\assh-rsa#{sized_bytes(key.e)}#{sized_bytes(key.n)}"].pack('a*m').gsub("\n", '')
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def build_key
|
||||
@build_key ||= OpenSSL::PKey::RSA.new(private_key)
|
||||
end
|
||||
|
||||
def sized_bytes(value)
|
||||
bytes = to_byte_array(value.to_i)
|
||||
[bytes.size, *bytes].pack('NC*')
|
||||
end
|
||||
|
||||
def to_byte_array(num, *significant)
|
||||
return significant if num.between?(-1, 0) and significant[0][7] == num[7]
|
||||
to_byte_array(*num.divmod(256)) + significant
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@ module Travis::API::V3
|
|||
class Models::Token < Model
|
||||
belongs_to :user
|
||||
validate :token, presence: true
|
||||
serialize :token, Extensions::EncryptedColumn.new(disable: true)
|
||||
serialize :token, Travis::Settings::EncryptedColumn.new(disable: true)
|
||||
before_validation :generate_token, on: :create
|
||||
|
||||
protected
|
||||
|
|
|
@ -9,7 +9,7 @@ module Travis::API::V3
|
|||
has_many :stars
|
||||
has_one :subscription, as: :owner
|
||||
|
||||
serialize :github_oauth_token, Extensions::EncryptedColumn.new(disable: true)
|
||||
serialize :github_oauth_token, Travis::Settings::EncryptedColumn.new(disable: true)
|
||||
|
||||
def token
|
||||
tokens.first_or_create.token
|
||||
|
|
8
lib/travis/api/v3/models/user_settings.rb
Normal file
8
lib/travis/api/v3/models/user_settings.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
module Travis::API::V3
|
||||
class Models::UserSettings < Travis::Settings::Model
|
||||
attribute :builds_only_with_travis_yml, Boolean, default: false
|
||||
attribute :build_pushes, Boolean, default: true
|
||||
attribute :build_pull_requests, Boolean, default: true
|
||||
attribute :maximum_number_of_builds, Integer, default: 0
|
||||
end
|
||||
end
|
|
@ -12,26 +12,19 @@ module Travis::API::V3
|
|||
|
||||
def cancel(user)
|
||||
raise BuildNotCancelable if %w(passed failed canceled errored).include? find.state
|
||||
|
||||
payload = { id: id, user_id: user.id, source: 'api' }
|
||||
if Travis::Features.enabled_for_all?(:enqueue_to_hub) || Travis::Features.owner_active?(:enqueue_to_hub, find.repository.owner)
|
||||
service = Travis::Enqueue::Services::CancelModel.new(user, { build_id: id })
|
||||
service.push("build:cancel", payload)
|
||||
else
|
||||
perform_async(:build_cancellation, payload)
|
||||
end
|
||||
service = Travis::Enqueue::Services::CancelModel.new(user, { build_id: id })
|
||||
service.push("build:cancel", payload)
|
||||
payload
|
||||
end
|
||||
|
||||
def restart(user)
|
||||
raise BuildAlreadyRunning if %w(received queued started).include? find.state
|
||||
if Travis::Features.enabled_for_all?(:enqueue_to_hub) || Travis::Features.owner_active?(:enqueue_to_hub, find.repository.owner)
|
||||
service = Travis::Enqueue::Services::RestartModel.new(user, { build_id: id })
|
||||
payload = { id: id, user_id: user.id }
|
||||
service.push("build:restart", payload)
|
||||
else
|
||||
payload = { id: id, user_id: user.id, source: 'api' }
|
||||
perform_async(:build_restart, payload)
|
||||
end
|
||||
|
||||
service = Travis::Enqueue::Services::RestartModel.new(user, { build_id: id })
|
||||
payload = { id: id, user_id: user.id }
|
||||
service.push("build:restart", payload)
|
||||
payload
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,7 +7,14 @@ module Travis::API::V3
|
|||
|
||||
def start_all()
|
||||
Models::Cron.all.select do |cron|
|
||||
start(cron) if cron.next_enqueuing <= Time.now
|
||||
begin
|
||||
@cron = cron
|
||||
start(cron) if cron.next_enqueuing <= Time.now
|
||||
rescue => e
|
||||
Raven.capture_exception(e, tags: { 'cron_id' => @cron.try(:id) })
|
||||
sleep(10) # This ensures the dyno does not spin down before the http request to send the error to sentry completes
|
||||
next
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -19,7 +26,8 @@ module Travis::API::V3
|
|||
return false
|
||||
end
|
||||
|
||||
user_id = branch.repository.users.detect { |u| u.github_oauth_token }.id
|
||||
user_id = branch.repository.users.detect { |u| u.github_oauth_token }.try(:id)
|
||||
user_id ||= branch.repository.owner.id
|
||||
|
||||
payload = {
|
||||
repository: { id: branch.repository.github_id, owner_name: branch.repository.owner_name, name: branch.repository.name },
|
||||
|
@ -30,8 +38,6 @@ module Travis::API::V3
|
|||
class_name, queue = Query.sidekiq_queue(:build_request)
|
||||
::Sidekiq::Client.push('queue'.freeze => queue, 'class'.freeze => class_name, 'args'.freeze => [{type: 'cron'.freeze, payload: JSON.dump(payload), credentials: {}}])
|
||||
true
|
||||
rescue => e
|
||||
puts e.message, e.backtrace
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
21
lib/travis/api/v3/queries/env_var.rb
Normal file
21
lib/travis/api/v3/queries/env_var.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
module Travis::API::V3
|
||||
class Queries::EnvVar < Query
|
||||
params :id, :name, :value, :public, prefix: :env_var
|
||||
|
||||
def find(repository)
|
||||
repository.env_vars.find(id)
|
||||
end
|
||||
|
||||
def update(repository)
|
||||
if env_var = find(repository)
|
||||
env_var.update(env_var_params)
|
||||
repository.save!
|
||||
env_var
|
||||
end
|
||||
end
|
||||
|
||||
def delete(repository)
|
||||
repository.env_vars.destroy(id)
|
||||
end
|
||||
end
|
||||
end
|
25
lib/travis/api/v3/queries/env_vars.rb
Normal file
25
lib/travis/api/v3/queries/env_vars.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
module Travis::API::V3
|
||||
class Queries::EnvVars < Query
|
||||
params :id, :name, :value, :public, prefix: :env_var
|
||||
|
||||
def find(repository)
|
||||
repository.env_vars
|
||||
end
|
||||
|
||||
def create(repository)
|
||||
env_var = repository.env_vars.create(env_var_params)
|
||||
handle_errors(env_var) unless env_var.valid?
|
||||
repository.save!
|
||||
env_var
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def handle_errors(env_var)
|
||||
base = env_var.errors[:base]
|
||||
raise WrongParams if base.include?(:format)
|
||||
raise DuplicateResource if base.include?(:duplicate_resource)
|
||||
raise ServerError
|
||||
end
|
||||
end
|
||||
end
|
|
@ -12,28 +12,19 @@ module Travis::API::V3
|
|||
|
||||
def cancel(user)
|
||||
raise JobNotCancelable if %w(passed failed canceled errored).include? find.state
|
||||
|
||||
payload = { id: id, user_id: user.id, source: 'api' }
|
||||
#look for repo.owner instead and look if the user belongs to the repo, instead of using user for the feature flag
|
||||
if Travis::Features.enabled_for_all?(:enqueue_to_hub) || Travis::Features.owner_active?(:enqueue_to_hub, find.repository.owner)
|
||||
service = Travis::Enqueue::Services::CancelModel.new(user, { job_id: id })
|
||||
service.push("job:cancel", payload)
|
||||
else
|
||||
perform_async(:job_cancellation, payload)
|
||||
end
|
||||
service = Travis::Enqueue::Services::CancelModel.new(user, { job_id: id })
|
||||
service.push("job:cancel", payload)
|
||||
payload
|
||||
end
|
||||
|
||||
def restart(user)
|
||||
raise JobAlreadyRunning if %w(received queued started).include? find.state
|
||||
|
||||
if Travis::Features.enabled_for_all?(:enqueue_to_hub) || Travis::Features.owner_active?(:enqueue_to_hub, find.repository.owner)
|
||||
service = Travis::Enqueue::Services::RestartModel.new(user, { job_id: id })
|
||||
payload = { id: id, user_id: user.id }
|
||||
service.push("job:restart", payload)
|
||||
else
|
||||
payload = { id: id, user_id: user.id, source: 'api' }
|
||||
perform_async(:job_restart, payload)
|
||||
end
|
||||
service = Travis::Enqueue::Services::RestartModel.new(user, { job_id: id })
|
||||
payload = { id: id, user_id: user.id }
|
||||
service.push("job:restart", payload)
|
||||
payload
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,7 +10,7 @@ module Travis::API::V3
|
|||
extend self
|
||||
|
||||
def clear(**args)
|
||||
args.select { |key, value| !value.nil? }
|
||||
args.compact
|
||||
end
|
||||
|
||||
def href(type, string_args = nil, script_name: nil, **args)
|
||||
|
@ -49,6 +49,7 @@ module Travis::API::V3
|
|||
when Model then render_model(value, **options)
|
||||
when ActiveRecord::Relation then render_value(value.to_a, **options)
|
||||
when ActiveRecord::Associations::CollectionProxy then render_value(value.to_a, **options)
|
||||
when Travis::Settings::EncryptedValue then value.decrypt
|
||||
else raise ArgumentError, 'cannot render %p (%p)' % [value.class, value]
|
||||
end
|
||||
end
|
||||
|
|
5
lib/travis/api/v3/renderer/env_var.rb
Normal file
5
lib/travis/api/v3/renderer/env_var.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
module Travis::API::V3
|
||||
class Renderer::EnvVar < Renderer::ModelRenderer
|
||||
representation :standard, :id, :name, :value, :public
|
||||
end
|
||||
end
|
6
lib/travis/api/v3/renderer/env_vars.rb
Normal file
6
lib/travis/api/v3/renderer/env_vars.rb
Normal file
|
@ -0,0 +1,6 @@
|
|||
module Travis::API::V3
|
||||
class Renderer::EnvVars < Renderer::CollectionRenderer
|
||||
type :env_vars
|
||||
collection_key :env_vars
|
||||
end
|
||||
end
|
|
@ -110,6 +110,7 @@ module Travis::API::V3
|
|||
end
|
||||
|
||||
fields.each do |field|
|
||||
next if field == :value && !@model.public?
|
||||
value = Renderer.render_value(send(field),
|
||||
access_control: access_control,
|
||||
script_name: script_name,
|
||||
|
|
|
@ -18,7 +18,6 @@ module Travis::API::V3
|
|||
env_params = params(env)
|
||||
factory, params = routes.factory_for(env['REQUEST_METHOD'.freeze], env['PATH_INFO'.freeze])
|
||||
|
||||
|
||||
raise NotFound unless factory
|
||||
metrics.name_after(factory)
|
||||
|
||||
|
|
|
@ -123,6 +123,19 @@ module Travis::API::V3
|
|||
get :find
|
||||
patch :update
|
||||
end
|
||||
|
||||
resource :env_vars do
|
||||
route '/env_vars'
|
||||
get :for_repository
|
||||
post :create
|
||||
end
|
||||
|
||||
resource :env_var do
|
||||
route '/env_var/{env_var.id}'
|
||||
get :find
|
||||
patch :update
|
||||
delete :delete
|
||||
end
|
||||
end
|
||||
|
||||
resource :user do
|
||||
|
|
|
@ -66,6 +66,11 @@ module Travis::API::V3
|
|||
object
|
||||
end
|
||||
|
||||
def check_login_and_find(*args)
|
||||
raise LoginRequired unless access_control.full_access_or_logged_in?
|
||||
find(*args) or raise NotFound
|
||||
end
|
||||
|
||||
def not_found(actually_not_found = false, type = nil)
|
||||
type, actually_not_found = actually_not_found, false if actually_not_found.is_a? Symbol
|
||||
error = actually_not_found ? EntityMissing : NotFound
|
||||
|
|
|
@ -11,6 +11,8 @@ module Travis::API::V3
|
|||
Builds = Module.new { extend Services }
|
||||
Cron = Module.new { extend Services }
|
||||
Crons = Module.new { extend Services }
|
||||
EnvVar = Module.new { extend Services }
|
||||
EnvVars = Module.new { extend Services }
|
||||
Job = Module.new { extend Services }
|
||||
Jobs = Module.new { extend Services }
|
||||
Lint = Module.new { extend Services }
|
||||
|
|
|
@ -2,8 +2,7 @@ module Travis::API::V3
|
|||
class Services::Build::Cancel < Service
|
||||
|
||||
def run
|
||||
raise LoginRequired unless access_control.logged_in? or access_control.full_access?
|
||||
raise NotFound unless build = find(:build)
|
||||
build = check_login_and_find(:build)
|
||||
access_control.permissions(build).cancel!
|
||||
|
||||
query.cancel(access_control.user)
|
||||
|
|
|
@ -2,8 +2,7 @@ module Travis::API::V3
|
|||
class Services::Build::Restart < Service
|
||||
|
||||
def run
|
||||
raise LoginRequired unless access_control.logged_in? or access_control.full_access?
|
||||
raise NotFound unless build = find(:build)
|
||||
build = check_login_and_find(:build)
|
||||
access_control.permissions(build).restart!
|
||||
|
||||
query.restart(access_control.user)
|
||||
|
|
|
@ -4,8 +4,7 @@ module Travis::API::V3
|
|||
params :interval, :disable_by_build
|
||||
|
||||
def run!
|
||||
raise LoginRequired unless access_control.logged_in? or access_control.full_access?
|
||||
raise NotFound unless repository = find(:repository)
|
||||
repository = check_login_and_find(:repository)
|
||||
raise NotFound unless branch = find(:branch, repository)
|
||||
raise Error.new('Crons can only be set up for branches existing on GitHub!', status: 422) unless branch.exists_on_github
|
||||
raise Error.new('Invalid value for interval. Interval must be "daily", "weekly" or "monthly"!', status: 422) unless ["daily", "weekly", "monthly"].include?(params["interval"])
|
||||
|
|
|
@ -3,8 +3,7 @@ module Travis::API::V3
|
|||
#params :id
|
||||
|
||||
def run!
|
||||
raise LoginRequired unless access_control.logged_in? or access_control.full_access?
|
||||
cron = find
|
||||
cron = check_login_and_find
|
||||
access_control.permissions(cron).delete!
|
||||
cron.destroy
|
||||
end
|
||||
|
|
11
lib/travis/api/v3/services/env_var/delete.rb
Normal file
11
lib/travis/api/v3/services/env_var/delete.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
module Travis::API::V3
|
||||
class Services::EnvVar::Delete < Service
|
||||
params :id, prefix: :repository
|
||||
params :id, prefix: :env_var
|
||||
|
||||
def run!
|
||||
repository = check_login_and_find(:repository)
|
||||
query.delete(repository)
|
||||
end
|
||||
end
|
||||
end
|
11
lib/travis/api/v3/services/env_var/find.rb
Normal file
11
lib/travis/api/v3/services/env_var/find.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
module Travis::API::V3
|
||||
class Services::EnvVar::Find < Service
|
||||
params :id, prefix: :repository
|
||||
params :id, prefix: :env_var
|
||||
|
||||
def run!
|
||||
repository = check_login_and_find(:repository)
|
||||
query.find(repository)
|
||||
end
|
||||
end
|
||||
end
|
11
lib/travis/api/v3/services/env_var/update.rb
Normal file
11
lib/travis/api/v3/services/env_var/update.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
module Travis::API::V3
|
||||
class Services::EnvVar::Update < Service
|
||||
params :id, prefix: :repository
|
||||
params :id, :name, :value, :public, prefix: :env_var
|
||||
|
||||
def run!
|
||||
repository = check_login_and_find(:repository)
|
||||
query.update(repository)
|
||||
end
|
||||
end
|
||||
end
|
12
lib/travis/api/v3/services/env_vars/create.rb
Normal file
12
lib/travis/api/v3/services/env_vars/create.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
module Travis::API::V3
|
||||
class Services::EnvVars::Create < Service
|
||||
params :id, prefix: :repository
|
||||
params :id, :name, :value, :public, prefix: :env_var
|
||||
|
||||
def run!
|
||||
repository = check_login_and_find(:repository)
|
||||
env_var = query(:env_vars).create(repository)
|
||||
result(:env_var, env_var, status: 201)
|
||||
end
|
||||
end
|
||||
end
|
8
lib/travis/api/v3/services/env_vars/for_repository.rb
Normal file
8
lib/travis/api/v3/services/env_vars/for_repository.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
module Travis::API::V3
|
||||
class Services::EnvVars::ForRepository < Service
|
||||
def run!
|
||||
repository = check_login_and_find(:repository)
|
||||
find(:env_vars, repository)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -2,8 +2,7 @@ module Travis::API::V3
|
|||
class Services::Job::Cancel < Service
|
||||
|
||||
def run
|
||||
raise LoginRequired unless access_control.logged_in? or access_control.full_access?
|
||||
raise NotFound unless job = find(:job)
|
||||
job = check_login_and_find(:job)
|
||||
access_control.permissions(job).cancel!
|
||||
|
||||
query.cancel(access_control.user)
|
||||
|
|
|
@ -5,8 +5,7 @@ module Travis::API::V3
|
|||
attr_reader :job
|
||||
|
||||
def run
|
||||
raise LoginRequired unless access_control.logged_in? or access_control.full_access?
|
||||
raise NotFound unless @job = find(:job)
|
||||
@job = check_login_and_find(:job)
|
||||
raise WrongCredentials unless Travis.config.debug_tools_enabled or Travis::Features.active?(:debug_tools, job.repository)
|
||||
access_control.permissions(job).debug!
|
||||
|
||||
|
|
|
@ -2,8 +2,7 @@ module Travis::API::V3
|
|||
class Services::Job::Restart < Service
|
||||
|
||||
def run
|
||||
raise LoginRequired unless access_control.logged_in? or access_control.full_access?
|
||||
raise NotFound unless job = find(:job)
|
||||
job = check_login_and_find(:job)
|
||||
access_control.permissions(job).restart!
|
||||
|
||||
query.restart(access_control.user)
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
module Travis::API::V3
|
||||
class Services::Repository::Disable < Service
|
||||
def run!(activate = false)
|
||||
raise LoginRequired unless access_control.logged_in? or access_control.full_access?
|
||||
raise NotFound unless repository = find(:repository)
|
||||
repository = check_login_and_find(:repository)
|
||||
check_access(repository)
|
||||
|
||||
admin = access_control.admin_for(repository)
|
||||
|
|
|
@ -1,7 +1,14 @@
|
|||
module Travis::API::V3
|
||||
class Services::Repository::Enable < Services::Repository::Disable
|
||||
def run!
|
||||
super(true)
|
||||
repository = super(true)
|
||||
|
||||
if repository.private?
|
||||
admin = access_control.admin_for(repository)
|
||||
github(admin).upload_key(repository)
|
||||
end
|
||||
|
||||
repository
|
||||
end
|
||||
|
||||
def check_access(repository)
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
module Travis::API::V3
|
||||
class Services::Repository::Star < Service
|
||||
def run!
|
||||
raise LoginRequired unless access_control.logged_in? or access_control.full_access?
|
||||
raise NotFound unless repository = find(:repository)
|
||||
repository = check_login_and_find(:repository)
|
||||
check_access(repository)
|
||||
current_user = access_control.user
|
||||
query.star(current_user)
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
module Travis::API::V3
|
||||
class Services::Repository::Unstar < Service
|
||||
def run!
|
||||
raise LoginRequired unless access_control.logged_in? or access_control.full_access?
|
||||
raise NotFound unless repository = find(:repository)
|
||||
repository = check_login_and_find(:repository)
|
||||
check_access(repository)
|
||||
current_user = access_control.user
|
||||
query.unstar(current_user)
|
||||
|
|
|
@ -8,8 +8,7 @@ module Travis::API::V3
|
|||
params "request", "user", :config, :message, :branch, :token
|
||||
|
||||
def run
|
||||
raise LoginRequired unless access_control.logged_in? or access_control.full_access?
|
||||
raise NotFound unless repository = find(:repository)
|
||||
repository = check_login_and_find(:repository)
|
||||
access_control.permissions(repository).create_request!
|
||||
|
||||
user = find(:user) if access_control.full_access? and params_for? 'user'.freeze
|
||||
|
@ -23,11 +22,7 @@ module Travis::API::V3
|
|||
end
|
||||
|
||||
def limit(repository)
|
||||
if repository.settings.nil?
|
||||
Travis.config.requests_create_api_limit || LIMIT
|
||||
else
|
||||
repository.settings["api_builds_rate_limit"] || Travis.config.requests_create_api_limit || LIMIT
|
||||
end
|
||||
repository.admin_settings.api_builds_rate_limit || Travis.config.requests_create_api_limit || LIMIT
|
||||
end
|
||||
|
||||
def remaining_requests(repository)
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
module Travis::API::V3
|
||||
class Services::Settings::Find < Service
|
||||
def run!
|
||||
raise LoginRequired unless access_control.logged_in? or access_control.full_access?
|
||||
raise NotFound unless repo = find(:repository)
|
||||
repo = check_login_and_find(:repository)
|
||||
find(:settings, repo)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,8 +3,7 @@ module Travis::API::V3
|
|||
params :builds_only_with_travis_yml, :build_pushes, :build_pull_requests, :maximum_number_of_builds, prefix: :settings
|
||||
|
||||
def run!
|
||||
raise LoginRequired unless access_control.logged_in? or access_control.full_access?
|
||||
raise NotFound unless repository = find(:repository)
|
||||
repository = check_login_and_find(:repository)
|
||||
query.update(repository)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,8 +2,7 @@ module Travis::API::V3
|
|||
class Services::User::Sync < Service
|
||||
|
||||
def run!
|
||||
raise LoginRequired unless access_control.logged_in? or access_control.full_access?
|
||||
raise NotFound unless user = find(:user)
|
||||
user = check_login_and_find(:user)
|
||||
access_control.permissions(user).sync!
|
||||
|
||||
query.sync(user)
|
||||
|
|
|
@ -19,6 +19,8 @@ module Travis
|
|||
end
|
||||
end
|
||||
|
||||
Amqps = Amqp
|
||||
|
||||
class << self
|
||||
def parse(url)
|
||||
return Generic.new if url.nil? || url.empty?
|
||||
|
|
|
@ -8,11 +8,6 @@ module Travis
|
|||
#
|
||||
# Handler registrations are defined in Travis.config so they can be added or
|
||||
# removed easily for different environments.
|
||||
#
|
||||
# Note that Travis::Event#notify accepts an internal event name like
|
||||
# 'create' (coming from the simple_states implementation in the models) and
|
||||
# turns it into a namespaced client event name like 'job:test:created').
|
||||
# Notification handlers register for and deal with these client event names.
|
||||
module Event
|
||||
require 'travis/event/config'
|
||||
require 'travis/event/handler'
|
||||
|
@ -42,10 +37,6 @@ module Travis
|
|||
end
|
||||
end
|
||||
|
||||
def notify(event, *args)
|
||||
Travis.logger.info("DEPRECATED: Event.notify used: event=#{event}, args=#{args}")
|
||||
Travis::Event.dispatch(client_event(event, self), self, *args)
|
||||
end
|
||||
|
||||
protected
|
||||
|
|
@ -111,6 +111,7 @@ module Travis
|
|||
#
|
||||
# By default, this return false.
|
||||
def owner_active?(feature, owner)
|
||||
return false unless owner
|
||||
redis.sismember(owner_key(feature, owner), owner.id)
|
||||
end
|
||||
|
||||
|
@ -123,7 +124,7 @@ module Travis
|
|||
end
|
||||
|
||||
def owner_key(feature, owner)
|
||||
suffix = owner.class.table_name
|
||||
suffix = owner.class.table_name if owner
|
||||
"#{key(feature)}:#{suffix}"
|
||||
end
|
||||
|
|
@ -11,7 +11,7 @@ module Travis
|
|||
GH.set(
|
||||
client_id: Travis.config.oauth2.client_id,
|
||||
client_secret: Travis.config.oauth2.client_secret,
|
||||
user_agent: "Travis-CI/#{Travis::VERSION} GH/#{GH::VERSION}",
|
||||
user_agent: "GH/#{GH::VERSION}",
|
||||
origin: Travis.config.host,
|
||||
api_url: Travis.config.github.api_url,
|
||||
ssl: Travis.config.ssl.to_h.merge(Travis.config.github.ssl || {}).to_h.compact
|
|
@ -28,21 +28,21 @@ class Build
|
|||
event :finish, to: :finished, if: :should_finish?
|
||||
event :reset, to: :created
|
||||
event :cancel, to: :canceled, if: :cancelable?
|
||||
event :all, after: [:denormalize, :notify]
|
||||
event :all, after: [:denormalize]
|
||||
end
|
||||
|
||||
def should_finish?
|
||||
matrix_finished? && !finished?
|
||||
end
|
||||
|
||||
#TODO remove?
|
||||
def receive(data = {})
|
||||
self.received_at = data[:received_at]
|
||||
end
|
||||
|
||||
#TODO remove?
|
||||
def start(data = {})
|
||||
self.started_at = data[:started_at]
|
||||
end
|
||||
|
||||
#TODO remove?
|
||||
def finish(data = {})
|
||||
self.state = matrix_state
|
||||
self.duration = matrix_duration
|
||||
|
@ -50,7 +50,7 @@ class Build
|
|||
|
||||
save!
|
||||
end
|
||||
|
||||
#TODO remove?
|
||||
def cancel(options = {})
|
||||
matrix.each do |job|
|
||||
job.cancel!
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user