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



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

def build_command
  ensure_labels_exist!

  super
end

#ensure_labels_exist!Object (private)



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

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)



34
35
36
# File 'lib/gitlab/triage/command_builders/label_command_builder.rb', line 34

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

#slash_command_stringObject (private)



30
31
32
# File 'lib/gitlab/triage/command_builders/label_command_builder.rb', line 30

def slash_command_string
  "/label"
end