Commit c89c4d82 authored by Mark Chao's avatar Mark Chao

Sync approvals_required count setting to rules

When project/MR's approvals_before_merge is changed,
update its rule's approvals_required.
parent 6da54c0d
...@@ -25,6 +25,8 @@ module EE ...@@ -25,6 +25,8 @@ module EE
cleanup_approvers(merge_request, reload: true) cleanup_approvers(merge_request, reload: true)
end end
sync_approval_rules(merge_request)
merge_request merge_request
end end
...@@ -42,6 +44,14 @@ module EE ...@@ -42,6 +44,14 @@ module EE
merge_request.approvals.delete_all if target_project.reset_approvals_on_push merge_request.approvals.delete_all if target_project.reset_approvals_on_push
end end
# TODO remove after #1979 is closed
def sync_approval_rules(merge_request)
return if merge_request.merged?
return unless merge_request.previous_changes.include?(:approvals_before_merge)
merge_request.approval_rules.regular.update_all(approvals_required: merge_request.approvals_before_merge)
end
end end
end end
end end
...@@ -37,6 +37,8 @@ module EE ...@@ -37,6 +37,8 @@ module EE
sync_wiki_on_enable if !wiki_was_enabled && project.wiki_enabled? sync_wiki_on_enable if !wiki_was_enabled && project.wiki_enabled?
project.import_state.force_import_job! if params[:mirror].present? && project.mirror? project.import_state.force_import_job! if params[:mirror].present? && project.mirror?
sync_approval_rules
end end
result result
...@@ -67,6 +69,13 @@ module EE ...@@ -67,6 +69,13 @@ module EE
def sync_wiki_on_enable def sync_wiki_on_enable
::Geo::RepositoryUpdatedService.new(project.wiki.repository).execute ::Geo::RepositoryUpdatedService.new(project.wiki.repository).execute
end end
# TODO remove after #1979 is closed
def sync_approval_rules
return unless project.previous_changes.include?(:approvals_before_merge)
project.approval_rules.update_all(approvals_required: project.approvals_before_merge)
end
end end
end end
end end
...@@ -56,5 +56,17 @@ describe MergeRequests::UpdateService, :mailer do ...@@ -56,5 +56,17 @@ describe MergeRequests::UpdateService, :mailer do
end.not_to change { ActionMailer::Base.deliveries.count } end.not_to change { ActionMailer::Base.deliveries.count }
end end
end end
context 'when approvals_before_merge changes' do
it "updates approval_rules' approvals_required" do
rule = create(:approval_merge_request_rule, merge_request: merge_request)
code_owner_rule = create(:approval_merge_request_rule, merge_request: merge_request, code_owner: true)
update_merge_request(approvals_before_merge: 42)
expect(rule.reload.approvals_required).to eq(42)
expect(code_owner_rule.reload.approvals_required).to eq(0)
end
end
end end
end end
...@@ -215,6 +215,16 @@ describe Projects::UpdateService, '#execute' do ...@@ -215,6 +215,16 @@ describe Projects::UpdateService, '#execute' do
end end
end end
context 'with approval_rules' do
it "updates approval_rules' approvals_required" do
rule = create(:approval_project_rule, project: project)
update_project(project, user, approvals_before_merge: 42)
expect(rule.reload.approvals_required).to eq(42)
end
end
def update_project(project, user, opts) def update_project(project, user, opts)
Projects::UpdateService.new(project, user, opts).execute Projects::UpdateService.new(project, user, opts).execute
end end
......
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