Add some fixes to builds API

This commit is contained in:
Tomasz Maczukin 2015-12-28 13:09:51 +01:00
parent b5fef34f1e
commit f39959d00a
2 changed files with 27 additions and 20 deletions

View file

@ -15,23 +15,15 @@ module API
# GET /projects/:id/builds
get ':id/builds' do
all_builds = user_project.builds
builds = all_builds.order('created_at DESC')
builds = all_builds.order('id DESC')
builds =
case params[:scope]
when 'all'
builds
when 'finished'
builds.finished
when 'running'
builds.running
when 'pending'
builds.pending
when 'success'
builds.success
when 'failed'
builds.failed
else
builds.running_or_pending.reverse_order
builds
end
page = (params[:page] || 1).to_i
@ -59,15 +51,14 @@ module API
# Example Request:
# GET /projects/:id/build/:build_id/trace
get ':id/builds/:build_id/trace' do
trace = get_build(params[:build_id]).trace
trace =
unless trace.nil?
trace.split("\n")
else
[]
end
build = get_build(params[:build_id])
present trace
header 'Content-Disposition', "infile; filename=\"#{build.id}.log\""
content_type 'text/plain'
env['api.format'] = :binary
trace = build.trace
body trace
end
end

View file

@ -367,14 +367,30 @@ module API
expose :id, :variables
end
class CiCommit < Grape::Entity
expose :id
expose :ref
expose :sha
expose :committed_at
end
class CiRunner < Grape::Entity
expose :id
expose :token
expose :description
expose :active
expose :is_shared
expose :name
end
class Build < Grape::Entity
expose :id
expose :status
expose :stage
expose :name
expose :ref
expose :commit
expose :runner
expose :commit, with: CiCommit
expose :runner, with: CiRunner
expose :created_at
expose :started_at
expose :finished_at