Commit d398e78e authored by Tomasz Maczukin's avatar Tomasz Maczukin

Add endpoint for getting builds for a specific commit

parent f4cff4dc
...@@ -4,7 +4,7 @@ module API ...@@ -4,7 +4,7 @@ module API
before { authenticate! } before { authenticate! }
resource :projects do resource :projects do
# Get a project repository commits # Get a project builds
# #
# Parameters: # Parameters:
# id (required) - The ID of a project # id (required) - The ID of a project
...@@ -14,18 +14,21 @@ module API ...@@ -14,18 +14,21 @@ module API
# Example Request: # Example Request:
# GET /projects/:id/builds # GET /projects/:id/builds
get ':id/builds' do get ':id/builds' do
all_builds = user_project.builds builds = user_project.builds.order('id DESC')
builds = all_builds.order('id DESC') builds = filter_builds(builds, params[:scope])
builds = present paginate(builds), with: Entities::Build
case params[:scope] end
when 'finished'
builds.finished
when 'running'
builds.running
else
builds
end
# GET builds for a specific commit of a project
#
# Parameters:
# id (required) - The ID of a project
# sha (required) - The SHA id of a commit
# Example Request:
# GET /projects/:id/builds/commit/:sha
get ':id/builds/commit/:sha' do
builds = user_project.ci_commits.find_by_sha(params[:sha]).builds.order('id DESC')
builds = filter_builds(builds, params[:scope])
present paginate(builds), with: Entities::Build present paginate(builds), with: Entities::Build
end end
...@@ -63,6 +66,17 @@ module API ...@@ -63,6 +66,17 @@ module API
def get_build(id) def get_build(id)
user_project.builds.where(id: id).first user_project.builds.where(id: id).first
end end
def filter_builds(builds, scope)
case scope
when 'finished'
builds.finished
when 'running'
builds.running
else
builds
end
end
end end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment