add find for cron

This commit is contained in:
Lennard Wolf 2015-11-05 11:43:58 +01:00
parent b923b21252
commit 046a63b60a
5 changed files with 85 additions and 0 deletions

View File

@ -0,0 +1,12 @@
module Travis::API::V3
class Queries::Cron < Query
params :id
sortable_by :id
def find
return Models::Repository.find_by_id(id) if id
raise WrongParams, 'missing job.id'.freeze
end
end
end

View File

@ -0,0 +1,55 @@
require 'travis/api/v3/renderer/model_renderer'
module Travis::API::V3
class Renderer::Cron < Renderer::ModelRenderer
representation(:minimal, :id, :name, :slug)
representation(:standard, :id, :name, :slug, :description, :github_language, :active, :private, :owner, :default_branch)
def active
!!model.active
end
def default_branch
return model.default_branch if include_default_branch?
{
:@type => 'branch'.freeze,
:@href => Renderer.href(:branch, name: model.default_branch_name, repository_id: id, script_name: script_name),
:@representation => 'minimal'.freeze,
:name => model.default_branch_name
}
end
def include_default_branch?
return true if include? 'repository.default_branch'.freeze
return true if include.any? { |i| i.start_with? 'branch'.freeze }
return true if included.any? { |i| i.is_a? Models::Branch and i.respository_id == id and i.name == i.default_branch_name }
end
def owner
return model.owner if include_owner?
owner_href = Renderer.href(owner_type.to_sym, id: model.owner_id, script_name: script_name)
if included_owner? and owner_href
{ :@href => owner_href }
else
result = { :@type => owner_type, :id => model.owner_id, :login => model.owner_name }
result[:@href] = owner_href if owner_href
result
end
end
def include_owner?
return false if included_owner?
return true if include? 'repository.owner'.freeze
return true if include.any? { |i| i.start_with? owner_type or i.start_with? 'owner'.freeze }
end
def included_owner?
included.any? { |i| i.is_a? Model and i.class.polymorphic_name == model.owner_type and i.id == model.owner_id }
end
def owner_type
@owner_type ||= model.owner_type.downcase if model.owner_type
end
end
end

View File

@ -27,6 +27,14 @@ module Travis::API::V3
end
end
resource :cron do
capture id: :digit
route '/cron/{cron.id}'
get :find
end
resource :job do
capture id: :digit
route '/job/{job.id}'

View File

@ -9,6 +9,7 @@ module Travis::API::V3
Broadcasts = Module.new { extend Services }
Build = Module.new { extend Services }
Builds = Module.new { extend Services }
Cron = Module.new { extend Services }
Job = Module.new { extend Services }
Jobs = Module.new { extend Services }
Organization = Module.new { extend Services }

View File

@ -0,0 +1,9 @@
module Travis::API::V3
class Services::Cron::Find < Service
#params :id
def run!
find
end
end
end