Class: Danger::DangerGitlabReviewbot

Inherits:
Plugin
  • Object
show all
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.

Examples:

Ensure people are well warned about merging on Mondays


my_plugin.warn_on_mondays

See Also:

  • Gallonetto/danger-gitlab_reviewbot

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#assignees_amountObject



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

def assignees_amount
  @assignees_amount || 1
end

#gitlab_groupObject

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

Returns:

  • String



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

def gitlab_group
  @gitlab_group
end

#strategyObject



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

Returns:

  • The usernames list of assigned reviewes [Array<String>]



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