summaryrefslogtreecommitdiff
path: root/lib/api
diff options
context:
space:
mode:
authorTomasz Maczukin <tomasz@maczukin.pl>2015-12-24 19:05:57 +0100
committerTomasz Maczukin <tomasz@maczukin.pl>2015-12-24 19:11:30 +0100
commitf4e7a8893d71bcbc92a5ecd16c95593f17d1ddf5 (patch)
tree9a2f516bac071e76ce8fd8a1df5b80f0cefbf334 /lib/api
parent835333c42609e85ca002816976522b4096863bf7 (diff)
downloadgitlab-ce-f4e7a8893d71bcbc92a5ecd16c95593f17d1ddf5.tar.gz
Add builds API (listing, showing trace)
Diffstat (limited to 'lib/api')
-rw-r--r--lib/api/api.rb2
-rw-r--r--lib/api/builds.rb80
-rw-r--r--lib/api/entities.rb13
3 files changed, 95 insertions, 0 deletions
diff --git a/lib/api/api.rb b/lib/api/api.rb
index 7834262d612..266b5f48f8f 100644
--- a/lib/api/api.rb
+++ b/lib/api/api.rb
@@ -54,5 +54,7 @@ module API
mount Keys
mount Tags
mount Triggers
+
+ mount Builds
end
end
diff --git a/lib/api/builds.rb b/lib/api/builds.rb
new file mode 100644
index 00000000000..ce4892b5eeb
--- /dev/null
+++ b/lib/api/builds.rb
@@ -0,0 +1,80 @@
+module API
+ # Projects builds API
+ class Builds < Grape::API
+ before { authenticate! }
+
+ resource :projects do
+ # Get a project repository commits
+ #
+ # Parameters:
+ # id (required) - The ID of a project
+ # scope (optional) - The scope of builds to show (one of: all, finished, running)
+ # page (optional) - The page number for pagination (default: 1)
+ # per_page (ooptional) - The value of items per page to show (default 30)
+ # Example Request:
+ # GET /projects/:id/builds/all
+ get ':id/builds' do
+ all_builds = user_project.builds
+ builds = all_builds.order('created_at 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
+ end
+
+ page = (params[:page] || 1).to_i
+ per_page = (params[:per_page] || 30).to_i
+
+ present builds.page(page).per(per_page), with: Entities::Build
+ end
+
+ # Get a specific build of a project
+ #
+ # Parameters:
+ # id (required) - The ID of a project
+ # build_id (required) - The ID of a build
+ # Example Request:
+ # GET /projects/:id/builds/:build_id
+ get ':id/builds/:build_id' do
+ present get_build(params[:build_id]), with: Entities::Build
+ end
+
+ # Get a trace of a specific build of a project
+ #
+ # Parameters:
+ # id (required) - The ID of a project
+ # build_id (required) - The ID of a build
+ # 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
+
+ present trace
+ end
+ end
+
+ helpers do
+ def get_build(id)
+ user_project.builds.where(id: id).first
+ end
+ end
+ end
+end
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index f8511ac5f5c..0bf50490eac 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -366,5 +366,18 @@ module API
class TriggerRequest < Grape::Entity
expose :id, :variables
end
+
+ class Build < Grape::Entity
+ expose :id
+ expose :status
+ expose :stage
+ expose :name
+ expose :ref
+ expose :commit
+ expose :runner
+ expose :created_at
+ expose :started_at
+ expose :finished_at
+ end
end
end