BigW Consortium Gitlab

command.rb 1.06 KB
Newer Older
1
module Gitlab
2
  module SlashCommands
3 4
    class Command < BaseCommand
      COMMANDS = [
5 6 7 8
        Gitlab::SlashCommands::IssueShow,
        Gitlab::SlashCommands::IssueNew,
        Gitlab::SlashCommands::IssueSearch,
        Gitlab::SlashCommands::Deploy
9 10 11
      ].freeze

      def execute
12 13 14 15
        command, match = match_command

        if command
          if command.allowed?(project, current_user)
16
            command.new(project, current_user, params).execute(match)
17
          else
18
            Gitlab::SlashCommands::Presenters::Access.new.access_denied
19
          end
20
        else
21
          Gitlab::SlashCommands::Help.new(project, current_user, params).execute(available_commands, params[:text])
22
        end
23 24
      end

25
      def match_command
26
        match = nil
Z.J. van de Weg committed
27 28 29 30
        service =
          available_commands.find do |klass|
            match = klass.match(params[:text])
          end
31 32 33 34

        [service, match]
      end

Kamil Trzcinski committed
35 36
      private

37 38 39 40
      def available_commands
        COMMANDS.select do |klass|
          klass.available?(project)
        end
41 42 43 44
      end
    end
  end
end