diff options
author | Tomasz Maczukin <tomasz@maczukin.pl> | 2015-12-28 15:49:13 +0100 |
---|---|---|
committer | Tomasz Maczukin <tomasz@maczukin.pl> | 2015-12-28 15:49:13 +0100 |
commit | d398e78ea09c1f88800cd4c99f92dd8e5d1d0d39 (patch) | |
tree | eb53c58cea8de4ab310989b75762bd6784984867 | |
parent | f4cff4dcd0b11d4597efe454731838fbf5803516 (diff) | |
download | gitlab-ce-d398e78ea09c1f88800cd4c99f92dd8e5d1d0d39.tar.gz |
Add endpoint for getting builds for a specific commit
-rw-r--r-- | lib/api/builds.rb | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/lib/api/builds.rb b/lib/api/builds.rb index f219b0f5241..7488863cdcf 100644 --- a/lib/api/builds.rb +++ b/lib/api/builds.rb @@ -4,7 +4,7 @@ module API before { authenticate! } resource :projects do - # Get a project repository commits + # Get a project builds # # Parameters: # id (required) - The ID of a project @@ -14,18 +14,21 @@ module API # Example Request: # GET /projects/:id/builds get ':id/builds' do - all_builds = user_project.builds - builds = all_builds.order('id DESC') - builds = - case params[:scope] - when 'finished' - builds.finished - when 'running' - builds.running - else - builds - end + builds = user_project.builds.order('id DESC') + builds = filter_builds(builds, params[:scope]) + present paginate(builds), with: Entities::Build + 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 end @@ -63,6 +66,17 @@ module API def get_build(id) user_project.builds.where(id: id).first end + + def filter_builds(builds, scope) + case scope + when 'finished' + builds.finished + when 'running' + builds.running + else + builds + end + end end end end |