Class: Danger::AssignStrategies::Strategy
- Inherits:
-
Object
- Object
- Danger::AssignStrategies::Strategy
- Defined in:
- lib/gitlab_reviewbot/strategies/strategy.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#excluded_users ⇒ Object
Returns the value of attribute excluded_users.
-
#group_name ⇒ Object
Returns the value of attribute group_name.
-
#mr_iid ⇒ Object
Returns the value of attribute mr_iid.
-
#project_id ⇒ Object
Returns the value of attribute project_id.
Instance Method Summary collapse
- #assign!(amount) ⇒ Object
- #assignees(amount) ⇒ Object
- #fetch_assigned_reviewers ⇒ Object
- #fetch_author ⇒ Object
- #fetch_users_in_group ⇒ Object
-
#initialize(client:, project:, mr:) ⇒ Strategy
constructor
A new instance of Strategy.
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
#client ⇒ Object
Returns the value of attribute client.
7 8 9 |
# File 'lib/gitlab_reviewbot/strategies/strategy.rb', line 7 def client @client end |
#excluded_users ⇒ Object
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_name ⇒ Object
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_iid ⇒ Object
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_id ⇒ Object
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_reviewers ⇒ Object
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_author ⇒ Object
32 33 34 |
# File 'lib/gitlab_reviewbot/strategies/strategy.rb', line 32 def client.(@project_id, @mr_iid) end |
#fetch_users_in_group ⇒ Object
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 |