# frozen_string_literal: true require "gitlab_reviewbot/gitlab" module Danger module AssignStrategies class LeastBusyStrategy < Strategy def assignees(amount) # This doesn't fetch the review count for the users so we need to fetch it separately later users_in_group = fetch_users_in_group invalid_assignees = [fetch_author] + fetch_assigned_reviewers group_users_with_reviews_pending = client.users_with_pending_mr_review(project_id).filter { |u| users_in_group.include? u } group_users_without_reviews_pending = users_in_group.filter { |u| !group_users_with_reviews_pending.include? u } (group_users_with_reviews_pending + group_users_without_reviews_pending).filter { |u| !invalid_assignees.include? u } .sort_by(&:review_count) .first(amount) end end end end