From 31409030d67858d21281fc72b654246b32f7c6eb Mon Sep 17 00:00:00 2001 From: Felipe Artur Date: Wed, 15 Feb 2017 13:01:07 -0200 Subject: Create compare object with default branch when target branch is missing --- app/services/merge_requests/build_service.rb | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'app/services/merge_requests/build_service.rb') diff --git a/app/services/merge_requests/build_service.rb b/app/services/merge_requests/build_service.rb index f4d52e3ebbd..9d4739e37bb 100644 --- a/app/services/merge_requests/build_service.rb +++ b/app/services/merge_requests/build_service.rb @@ -2,18 +2,14 @@ module MergeRequests class BuildService < MergeRequests::BaseService def execute self.merge_request = MergeRequest.new(params) - merge_request.can_be_created = true merge_request.compare_commits = [] merge_request.source_project = find_source_project merge_request.target_project = find_target_project merge_request.target_branch = find_target_branch + merge_request.can_be_created = branches_valid? && source_branch_specified? && target_branch_specified? - if branches_specified? && branches_valid? - compare_branches - assign_title_and_description - else - merge_request.can_be_created = false - end + compare_branches if branches_present? + assign_title_and_description if merge_request.can_be_created merge_request end @@ -37,11 +33,17 @@ module MergeRequests target_branch || target_project.default_branch end - def branches_specified? - params[:source_branch] && params[:target_branch] + def source_branch_specified? + params[:source_branch].present? + end + + def target_branch_specified? + params[:target_branch].present? end def branches_valid? + return false unless source_branch_specified? || target_branch_specified? + validate_branches errors.blank? end @@ -55,8 +57,10 @@ module MergeRequests target_branch ) - merge_request.compare_commits = compare.commits - merge_request.compare = compare + if compare + merge_request.compare_commits = compare.commits + merge_request.compare = compare + end end def validate_branches -- cgit v1.2.1