Sha256: 82b7c8696d0e9319bad64659ed70e26aec5add61136aed01babe6426941a0c12

Contents?: true

Size: 1.44 KB

Versions: 7

Compression:

Stored size: 1.44 KB

Contents

# frozen_string_literal: true

module Danger
  module AssignStrategies
    class Strategy
      attr_accessor :mr_iid
      attr_accessor :project_id
      attr_accessor :group_name
      attr_accessor :client
      attr_accessor :excluded_users

      def initialize(client:, project:, mr_iid:)
        @client = client
        @project_id = project
        @mr_iid = mr_iid
        @excluded_users = []
      end

      def assign!(amount)
        currently_assigned = fetch_assigned_reviewers
        return [] if (amount - currently_assigned.length) <= 0

        to_be_assigned = assignees(amount - currently_assigned.length)
        all_assignees = currently_assigned + to_be_assigned

        client.assign_mr_to_users(project_id, mr_iid, all_assignees)
        all_assignees.map(&:username)
      end

      def assignees(amount)
        raise "To be implemented in the subclasses"
      end

      def fetch_author
        client.fetch_author_for_mr(@project_id, @mr_iid)
      end

      def fetch_assigned_reviewers
        client.fetch_mr_reviewers(@project_id, @mr_iid)
      end

      def fetch_users_in_group
        excluded = @excluded_users.map do |u|
          server_user = client.find_user_with_username(u).first
          raise "ERROR: Invalid username #{u} among excluded_users" if server_user.nil?
          server_user
        end
        client.fetch_users_for_group(@group_name).filter { |u| !excluded.include? u }
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
danger-gitlab_reviewbot-1.2.3 lib/gitlab_reviewbot/strategies/strategy.rb
danger-gitlab_reviewbot-1.2.1 lib/gitlab_reviewbot/strategies/strategy.rb
danger-gitlab_reviewbot-1.2.0 lib/gitlab_reviewbot/strategies/strategy.rb
danger-gitlab_reviewbot-1.1.10 lib/gitlab_reviewbot/strategies/strategy.rb
danger-gitlab_reviewbot-1.1.9 lib/gitlab_reviewbot/strategies/strategy.rb
danger-gitlab_reviewbot-1.1.8 lib/gitlab_reviewbot/strategies/strategy.rb
danger-gitlab_reviewbot-1.1.6 lib/gitlab_reviewbot/strategies/strategy.rb