Commit fae3f466 authored by Izaak Alpert's avatar Izaak Alpert

Refactor merge api create

-Made the api method a little more readable
-removed some missed extra newline's

Change-Id: Ic38baafc813aaeda0a8b283f39916182c8ec37d5
parent 539c70c7
...@@ -14,6 +14,14 @@ module API ...@@ -14,6 +14,14 @@ module API
end end
not_found! not_found!
end end
def not_fork?(target_project_id, user_project)
target_project_id.nil? || target_project_id == user_project.id.to_s
end
def target_matches_fork(target_project_id,user_project)
user_project.forked? && user_project.forked_from_project.id.to_s == target_project_id
end
end end
# List merge requests # List merge requests
...@@ -69,13 +77,16 @@ module API ...@@ -69,13 +77,16 @@ module API
merge_request.author = current_user merge_request.author = current_user
merge_request.source_project = user_project merge_request.source_project = user_project
target_project_id = attrs[:target_project_id] target_project_id = attrs[:target_project_id]
if !target_project_id.nil? && user_project.forked? && user_project.forked_from_project.id.to_s == target_project_id if not_fork?(target_project_id, user_project)
merge_request.target_project = Project.find_by_id(attrs[:target_project_id])
elsif target_project_id.nil? || target_project_id == user_project.id.to_s
merge_request.target_project = user_project merge_request.target_project = user_project
elsif !target_project_id.nil? else
if target_matches_fork(target_project_id,user_project)
merge_request.target_project = Project.find_by_id(attrs[:target_project_id])
else
render_api_error!('(Bad Request) Specified target project that is not the source project, or the source fork of the project.', 400) render_api_error!('(Bad Request) Specified target project that is not the source project, or the source fork of the project.', 400)
end end
end
if merge_request.save if merge_request.save
merge_request.reload_code merge_request.reload_code
present merge_request, with: Entities::MergeRequest present merge_request, with: Entities::MergeRequest
......
...@@ -130,7 +130,6 @@ module Gitlab ...@@ -130,7 +130,6 @@ module Gitlab
repo.git.fetch(default_options, :origin) repo.git.fetch(default_options, :origin)
end end
def default_options(options = {}) def default_options(options = {})
{raise: true, timeout: true}.merge(options) {raise: true, timeout: true}.merge(options)
end end
......
...@@ -83,7 +83,6 @@ describe MergeRequest do ...@@ -83,7 +83,6 @@ describe MergeRequest do
end end
end end
describe '#allow_source_branch_removal?' do describe '#allow_source_branch_removal?' do
it 'should not allow removal when mr is a fork' do it 'should not allow removal when mr is a fork' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment