Add AutoAssignReviewersWorker and reviewer-preserving assign logic (3b/3)

Summary

Introduces the Sidekiq worker that performs automatic reviewer assignment and refactors ReviewerAssignment::AssignService so the worker can invoke it cleanly.

Worker (MergeRequests::AutoAssignReviewersWorker):

  • idempotent!, data_consistency :sticky, urgency :low
  • feature_category :code_review_workflow
  • defer_on_database_health_signal :gitlab_main
  • Resolves the automation_bot for the project's organization and passes it into the service as current_user

AssignService refactor:

  • Resolves the strategy from StrategyFactory rather than taking it as a required arg, so the worker can call .new(merge_request:, current_user:)
  • Takes current_user: in initialize like every other BaseProjectService subclass — no more nil-then-reassign inside execute
  • Preserves existing reviewers when assigning (append rather than overwrite)
  • Duo Code Review compatible: a solo Duo bot reviewer is treated as "no human reviewers" so code owners are still added alongside

No callers invoke the worker yet; the trigger points arrive in Part 3c.

Part 3b of 3 for CODEOWNERS automatic reviewer assignment. This MR can merge independently of 3a (the service still reads reviewer_auto_assignment_enabled?, which exists on master).

Test plan

  • bundle exec rspec ee/spec/workers/merge_requests/auto_assign_reviewers_worker_spec.rb
  • bundle exec rspec ee/spec/services/merge_requests/reviewer_assignment/assign_service_spec.rb
  • Enqueue worker manually for an MR with existing human reviewer: reviewers remain unchanged (skip path)
  • Enqueue worker for an MR with solo Duo bot reviewer: code owners added alongside Duo bot
  • Enqueue worker for an MR with no reviewers: code owners assigned, author is automation_bot
Edited by Marc Shaw

Merge request reports

Loading