Class: Gitlab::Triage::CommandBuilders::LabelCommandBuilder

Inherits:
BaseCommandBuilder show all
Defined in:
lib/gitlab/triage/command_builders/label_command_builder.rb

Direct Known Subclasses

RemoveLabelCommandBuilder

Instance Attribute Summary

Attributes inherited from BaseCommandBuilder

#items, #network, #resource

Instance Method Summary collapse

Methods inherited from BaseCommandBuilder

#content_string, #initialize, #separator

Constructor Details

This class inherits a constructor from Gitlab::Triage::CommandBuilders::BaseCommandBuilder

Instance Method Details

#build_commandObject



9
10
11
12
13
# File 'lib/gitlab/triage/command_builders/label_command_builder.rb', line 9

def build_command
  ensure_labels_exist!

  super
end

#ensure_labels_exist!Object (private)



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/gitlab/triage/command_builders/label_command_builder.rb', line 17

def ensure_labels_exist!
  items.each do |label|
    source_id_key = resource.key?(:group_id) ? :group_id : :project_id
    label_opts = {
      source_id_key => resource[source_id_key],
      name: label
    }

    unless Resource::Label.new(label_opts, network: network).exist?
      raise Resource::Label::LabelDoesntExistError,
        "Label `#{label}` doesn't exist!"
    end
  end
end

#format_item(item) ⇒ Object (private)



36
37
38
# File 'lib/gitlab/triage/command_builders/label_command_builder.rb', line 36

def format_item(item)
  "~\"#{item}\""
end

#slash_command_stringObject (private)



32
33
34
# File 'lib/gitlab/triage/command_builders/label_command_builder.rb', line 32

def slash_command_string
  "/label"
end