summaryrefslogtreecommitdiff
path: root/lib/api/commits.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/api/commits.rb')
-rw-r--r--lib/api/commits.rb38
1 files changed, 29 insertions, 9 deletions
diff --git a/lib/api/commits.rb b/lib/api/commits.rb
index 1a0fe393753..3c7ed2a25a0 100644
--- a/lib/api/commits.rb
+++ b/lib/api/commits.rb
@@ -13,7 +13,7 @@ module API
helpers do
def user_access
- @user_access ||= Gitlab::UserAccess.new(current_user, project: user_project)
+ @user_access ||= Gitlab::UserAccess.new(current_user, container: user_project)
end
def authorize_push_to_branch!(branch)
@@ -203,6 +203,7 @@ module API
params do
requires :sha, type: String, desc: 'A commit sha, or the name of a branch or tag to be cherry picked'
requires :branch, type: String, desc: 'The name of the branch', allow_blank: false
+ optional :dry_run, type: Boolean, default: false, desc: "Does not commit any changes"
end
post ':id/repository/commits/:sha/cherry_pick', requirements: API::COMMIT_ENDPOINT_REQUIREMENTS do
authorize_push_to_branch!(params[:branch])
@@ -215,7 +216,8 @@ module API
commit_params = {
commit: commit,
start_branch: params[:branch],
- branch_name: params[:branch]
+ branch_name: params[:branch],
+ dry_run: params[:dry_run]
}
result = ::Commits::CherryPickService
@@ -223,10 +225,18 @@ module API
.execute
if result[:status] == :success
- present user_project.repository.commit(result[:result]),
- with: Entities::Commit
+ if params[:dry_run]
+ present dry_run: :success
+ status :ok
+ else
+ present user_project.repository.commit(result[:result]),
+ with: Entities::Commit
+ end
else
- error!(result.slice(:message, :error_code), 400, header)
+ response = result.slice(:message, :error_code)
+ response[:dry_run] = :error if params[:dry_run]
+
+ error!(response, 400, header)
end
end
@@ -237,6 +247,7 @@ module API
params do
requires :sha, type: String, desc: 'Commit SHA to revert'
requires :branch, type: String, desc: 'Target branch name', allow_blank: false
+ optional :dry_run, type: Boolean, default: false, desc: "Does not commit any changes"
end
post ':id/repository/commits/:sha/revert', requirements: API::COMMIT_ENDPOINT_REQUIREMENTS do
authorize_push_to_branch!(params[:branch])
@@ -249,7 +260,8 @@ module API
commit_params = {
commit: commit,
start_branch: params[:branch],
- branch_name: params[:branch]
+ branch_name: params[:branch],
+ dry_run: params[:dry_run]
}
result = ::Commits::RevertService
@@ -257,10 +269,18 @@ module API
.execute
if result[:status] == :success
- present user_project.repository.commit(result[:result]),
- with: Entities::Commit
+ if params[:dry_run]
+ present dry_run: :success
+ status :ok
+ else
+ present user_project.repository.commit(result[:result]),
+ with: Entities::Commit
+ end
else
- error!(result.slice(:message, :error_code), 400, header)
+ response = result.slice(:message, :error_code)
+ response[:dry_run] = :error if params[:dry_run]
+
+ error!(response, 400, header)
end
end