diff options
author | Robert Speicher <rspeicher@gmail.com> | 2018-11-06 23:27:14 -0500 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2018-11-09 15:26:38 +0000 |
commit | 2331d3af63122e7b2419bce2e5e6e5bdc63cd2d8 (patch) | |
tree | 8961f5dec1589228b6b3652a901174f4d8126af5 /lib/api | |
parent | cc12b57c3ff6a46583abecc76e366e59426cf14c (diff) | |
download | gitlab-ce-2331d3af63122e7b2419bce2e5e6e5bdc63cd2d8.tar.gz |
Add revert to commits API
Diffstat (limited to 'lib/api')
-rw-r--r-- | lib/api/commits.rb | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/api/commits.rb b/lib/api/commits.rb index e59abd3e3d0..1b228069005 100644 --- a/lib/api/commits.rb +++ b/lib/api/commits.rb @@ -204,6 +204,40 @@ module API end end + desc 'Revert a commit in a branch' do + detail 'This feature was introduced in GitLab 11.6' + success Entities::Commit + end + params do + requires :sha, type: String, desc: 'Commit SHA to revert' + requires :branch, type: String, desc: 'Target branch name', allow_blank: false + end + post ':id/repository/commits/:sha/revert', requirements: API::COMMIT_ENDPOINT_REQUIREMENTS do + authorize_push_to_branch!(params[:branch]) + + commit = user_project.commit(params[:sha]) + not_found!('Commit') unless commit + + find_branch!(params[:branch]) + + commit_params = { + commit: commit, + start_branch: params[:branch], + branch_name: params[:branch] + } + + result = ::Commits::RevertService + .new(user_project, current_user, commit_params) + .execute + + if result[:status] == :success + present user_project.repository.commit(result[:result]), + with: Entities::Commit + else + render_api_error!(result[:message], 400) + end + end + desc 'Get all references a commit is pushed to' do detail 'This feature was introduced in GitLab 10.6' success Entities::BasicRef |