diff options
author | Robert Schilling <rschilling@student.tugraz.at> | 2016-12-12 13:04:13 +0100 |
---|---|---|
committer | Robert Schilling <rschilling@student.tugraz.at> | 2016-12-13 16:12:40 +0100 |
commit | 1a81fcfbd8261862c9614f0ea317af02ae20b24a (patch) | |
tree | 0305f26c3d02ab68c2ebc3ef4e9b2711213586b0 /lib/api/commits.rb | |
parent | db9e1635d0d17596193ecbee8e0acc1916918d1d (diff) | |
download | gitlab-ce-1a81fcfbd8261862c9614f0ea317af02ae20b24a.tar.gz |
API: Ability to cherry-pick a commit
Diffstat (limited to 'lib/api/commits.rb')
-rw-r--r-- | lib/api/commits.rb | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/lib/api/commits.rb b/lib/api/commits.rb index 2670a2d413a..cf2489dbb67 100644 --- a/lib/api/commits.rb +++ b/lib/api/commits.rb @@ -1,7 +1,6 @@ require 'mime/types' module API - # Projects commits API class Commits < Grape::API include PaginationParams @@ -121,6 +120,41 @@ module API present paginate(notes), with: Entities::CommitNote end + desc 'Cherry pick commit into a branch' do + detail 'This feature was introduced in GitLab 8.15' + success Entities::RepoCommit + end + params do + requires :sha, type: String, desc: 'A commit sha to be cherry picked' + requires :branch, type: String, desc: 'The name of the branch' + end + post ':id/repository/commits/:sha/cherry_pick' do + authorize! :push_code, user_project + + commit = user_project.commit(params[:sha]) + not_found!('Commit') unless commit + + branch = user_project.repository.find_branch(params[:branch]) + not_found!('Branch') unless branch + + commit_params = { + commit: commit, + create_merge_request: false, + source_project: user_project, + source_branch: commit.cherry_pick_branch_name, + target_branch: params[:branch] + } + + result = ::Commits::CherryPickService.new(user_project, current_user, commit_params).execute + + if result[:status] == :success + branch = user_project.repository.find_branch(params[:branch]) + present user_project.repository.commit(branch.dereferenced_target), with: Entities::RepoCommit + else + render_api_error!(result[:message], 400) + end + end + desc 'Post comment to commit' do success Entities::CommitNote end |