add time and disable_by_push options for cron

This commit is contained in:
Steffen Kötte 2015-11-19 13:39:13 +01:00
parent 75449baacd
commit f356beaccf
7 changed files with 109 additions and 41 deletions

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, :branch, :repository)
representation(:standard, :id, :repository, :branch, :hour, :mon, :tue, :wed, :thu, :fri, :sat, :sun, :disable_by_push)
def repository
model.branch.repository

View File

@ -1,15 +1,28 @@
module Travis::API::V3
class Services::Crons::Create < Service
result_type :cron
params :mon, :tue, :wed, :thu, :fri, :sat, :sun, :disable_by_push, :hour
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(branch: branch,
mon: value("mon"),
tue: value("tue"),
wed: value("wed"),
thu: value("thu"),
fri: value("fri"),
sat: value("sat"),
sun: value("sun"),
hour: params["hour"],
disable_by_push: value("disable_by_push"))
end
Models::Cron.create(branch: branch)
end
def value s
params[s] ? params[s] : false
end
end
end

View File

@ -21,18 +21,27 @@ describe Travis::API::V3::Services::Cron::Delete do
"read" => true,
"delete" => true },
"id" => cron.id,
"branch" => {
"@type" => "branch",
"@href" => "/v3/repo/#{repo.id}/branch/#{branch.name}",
"@representation" => "minimal",
"name" => branch.name },
"repository" => {
"@type" => "repository",
"@href" => "/v3/repo/#{repo.id}",
"@representation" => "minimal",
"id" => repo.id,
"name" => "minimal",
"slug" => "svenfuchs/minimal" }
"slug" => "svenfuchs/minimal" },
"branch" => {
"@type" => "branch",
"@href" => "/v3/repo/#{repo.id}/branch/#{branch.name}",
"@representation" => "minimal",
"name" => branch.name },
"hour" => nil,
"mon" => false,
"tue" => false,
"wed" => false,
"thu" => false,
"fri" => false,
"sat" => false,
"sun" => false,
"disable_by_push" => true
}}
end

View File

@ -17,18 +17,27 @@ describe Travis::API::V3::Services::Cron::Find do
"read" => true,
"delete" => false },
"id" => cron.id,
"branch" => {
"@type" => "branch",
"@href" => "/v3/repo/#{repo.id}/branch/#{branch.name}",
"@representation" => "minimal",
"name" => branch.name },
"repository" => {
"@type" => "repository",
"@href" => "/v3/repo/#{repo.id}",
"@representation" => "minimal",
"id" => repo.id,
"name" => "minimal",
"slug" => "svenfuchs/minimal" }
"slug" => "svenfuchs/minimal" },
"branch" => {
"@type" => "branch",
"@href" => "/v3/repo/#{repo.id}/branch/#{branch.name}",
"@representation" => "minimal",
"name" => branch.name },
"hour" => nil,
"mon" => false,
"tue" => false,
"wed" => false,
"thu" => false,
"fri" => false,
"sat" => false,
"sun" => false,
"disable_by_push" => true
}}
end
@ -72,18 +81,27 @@ describe Travis::API::V3::Services::Cron::Find do
"read" => true,
"delete" => false },
"id" => cron.id,
"branch" => {
"@type" => "branch",
"@href" => "/v3/repo/#{repo.id}/branch/#{branch.name}",
"@representation" => "minimal",
"name" => branch.name },
"repository" => {
"@type" => "repository",
"@href" => "/v3/repo/#{repo.id}",
"@representation" => "minimal",
"id" => repo.id,
"name" => "minimal",
"slug" => "svenfuchs/minimal" }
"slug" => "svenfuchs/minimal" },
"branch" => {
"@type" => "branch",
"@href" => "/v3/repo/#{repo.id}/branch/#{branch.name}",
"@representation" => "minimal",
"name" => branch.name },
"hour" => nil,
"mon" => false,
"tue" => false,
"wed" => false,
"thu" => false,
"fri" => false,
"sat" => false,
"sun" => false,
"disable_by_push" => true
}}
end

View File

