From 35c37fb29343974bf2edc3959d6a21db9c384307 Mon Sep 17 00:00:00 2001 From: Kerri Miller Date: Fri, 31 May 2019 14:21:15 +0000 Subject: Add optional param :start_project to allow variable commit targets This extends POST#:id/repository/commits to allow the optional parameter `:start_project`, which will allow targeting other projects besides the one derived from `:id`. Resolves https://gitlab.com/gitlab-org/gitlab-ce/issues/50850 --- lib/api/commits.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'lib/api/commits.rb') diff --git a/lib/api/commits.rb b/lib/api/commits.rb index 65eb9bfb87e..80913f4ca07 100644 --- a/lib/api/commits.rb +++ b/lib/api/commits.rb @@ -96,17 +96,27 @@ module API end end optional :start_branch, type: String, desc: 'Name of the branch to start the new commit from' + optional :start_project, types: [Integer, String], desc: 'The ID or path of the project to start the commit from' optional :author_email, type: String, desc: 'Author email for commit' optional :author_name, type: String, desc: 'Author name for commit' optional :stats, type: Boolean, default: true, desc: 'Include commit stats' optional :force, type: Boolean, default: false, desc: 'When `true` overwrites the target branch with a new commit based on the `start_branch`' end post ':id/repository/commits' do + if params[:start_project] + start_project = find_project!(params[:start_project]) + + unless user_project.forked_from?(start_project) + forbidden!("Project is not included in the fork network for #{start_project.full_name}") + end + end + authorize_push_to_branch!(params[:branch]) attrs = declared_params attrs[:branch_name] = attrs.delete(:branch) attrs[:start_branch] ||= attrs[:branch_name] + attrs[:start_project] = start_project if start_project result = ::Files::MultiService.new(user_project, current_user, attrs).execute -- cgit v1.2.1