Commit 097faeb4 authored by Douwe Maan's avatar Douwe Maan

Get "Merge when build succeeds" to work when commits were pushed to MR target...

Get "Merge when build succeeds" to work when commits were pushed to MR target branch while builds were running
parent 7c3c901a
...@@ -20,6 +20,7 @@ v 8.4.0 (unreleased) ...@@ -20,6 +20,7 @@ v 8.4.0 (unreleased)
- Fix API project lookups when querying with a namespace with dots (Stan Hu) - Fix API project lookups when querying with a namespace with dots (Stan Hu)
v 8.3.3 (unreleased) v 8.3.3 (unreleased)
- Get "Merge when build succeeds" to work when commits were pushed to MR target branch while builds were running
- Fix project transfer e-mail sending incorrect paths in e-mail notification (Stan Hu) - Fix project transfer e-mail sending incorrect paths in e-mail notification (Stan Hu)
- Enable "Add key" button when user fills in a proper key (Stan Hu) - Enable "Add key" button when user fills in a proper key (Stan Hu)
......
...@@ -153,7 +153,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -153,7 +153,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
end end
def merge_check def merge_check
@merge_request.check_if_can_be_merged if @merge_request.unchecked? @merge_request.check_if_can_be_merged
render partial: "projects/merge_requests/widget/show.html.haml", layout: false render partial: "projects/merge_requests/widget/show.html.haml", layout: false
end end
......
...@@ -229,6 +229,8 @@ class MergeRequest < ActiveRecord::Base ...@@ -229,6 +229,8 @@ class MergeRequest < ActiveRecord::Base
end end
def check_if_can_be_merged def check_if_can_be_merged
return unless unchecked?
can_be_merged = can_be_merged =
project.repository.can_be_merged?(source_sha, target_branch) project.repository.can_be_merged?(source_sha, target_branch)
...@@ -252,7 +254,11 @@ class MergeRequest < ActiveRecord::Base ...@@ -252,7 +254,11 @@ class MergeRequest < ActiveRecord::Base
end end
def mergeable? def mergeable?
open? && !work_in_progress? && can_be_merged? return false unless open? && !work_in_progress?
check_if_can_be_merged
can_be_merged?
end end
def gitlab_merge_status def gitlab_merge_status
...@@ -452,6 +458,10 @@ class MergeRequest < ActiveRecord::Base ...@@ -452,6 +458,10 @@ class MergeRequest < ActiveRecord::Base
!source_branch_exists? || !target_branch_exists? !source_branch_exists? || !target_branch_exists?
end end
def broken?
self.commits.blank? || branch_missing? || cannot_be_merged?
end
def can_be_merged_by?(user) def can_be_merged_by?(user)
::Gitlab::GitAccess.new(user, project).can_push_to_branch?(target_branch) ::Gitlab::GitAccess.new(user, project).can_push_to_branch?(target_branch)
end end
...@@ -507,8 +517,4 @@ class MergeRequest < ActiveRecord::Base ...@@ -507,8 +517,4 @@ class MergeRequest < ActiveRecord::Base
def ci_commit def ci_commit
@ci_commit ||= source_project.ci_commit(last_commit.id) if last_commit && source_project @ci_commit ||= source_project.ci_commit(last_commit.id) if last_commit && source_project
end end
def broken?
self.commits.blank? || branch_missing? || cannot_be_merged?
end
end end
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
= render "projects/merge_requests/show/how_to_merge" = render "projects/merge_requests/show/how_to_merge"
= render "projects/merge_requests/widget/show.html.haml" = render "projects/merge_requests/widget/show.html.haml"
- if @merge_request.open? && @merge_request.source_branch_exists? && @merge_request.can_be_merged? && @merge_request.can_be_merged_by?(current_user) - if @merge_request.source_branch_exists? && @merge_request.mergeable? && @merge_request.can_be_merged_by?(current_user)
.light.prepend-top-default .light.prepend-top-default
You can also accept this merge request manually using the You can also accept this merge request manually using the
= succeed '.' do = succeed '.' do
......
...@@ -211,7 +211,7 @@ module API ...@@ -211,7 +211,7 @@ module API
unauthorized! unless merge_request.can_be_merged_by?(current_user) unauthorized! unless merge_request.can_be_merged_by?(current_user)
not_allowed! if !merge_request.open? || merge_request.work_in_progress? not_allowed! if !merge_request.open? || merge_request.work_in_progress?
merge_request.check_if_can_be_merged if merge_request.unchecked? merge_request.check_if_can_be_merged
render_api_error!('Branch cannot be merged', 406) unless merge_request.can_be_merged? render_api_error!('Branch cannot be merged', 406) unless merge_request.can_be_merged?
......
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