Class: Gitlab::SlashCommands::GlobalSlackHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/slash_commands/global_slack_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ GlobalSlackHandler

Returns a new instance of GlobalSlackHandler.



8
9
10
11
# File 'lib/gitlab/slash_commands/global_slack_handler.rb', line 8

def initialize(params)
  @project_alias, command = parse_command_text(params)
  @params = params.merge(text: command, original_command: params[:text])
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



6
7
8
# File 'lib/gitlab/slash_commands/global_slack_handler.rb', line 6

def params
  @params
end

#project_aliasObject (readonly)

Returns the value of attribute project_alias.



6
7
8
# File 'lib/gitlab/slash_commands/global_slack_handler.rb', line 6

def project_alias
  @project_alias
end

Instance Method Details

#triggerObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/gitlab/slash_commands/global_slack_handler.rb', line 13

def trigger
  return false unless valid_token?
  return Gitlab::SlashCommands::ApplicationHelp.new(nil, params).execute if help_command?

  unless slack_integration = find_slack_integration
    error_message = 'GitLab error: project or alias not found'
    return Gitlab::SlashCommands::Presenters::Error.new(error_message).message
  end

  chat_user = ChatNames::FindUserService.new(params[:team_id], params[:user_id]).execute
  integration = slack_integration.integration

  if chat_user&.user
    Gitlab::SlashCommands::Command.new(integration.project, chat_user, params).execute
  else
    url = ChatNames::AuthorizeUserService.new(params).execute
    Gitlab::SlashCommands::Presenters::Access.new(url).authorize
  end
end