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:) ⇒ Strategy

Returns a new instance of Strategy.



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

def initialize(client:, project:, mr:)
  @client = client
  @project_id = project
  @mr_iid = mr
  @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



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

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



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

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

#fetch_assigned_reviewersObject



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

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

#fetch_authorObject



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

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

#fetch_users_in_groupObject



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

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