diff options
author | Nick Thomas <nick@gitlab.com> | 2018-11-09 16:33:50 +0000 |
---|---|---|
committer | Nick Thomas <nick@gitlab.com> | 2018-11-09 16:33:50 +0000 |
commit | 8d74ef331c4f2d391279f178ebb02c28a56205ac (patch) | |
tree | 4232aed4c18ce449e9db99e93374552a49646051 /lib | |
parent | 57cee17673a711ff023fd1a9766defefd0103a9f (diff) | |
parent | 2331d3af63122e7b2419bce2e5e6e5bdc63cd2d8 (diff) | |
download | gitlab-ce-8d74ef331c4f2d391279f178ebb02c28a56205ac.tar.gz |
Merge branch 'rs-revert-api' into 'master'
Add revert to commits API
Closes gitlab-org/release/framework#48
See merge request gitlab-org/gitlab-ce!22919
Diffstat (limited to 'lib')
-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 |