Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/project_services/mattermost_slash_commands_service.rb')
-rw-r--r--app/models/project_services/mattermost_slash_commands_service.rb44
1 files changed, 23 insertions, 21 deletions
diff --git a/app/models/project_services/mattermost_slash_commands_service.rb b/app/models/project_services/mattermost_slash_commands_service.rb
index 33431f41dc2..2cb481182d7 100644
--- a/app/models/project_services/mattermost_slash_commands_service.rb
+++ b/app/models/project_services/mattermost_slash_commands_service.rb
@@ -1,4 +1,4 @@
-class MattermostSlashCommandsService < ChatService
+class MattermostSlashCommandsService < ChatSlashCommandsService
include TriggersHelper
prop_accessor :token
@@ -19,31 +19,33 @@ class MattermostSlashCommandsService < ChatService
'mattermost_slash_commands'
end
- def fields
- [
- { type: 'text', name: 'token', placeholder: '' }
- ]
- end
-
- def trigger(params)
- return nil unless valid_token?(params[:token])
+ def configure(user, params)
+ token = Mattermost::Command.new(user).
+ create(command(params))
- user = find_chat_user(params)
- unless user
- url = authorize_chat_name_url(params)
- return Mattermost::Presenter.authorize_chat_name(url)
- end
+ update(active: true, token: token) if token
+ rescue Mattermost::Error => e
+ [false, e.message]
+ end
- Gitlab::ChatCommands::Command.new(project, user, params).execute
+ def list_teams(user)
+ Mattermost::Team.new(user).all
+ rescue Mattermost::Error => e
+ [[], e.message]
end
private
- def find_chat_user(params)
- ChatNames::FindUserService.new(self, params).execute
- end
-
- def authorize_chat_name_url(params)
- ChatNames::AuthorizeUserService.new(self, params).execute
+ def command(params)
+ pretty_project_name = project.name_with_namespace
+
+ params.merge(
+ auto_complete: true,
+ auto_complete_desc: "Perform common operations on: #{pretty_project_name}",
+ auto_complete_hint: '[help]',
+ description: "Perform common operations on: #{pretty_project_name}",
+ display_name: "GitLab / #{pretty_project_name}",
+ method: 'P',
+ username: 'GitLab')
end
end