@ -6,13 +6,14 @@ describe Travis::API::V3::Services::Crons::Create do
let(:last_cron) {Travis::API::V3::Models::Cron.where(branch_id: branch.id).last}
let(:current_cron) {Travis::API::V3::Models::Cron.where(branch_id: branch.id).last}
let(:token) { Travis::Api::App::AccessToken.create(user: repo.owner, app_id: 1) }
let(:headers) {{ 'HTTP_AUTHORIZATION' => "token #{token}" }}
let(:headers) {{ 'HTTP_AUTHORIZATION' => "token #{token}", "Content-Type" => "application/json" }}
let(:options) {{ "tue" => true, "sat" => true, "sun" => false, "disable_by_push" => true, "hour" => 12 }}
let(:parsed_body) { JSON.load(body) }
describe "creating a cron job" do
before { last_cron }
before { Travis::API::V3::Models::Permission.create(repository: repo, user: repo.owner, push: true) }
before { post("/v3/repo/#{repo.id}/branch/#{branch.name}/crons/create", {}, headers) }
before { post("/v3/repo/#{repo.id}/branch/#{branch.name}/crons/create", options, headers) }
example { expect(current_cron == last_cron).to be_falsey }
example { expect(last_response).to be_ok }
example { expect(parsed_body).to be == {
@ -23,18 +24,27 @@ describe Travis::API::V3::Services::Crons::Create do
"read" => true,
"delete" => true },
"id" => current_cron.id,
"branch" => {
"@type" => "branch",
"@href" => "/v3/repo/#{repo.id}/branch/#{branch.name}",
"@representation" => "minimal",
"name" => "#{branch.name}" },
"repository" => {
"@type" => "repository",
"@href" => "/v3/repo/#{repo.id}",
"@representation" => "minimal",
"id" => repo.id,
"name" => "minimal",
"slug" => "svenfuchs/minimal" }
"slug" => "svenfuchs/minimal" },
"branch" => {
"@type" => "branch",
"@href" => "/v3/repo/#{repo.id}/branch/#{branch.name}",
"@representation" => "minimal",
"name" => "#{branch.name}" },
"hour" => 12,
"mon" => false,
"tue" => true,
"wed" => false,
"thu" => false,
"fri" => false,
"sat" => true,
"sun" => false,
"disable_by_push" => true
}}
end

View File

@ -39,18 +39,27 @@ describe Travis::API::V3::Services::Crons::Find do
"read" => true,
"delete" => false },
"id" => cron.id,
"branch" => {
"@type" => "branch",
"@href" => "/v3/repo/#{repo.id}/branch/#{branch.name}",
"@representation" => "minimal",
"name" => "#{branch.name}" },
"repository" => {
"@type" => "repository",
"@href" => "/v3/repo/#{repo.id}",
"@representation" => "minimal",
"id" => repo.id,
"name" => "minimal",
"slug" => "svenfuchs/minimal" }
"slug" => "svenfuchs/minimal" },
"branch" => {
"@type" => "branch",
"@href" => "/v3/repo/#{repo.id}/branch/#{branch.name}",
"@representation" => "minimal",
"name" => "#{branch.name}" },
"hour" => nil,
"mon" => false,
"tue" => false,
"wed" => false,
"thu" => false,
"fri" => false,
"sat" => false,
"sun" => false,
"disable_by_push" => true
}
]
}}

View File

@ -39,18 +39,27 @@ describe Travis::API::V3::Services::Crons::ForRepository do
"read" => true,
"delete" => false },
"id" => cron.id,
"branch" => {
"@type" => "branch",
"@href" => "/v3/repo/#{repo.id}/branch/#{branch.name}",
"@representation" => "minimal",
"name" => "#{branch.name}" },
"repository" => {
"@type" => "repository",
"@href" => "/v3/repo/#{repo.id}",
"@representation" => "minimal",
"id" => repo.id,
"name" => "minimal",
"slug" => "svenfuchs/minimal" }
"slug" => "svenfuchs/minimal" },
"branch" => {
"@type" => "branch",
"@href" => "/v3/repo/#{repo.id}/branch/#{branch.name}",
"@representation" => "minimal",
"name" => "#{branch.name}" },
"hour" => nil,
"mon" => false,
"tue" => false,
"wed" => false,
"thu" => false,
"fri" => false,
"sat" => false,
"sun" => false,
"disable_by_push" => true
}
]
}}