diff options
author | Izaak Alpert <ialpert@blackberry.com> | 2013-07-17 11:23:36 -0400 |
---|---|---|
committer | Izaak Alpert <ialpert@blackberry.com> | 2013-07-17 22:48:03 -0400 |
commit | fae3f466151ac8ee9f9e0e496669be8a9e649120 (patch) | |
tree | 62f3e2dc4d286764957661b9852d935b90b52688 /lib/api/merge_requests.rb | |
parent | 539c70c7d64589656cce804282725b97e28e49ff (diff) | |
download | gitlab-ce-fae3f466151ac8ee9f9e0e496669be8a9e649120.tar.gz |
Refactor merge api create
-Made the api method a little more readable
-removed some missed extra newline's
Change-Id: Ic38baafc813aaeda0a8b283f39916182c8ec37d5
Diffstat (limited to 'lib/api/merge_requests.rb')
-rw-r--r-- | lib/api/merge_requests.rb | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/lib/api/merge_requests.rb b/lib/api/merge_requests.rb index f9fb9cb8c13..d690f1d07e7 100644 --- a/lib/api/merge_requests.rb +++ b/lib/api/merge_requests.rb @@ -14,6 +14,14 @@ module API end not_found! 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 # List merge requests @@ -69,13 +77,16 @@ module API merge_request.author = current_user merge_request.source_project = user_project 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 - 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 + if not_fork?(target_project_id, user_project) merge_request.target_project = user_project - elsif !target_project_id.nil? - render_api_error!('(Bad Request) Specified target project that is not the source project, or the source fork of the project.', 400) + 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) + end end + if merge_request.save merge_request.reload_code present merge_request, with: Entities::MergeRequest |