Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
ed880e49
Commit
ed880e49
authored
Dec 15, 2016
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename ChatService into ChatSlashCommandsService
parent
0d3e2435
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
60 additions
and
60 deletions
+60
-60
app/models/project.rb
app/models/project.rb
+0
-1
app/models/project_services/chat_slash_commands_service.rb
app/models/project_services/chat_slash_commands_service.rb
+55
-0
app/models/project_services/mattermost_slash_commands_service.rb
...els/project_services/mattermost_slash_commands_service.rb
+2
-26
app/models/project_services/slack_slash_commands_service.rb
app/models/project_services/slack_slash_commands_service.rb
+3
-33
No files found.
app/models/project.rb
View file @
ed880e49
...
...
@@ -79,7 +79,6 @@ class Project < ActiveRecord::Base
has_one
:last_event
,
->
{
order
'events.created_at DESC'
},
class_name:
'Event'
has_many
:boards
,
before_add: :validate_board_limit
,
dependent: :destroy
has_many
:chat_services
# Project services
has_one
:campfire_service
,
dependent: :destroy
...
...
app/models/project_services/chat_service.rb
→
app/models/project_services/chat_s
lash_commands_s
ervice.rb
View file @
ed880e49
# Base class for Chat services
# This class is not meant to be used directly, but only to inherit from.
class
ChatService
<
Service
# This class is not meant to be used directly, but only to inher
r
it from.
class
ChatS
lashCommandsS
ervice
<
Service
default_value_for
:category
,
'chat'
prop_accessor
:token
has_many
:chat_names
,
foreign_key: :service_id
def
valid_token?
(
token
)
...
...
@@ -15,7 +17,39 @@ class ChatService < Service
[]
end
def
can_test?
false
end
def
fields
[
{
type:
'text'
,
name:
'token'
,
placeholder:
''
}
]
end
def
trigger
(
params
)
raise
NotImplementedError
return
nil
unless
valid_token?
(
params
[
:token
])
user
=
find_chat_user
(
params
)
unless
user
url
=
authorize_chat_name_url
(
params
)
return
presenter
.
authorize_chat_name
(
url
)
end
Gitlab
::
ChatCommands
::
Command
.
new
(
presenter
,
project
,
user
,
params
).
execute
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
end
def
presenter
throw
NotImplementedError
end
end
app/models/project_services/mattermost_slash_commands_service.rb
View file @
ed880e49
...
...
@@ -19,31 +19,7 @@ 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
])
user
=
find_chat_user
(
params
)
unless
user
url
=
authorize_chat_name_url
(
params
)
return
Mattermost
::
Presenter
.
authorize_chat_name
(
url
)
end
Gitlab
::
ChatCommands
::
Command
.
new
(
project
,
user
,
params
).
execute
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
presenter
Gitlab
::
ChatCommands
::
Presenters
::
Mattermost
.
new
end
end
app/models/project_services/slack_slash_commands_service.rb
View file @
ed880e49
class
SlackSlashCommandsService
<
ChatService
class
SlackSlashCommandsService
<
ChatS
lashCommandsS
ervice
include
TriggersHelper
prop_accessor
:token
def
can_test?
false
end
def
title
'Slack Slash Command'
end
...
...
@@ -19,31 +13,7 @@ class SlackSlashCommandsService < ChatService
'slack_slash_commands'
end
def
fields
[
{
type:
'text'
,
name:
'token'
,
placeholder:
''
}
]
end
def
trigger
(
params
)
return
nil
unless
valid_token?
(
params
[
:token
])
user
=
find_chat_user
(
params
)
unless
user
url
=
authorize_chat_name_url
(
params
)
return
Gitlab
::
ChatCommands
::
Presenters
::
Access
.
new
(
url
).
authorize
end
Gitlab
::
ChatCommands
::
Command
.
new
(
project
,
user
,
params
).
execute
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
presenter
Gitlab
::
ChatCommands
::
Presenters
::
Mattermost
.
new
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment