Class: Danger::AssignStrategies::Strategy

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab_reviewbot/strategies/strategy.rb

Direct Known Subclasses

LeastBusyStrategy, RandomStrategy

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client:, project:, mr:, group:) ⇒ Strategy

Returns a new instance of Strategy.



10
11
12
13
14
15
16
# File 'lib/gitlab_reviewbot/strategies/strategy.rb', line 10

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

Instance Attribute Details

#clientObject

Returns the value of attribute client.



7
8
9
# File 'lib/gitlab_reviewbot/strategies/strategy.rb', line 7

def client
  @client
end

#excluded_usersObject

Returns the value of attribute excluded_users.



8
9
10
# File 'lib/gitlab_reviewbot/strategies/strategy.rb', line 8

def excluded_users
  @excluded_users
end

#group_nameObject

Returns the value of attribute group_name.



6
7
8
# File 'lib/gitlab_reviewbot/strategies/strategy.rb', line 6

def group_name
  @group_name
end

#mr_iidObject

Returns the value of attribute mr_iid.



4
5
6
# File 'lib/gitlab_reviewbot/strategies/strategy.rb', line 4

def mr_iid
  @mr_iid
end

#project_idObject

Returns the value of attribute project_id.



5
6
7
# File 'lib/gitlab_reviewbot/strategies/strategy.rb', line 5

def project_id
  @project_id
end

Instance Method Details

#assign!(amount) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/gitlab_reviewbot/strategies/strategy.rb', line 18

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

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

#assignees(amount) ⇒ Object



29
30
31
# File 'lib/gitlab_reviewbot/strategies/strategy.rb', line 29

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

#fetch_assigned_reviewersObject



37
38
39
# File 'lib/gitlab_reviewbot/strategies/strategy.rb', line 37

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

#fetch_authorObject



33
34
35
# File 'lib/gitlab_reviewbot/strategies/strategy.rb', line 33

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

#fetch_users_in_groupObject



41
42
43
44
# File 'lib/gitlab_reviewbot/strategies/strategy.rb', line 41

def fetch_users_in_group
  excluded_users = @excluded_users.map { |u| client.find_user_with_username(u) }
  client.fetch_users_for_group(@group_name).filter { |u| ! excluded_users.include? u }
end