Commit 4f68daee authored by James Fargher's avatar James Fargher

Merge branch 'ld-renamespace-ee-merge_requests-reset_approvals_service' into 'master'

Renamespace `MergeRequests::ResetApprovalsService` out of `EE`

See merge request gitlab-org/gitlab!62270
parents 3fd2da6a 81671b47
# frozen_string_literal: true
module EE
module MergeRequests
class ResetApprovalsService < ::MergeRequests::BaseService
def execute(ref, newrev)
reset_approvals_for_merge_requests(ref, newrev)
end
private
# Note: Closed merge requests also need approvals reset.
def reset_approvals_for_merge_requests(ref, newrev)
branch_name = ::Gitlab::Git.ref_name(ref)
merge_requests = merge_requests_for(branch_name, mr_states: [:opened, :closed])
merge_requests.each do |merge_request|
reset_approvals(merge_request, newrev)
end
end
def reset_approvals?(merge_request, newrev)
super && merge_request.rebase_commit_sha != newrev
end
end
end
end
# frozen_string_literal: true
module MergeRequests
class ResetApprovalsService < ::MergeRequests::BaseService
def execute(ref, newrev)
reset_approvals_for_merge_requests(ref, newrev)
end
private
# Note: Closed merge requests also need approvals reset.
def reset_approvals_for_merge_requests(ref, newrev)
branch_name = ::Gitlab::Git.ref_name(ref)
merge_requests = merge_requests_for(branch_name, mr_states: [:opened, :closed])
merge_requests.each do |merge_request|
reset_approvals(merge_request, newrev)
end
end
def reset_approvals?(merge_request, newrev)
super && merge_request.rebase_commit_sha != newrev
end
end
end
......@@ -18,7 +18,7 @@ class MergeRequestResetApprovalsWorker # rubocop:disable Scalability/IdempotentW
user = User.find_by(id: user_id)
return unless user
EE::MergeRequests::ResetApprovalsService.new(project: project, current_user: user).execute(ref, newrev)
MergeRequests::ResetApprovalsService.new(project: project, current_user: user).execute(ref, newrev)
end
# rubocop: enable CodeReuse/ActiveRecord
end
......@@ -2,7 +2,7 @@
require 'spec_helper'
RSpec.describe EE::MergeRequests::ResetApprovalsService do
RSpec.describe MergeRequests::ResetApprovalsService do
let(:service) { described_class.new(project: project, current_user: current_user) }
let(:current_user) { merge_request.author }
let(:group) { create(:group) }
......
......@@ -19,7 +19,7 @@ RSpec.describe MergeRequestResetApprovalsWorker do
end
it "executes MergeRequests::RefreshService with expected values" do
expect_next_instance_of(EE::MergeRequests::ResetApprovalsService, project: project, current_user: user) do |refresh_service|
expect_next_instance_of(MergeRequests::ResetApprovalsService, project: project, current_user: user) do |refresh_service|
expect(refresh_service).to receive(:execute).with(ref, newrev)
end
......@@ -30,7 +30,7 @@ RSpec.describe MergeRequestResetApprovalsWorker do
let(:project) { double("project", id: "foo") }
it "doesn't execute the service" do
expect(EE::MergeRequests::ResetApprovalsService).not_to receive(:new)
expect(MergeRequests::ResetApprovalsService).not_to receive(:new)
perform
end
......@@ -40,7 +40,7 @@ RSpec.describe MergeRequestResetApprovalsWorker do
let(:user) { double("user", id: "foo") }
it "doesn't execute the service" do
expect(EE::MergeRequests::ResetApprovalsService).not_to receive(:new)
expect(MergeRequests::ResetApprovalsService).not_to receive(:new)
perform
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