Class: Danger::DangerGitlabReviewbot
- Inherits:
-
Plugin
- Object
- Plugin
- Danger::DangerGitlabReviewbot
- Defined in:
- lib/gitlab_reviewbot/plugin.rb
Overview
This is your plugin class. Any attributes or methods you expose here will be available from within your Dangerfile.
To be published on the Danger plugins site, you will need to have the public interface documented. Danger uses [YARD](yardoc.org/) for generating documentation from your plugin source, and you can verify by running ‘danger plugins lint` or `bundle exec rake spec`.
You should replace these comments with a public description of your library.
Instance Attribute Summary collapse
- #assignees_amount ⇒ Object
-
#gitlab_group ⇒ Object
Define the group to take the reviewers from.
- #strategy ⇒ Object
Instance Method Summary collapse
-
#assign! ⇒ Object
Call this method from the Dangerfile to assign reviewers to your merge requests.
Instance Attribute Details
#assignees_amount ⇒ Object
36 37 38 |
# File 'lib/gitlab_reviewbot/plugin.rb', line 36 def assignees_amount @assignees_amount || 1 end |
#gitlab_group ⇒ Object
Define the group to take the reviewers from. NOTE: This is the group full path as in ‘tech/iOS’ instead of just the group name
28 29 30 |
# File 'lib/gitlab_reviewbot/plugin.rb', line 28 def gitlab_group @gitlab_group end |
#strategy ⇒ Object
48 49 50 |
# File 'lib/gitlab_reviewbot/plugin.rb', line 48 def strategy @strategy || Danger::AssignStrategies::RandomStrategy end |
Instance Method Details
#assign! ⇒ Object
Call this method from the Dangerfile to assign reviewers to your merge requests
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/gitlab_reviewbot/plugin.rb', line 55 def assign! project_id = ENV['CI_PROJECT_ID'] mr_iid = ENV['CI_MERGE_REQUEST_IID'] if mr_iid.nil? raise "Env variable CI_MERGE_REQUEST_IID doesn't point to a valid merge request iid" end if project_id.nil? raise "Env variable CI_PROJECT_ID doesn't point to a valid project id" end current_assignees = (ENV['CI_MERGE_REQUEST_ASSIGNEES'] || '').split(',') #buggy? already_assigned_count = current_assignees.length required_assignees_count = [assignees_amount - already_assigned_count, 0].max puts "Project ID: #{project_id}" if verbose puts "MR IID: #{mr_iid}" if verbose puts "Currently assigned: #{current_assignees}" if verbose # puts "Required: #{required_assignees_count}" if @verbose # if required_assignees_count == 0 # puts "Nothing to do" if @verbose # return # end strategy_class = strategy.new(client: gitlab.api, project: project_id, mr: mr_iid, group: gitlab_group) assignees = strategy_class.assign! assignees_amount puts "Assigning: #{assignees}" if verbose return assignees end |