further changes for new structure with only one cron per branch
This commit is contained in:
parent
b45b3fadf7
commit
0920041375
|
@ -4,7 +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_one :crons, dependent: :delete
|
has_one :cron, dependent: :delete
|
||||||
|
|
||||||
def default_branch
|
def default_branch
|
||||||
name == repository.default_branch_name
|
name == repository.default_branch_name
|
||||||
|
|
|
@ -2,7 +2,7 @@ module Travis::API::V3
|
||||||
class Queries::Crons < Query
|
class Queries::Crons < Query
|
||||||
|
|
||||||
def find(branch)
|
def find(branch)
|
||||||
branch.crons
|
branch.cron
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,7 +3,7 @@ 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, :branch, :hour, :mon, :tue, :wed, :thu, :fri, :sat, :sun, :disable_by_push)
|
representation(:standard, :id, :repository, :branch, :interval, :disable_by_build)
|
||||||
|
|
||||||
def repository
|
def repository
|
||||||
model.branch.repository
|
model.branch.repository
|
||||||
|
|
|
@ -85,9 +85,9 @@ module Travis::API::V3
|
||||||
route '/branch/{branch.name}'
|
route '/branch/{branch.name}'
|
||||||
get :find
|
get :find
|
||||||
|
|
||||||
resource :crons do
|
resource :cron do
|
||||||
route '/cron'
|
route '/cron'
|
||||||
get :find
|
get :for_branch
|
||||||
|
|
||||||
post :create, '/create'
|
post :create, '/create'
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
module Travis::API::V3
|
module Travis::API::V3
|
||||||
class Services::Crons::Create < Service
|
class Services::Cron::Create < Service
|
||||||
result_type :cron
|
result_type :cron
|
||||||
params :type, :disable_by_build
|
params :interval, :disable_by_build
|
||||||
|
|
||||||
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?
|
||||||
|
@ -9,12 +9,8 @@ module Travis::API::V3
|
||||||
raise NotFound unless branch = find(:branch, repository)
|
raise NotFound unless branch = find(:branch, repository)
|
||||||
access_control.permissions(repository).create_cron!
|
access_control.permissions(repository).create_cron!
|
||||||
Models::Cron.create(branch: branch,
|
Models::Cron.create(branch: branch,
|
||||||
type: params["type"],
|
interval: params["interval"],
|
||||||
disable_by_build: value("disable_by_build"))
|
disable_by_build: params["disable_by_build"] ? params["disable_by_build"] : false)
|
||||||
end
|
|
||||||
|
|
||||||
def value s
|
|
||||||
params[s] ? params[s] : false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
8
lib/travis/api/v3/services/cron/for_branch.rb
Normal file
8
lib/travis/api/v3/services/cron/for_branch.rb
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
module Travis::API::V3
|
||||||
|
class Services::Cron::ForBranch < Service
|
||||||
|
|
||||||
|
def run!
|
||||||
|
Models::Cron.where(:branch_id => find(:branch, find(:repository))).first
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user