use branch for storing cron

This commit is contained in:
Steffen Kötte 2015-11-16 14:24:11 +01:00
parent 0a91a69d0d
commit aca632ed15
10 changed files with 31 additions and 12 deletions

View File

@ -60,11 +60,11 @@ module Travis::API::V3
end end
def cron_visible?(cron) def cron_visible?(cron)
visible? cron.repository visible? cron.branch.repository
end end
def cron_writable?(cron) def cron_writable?(cron)
writable? cron.repository writable? cron.branch.repository
end end
def job_visible?(job) def job_visible?(job)

View File

@ -4,6 +4,7 @@ module Travis::API::V3
belongs_to :last_build, class_name: 'Travis::API::V3::Models::Build'.freeze 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 :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 :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 def default_branch
name == repository.default_branch_name name == repository.default_branch_name

View File

@ -1,7 +1,7 @@
module Travis::API::V3 module Travis::API::V3
class Models::Cron < Model class Models::Cron < Model
belongs_to :repository belongs_to :branch
end end
end end

View File

@ -6,7 +6,6 @@ module Travis::API::V3
has_many :builds, dependent: :delete_all, order: 'builds.id DESC'.freeze has_many :builds, dependent: :delete_all, order: 'builds.id DESC'.freeze
has_many :permissions, dependent: :delete_all has_many :permissions, dependent: :delete_all
has_many :users, through: :permissions has_many :users, through: :permissions
has_many :crons, dependent: :delete_all
belongs_to :owner, polymorphic: true belongs_to :owner, polymorphic: true
belongs_to :last_build, class_name: 'Travis::API::V3::Models::Build'.freeze belongs_to :last_build, class_name: 'Travis::API::V3::Models::Build'.freeze

View File

@ -1,8 +1,8 @@
module Travis::API::V3 module Travis::API::V3
class Queries::Crons < Query class Queries::Crons < Query
def find(repository) def find(branch)
repository.crons branch.crons
end end
end end
end end

View File

@ -3,7 +3,11 @@ require 'travis/api/v3/renderer/model_renderer'
module Travis::API::V3 module Travis::API::V3
class Renderer::Cron < Renderer::ModelRenderer class Renderer::Cron < Renderer::ModelRenderer
representation(:minimal, :id) representation(:minimal, :id)
representation(:standard, :id, :repository) representation(:standard, :id, :branch, :repository)
def repository
model.branch.repository
end
end end
end end

View File

@ -82,6 +82,13 @@ module Travis::API::V3
resource :branch do resource :branch do
route '/branch/{branch.name}' route '/branch/{branch.name}'
get :find get :find
resource :crons do
route '/crons'
get :find
post :create, '/create'
end
end end
resource :branches do resource :branches do
@ -96,9 +103,7 @@ module Travis::API::V3
resource :crons do resource :crons do
route '/crons' route '/crons'
get :find get :for_repository
post :create, '/create'
end end
resource :requests do resource :requests do

View File

@ -5,9 +5,10 @@ module Travis::API::V3
def run! def run!
raise LoginRequired unless access_control.logged_in? or access_control.full_access? raise LoginRequired unless access_control.logged_in? or access_control.full_access?
raise NotFound unless repository = find(:repository) raise NotFound unless repository = find(:repository)
raise NotFound unless branch = find(:branch, repository)
access_control.permissions(repository).create_cron! access_control.permissions(repository).create_cron!
Models::Cron.create(repository: repository) Models::Cron.create(branch: branch)
end end
end end

View File

@ -3,7 +3,7 @@ module Travis::API::V3
paginate paginate
def run! def run!
query.find(find(:repository)) query.find(find(:branch, find(:repository)))
end end
end end
end end

View 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