From 476cf23fc37d6db8d3fb412ce0b646f228d9aac4 Mon Sep 17 00:00:00 2001 From: Felipe Artur Date: Mon, 11 Apr 2016 16:21:32 -0300 Subject: Allow to close invalid merge request --- app/models/merge_request.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'app/models/merge_request.rb') diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index bf185cb5dd8..8292445bcac 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -213,6 +213,8 @@ class MergeRequest < ActiveRecord::Base end def validate_branches + return if allow_broken + if target_project == source_project && target_branch == source_branch errors.add :branch_conflict, "You can not use same project/branch for source and target" end @@ -344,9 +346,12 @@ class MergeRequest < ActiveRecord::Base end def hook_attrs + source_hook_attrs = source_project.hook_attrs if source_project.present? + target_hook_attrs = target_project.hook_attrs if target_project.present? + attrs = { - source: source_project.hook_attrs, - target: target_project.hook_attrs, + source: source_hook_attrs, + target: target_hook_attrs, last_commit: nil, work_in_progress: work_in_progress? } -- cgit v1.2.1 From a64f1c763615c049e551c82a9f3a7c53525a172c Mon Sep 17 00:00:00 2001 From: Felipe Artur Date: Tue, 12 Apr 2016 15:39:33 -0300 Subject: Add changelog entry, improve specs and model code --- app/models/merge_request.rb | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'app/models/merge_request.rb') diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index 8292445bcac..e410febdfff 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -128,7 +128,7 @@ class MergeRequest < ActiveRecord::Base validates :target_project, presence: true validates :target_branch, presence: true validates :merge_user, presence: true, if: :merge_when_build_succeeds? - validate :validate_branches + validate :validate_branches, unless: :allow_broken validate :validate_fork scope :by_branch, ->(branch_name) { where("(source_branch LIKE :branch) OR (target_branch LIKE :branch)", branch: branch_name) } @@ -213,14 +213,12 @@ class MergeRequest < ActiveRecord::Base end def validate_branches - return if allow_broken - if target_project == source_project && target_branch == source_branch errors.add :branch_conflict, "You can not use same project/branch for source and target" end if opened? || reopened? - similar_mrs = self.target_project.merge_requests.where(source_branch: source_branch, target_branch: target_branch, source_project_id: source_project.id).opened + similar_mrs = self.target_project.merge_requests.where(source_branch: source_branch, target_branch: target_branch, source_project_id: source_project.try(:id)).opened similar_mrs = similar_mrs.where('id not in (?)', self.id) if self.id if similar_mrs.any? errors.add :validate_branches, @@ -346,12 +344,9 @@ class MergeRequest < ActiveRecord::Base end def hook_attrs - source_hook_attrs = source_project.hook_attrs if source_project.present? - target_hook_attrs = target_project.hook_attrs if target_project.present? - attrs = { - source: source_hook_attrs, - target: target_hook_attrs, + source: source_project.try(:hook_attrs), + target: target_project.hook_attrs, last_commit: nil, work_in_progress: work_in_progress? } -- cgit v1.2.1