use branch for storing cron
This commit is contained in:
parent
0a91a69d0d
commit
aca632ed15
|
@ -60,11 +60,11 @@ module Travis::API::V3
|
|||
end
|
||||
|
||||
def cron_visible?(cron)
|
||||
visible? cron.repository
|
||||
visible? cron.branch.repository
|
||||
end
|
||||
|
||||
def cron_writable?(cron)
|
||||
writable? cron.repository
|
||||
writable? cron.branch.repository
|
||||
end
|
||||
|
||||
def job_visible?(job)
|
||||
|
|
|
@ -4,6 +4,7 @@ module Travis::API::V3
|
|||
belongs_to :last_build, class_name: 'Travis::API::V3::Models::Build'.freeze
|
||||
has_many :builds, foreign_key: [:repository_id, :branch], primary_key: [:repository_id, :name], order: 'builds.id DESC'.freeze, conditions: { event_type: 'push' }
|
||||
has_many :commits, foreign_key: [:repository_id, :branch], primary_key: [:repository_id, :name], order: 'commits.id DESC'.freeze
|
||||
has_many :crons, dependent: :delete_all
|
||||
|
||||
def default_branch
|
||||
name == repository.default_branch_name
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
module Travis::API::V3
|
||||
class Models::Cron < Model
|
||||
|
||||
belongs_to :repository
|
||||
belongs_to :branch
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,7 +6,6 @@ module Travis::API::V3
|
|||
has_many :builds, dependent: :delete_all, order: 'builds.id DESC'.freeze
|
||||
has_many :permissions, dependent: :delete_all
|
||||
has_many :users, through: :permissions
|
||||
has_many :crons, dependent: :delete_all
|
||||
|
||||
belongs_to :owner, polymorphic: true
|
||||
belongs_to :last_build, class_name: 'Travis::API::V3::Models::Build'.freeze
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
module Travis::API::V3
|
||||
class Queries::Crons < Query
|
||||
|
||||
def find(repository)
|
||||
repository.crons
|
||||
def find(branch)
|
||||
branch.crons
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,7 +3,11 @@ require 'travis/api/v3/renderer/model_renderer'
|
|||
module Travis::API::V3
|
||||
class Renderer::Cron < Renderer::ModelRenderer
|
||||
representation(:minimal, :id)
|
||||
representation(:standard, :id, :repository)
|
||||
representation(:standard, :id, :branch, :repository)
|
||||
|
||||
def repository
|
||||
model.branch.repository
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -82,6 +82,13 @@ module Travis::API::V3
|
|||
resource :branch do
|
||||
route '/branch/{branch.name}'
|
||||
get :find
|
||||
|
||||
resource :crons do
|
||||
route '/crons'
|
||||
get :find
|
||||
|
||||
post :create, '/create'
|
||||
end
|
||||
end
|
||||
|
||||
resource :branches do
|
||||
|
@ -96,9 +103,7 @@ module Travis::API::V3
|
|||
|
||||
resource :crons do
|
||||
route '/crons'
|
||||
get :find
|
||||
|
||||
post :create, '/create'
|
||||
get :for_repository
|
||||
end
|
||||
|
||||
resource :requests do
|
||||
|
|
|
@ -5,9 +5,10 @@ module Travis::API::V3
|
|||
def run!
|
||||
raise LoginRequired unless access_control.logged_in? or access_control.full_access?
|
||||
raise NotFound unless repository = find(:repository)
|
||||
raise NotFound unless branch = find(:branch, repository)
|
||||
access_control.permissions(repository).create_cron!
|
||||
|
||||
Models::Cron.create(repository: repository)
|
||||
Models::Cron.create(branch: branch)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -3,7 +3,7 @@ module Travis::API::V3
|
|||
paginate
|
||||
|
||||
def run!
|
||||
query.find(find(:repository))
|
||||
query.find(find(:branch, find(:repository)))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
9
lib/travis/api/v3/services/crons/for_repository.rb
Normal file
9
lib/travis/api/v3/services/crons/for_repository.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
module Travis::API::V3
|
||||
class Services::Crons::ForRepository < Service
|
||||
paginate
|
||||
|
||||
def run!
|
||||
Models::Cron.where(:branch_id => find(:repository).branches)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user