further changes for new structure with only one cron per branch

This commit is contained in:
Steffen Kötte 2016-01-11 14:14:00 +01:00
parent b45b3fadf7
commit 0920041375
6 changed files with 17 additions and 13 deletions

View File

@ -4,7 +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_one :crons, dependent: :delete
has_one :cron, dependent: :delete
def default_branch
name == repository.default_branch_name

View File

@ -2,7 +2,7 @@ module Travis::API::V3
class Queries::Crons < Query
def find(branch)
branch.crons
branch.cron
end
end
end

View File

@ -3,7 +3,7 @@ require 'travis/api/v3/renderer/model_renderer'
module Travis::API::V3
class Renderer::Cron < Renderer::ModelRenderer
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
model.branch.repository

View File

@ -85,9 +85,9 @@ module Travis::API::V3
route '/branch/{branch.name}'
get :find
resource :crons do
resource :cron do
route '/cron'
get :find
get :for_branch
post :create, '/create'
end

View File

@ -1,7 +1,7 @@
module Travis::API::V3
class Services::Crons::Create < Service
class Services::Cron::Create < Service
result_type :cron
params :type, :disable_by_build
params :interval, :disable_by_build
def run!
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)
access_control.permissions(repository).create_cron!
Models::Cron.create(branch: branch,
type: params["type"],
disable_by_build: value("disable_by_build"))
end
def value s
params[s] ? params[s] : false
interval: params["interval"],
disable_by_build: params["disable_by_build"] ? params["disable_by_build"] : false)
end
end

View 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