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
Tatuya Kamada
gitlab-ce
Commits
0f277628
Commit
0f277628
authored
Dec 16, 2016
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use Slack::Notifier::LinkFormatter to convert markdown links to slack compat
parent
f9f1a508
Changes
12
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
57 additions
and
58 deletions
+57
-58
app/models/project_services/chat_slash_commands_service.rb
app/models/project_services/chat_slash_commands_service.rb
+2
-6
app/models/project_services/mattermost_slash_commands_service.rb
...els/project_services/mattermost_slash_commands_service.rb
+0
-4
app/models/project_services/slack_slash_commands_service.rb
app/models/project_services/slack_slash_commands_service.rb
+9
-2
lib/gitlab/chat_commands/base_command.rb
lib/gitlab/chat_commands/base_command.rb
+1
-1
lib/gitlab/chat_commands/presenter.rb
lib/gitlab/chat_commands/presenter.rb
+3
-22
spec/lib/gitlab/chat_commands/command_spec.rb
spec/lib/gitlab/chat_commands/command_spec.rb
+3
-11
spec/models/project_services/mattermost_notification_service_spec.rb
.../project_services/mattermost_notification_service_spec.rb
+1
-1
spec/models/project_services/mattermost_slash_commands_service_spec.rb
...roject_services/mattermost_slash_commands_service_spec.rb
+1
-1
spec/models/project_services/slack_notification_service_spec.rb
...odels/project_services/slack_notification_service_spec.rb
+1
-1
spec/models/project_services/slack_slash_commands_service.rb
spec/models/project_services/slack_slash_commands_service.rb
+34
-1
spec/support/chat_slash_commands_shared_examples.rb
spec/support/chat_slash_commands_shared_examples.rb
+1
-7
spec/support/slack_mattermost_notifications_shared_examples.rb
...support/slack_mattermost_notifications_shared_examples.rb
+1
-1
No files found.
app/models/project_services/chat_slash_commands_service.rb
View file @
0f277628
...
...
@@ -37,7 +37,7 @@ class ChatSlashCommandsService < Service
end
Gitlab
::
ChatCommands
::
Command
.
new
(
project
,
user
,
params
.
merge
(
presenter_format:
presenter_format
)
).
execute
params
).
execute
end
private
...
...
@@ -51,10 +51,6 @@ class ChatSlashCommandsService < Service
end
def
presenter
Gitlab
::
ChatCommands
::
Presenter
.
new
(
presenter_format
)
end
def
presenter_format
throw
NotImplementedError
Gitlab
::
ChatCommands
::
Presenter
.
new
end
end
app/models/project_services/mattermost_slash_commands_service.rb
View file @
0f277628
...
...
@@ -18,8 +18,4 @@ class MattermostSlashCommandsService < ChatSlashCommandsService
def
to_param
'mattermost_slash_commands'
end
def
presenter_format
'mattermost'
end
end
app/models/project_services/slack_slash_commands_service.rb
View file @
0f277628
...
...
@@ -13,7 +13,14 @@ class SlackSlashCommandsService < ChatSlashCommandsService
'slack_slash_commands'
end
def
presenter_format
'slack'
def
trigger
(
params
)
result
=
super
# Format messages to be Slack-compatible
if
result
&&
result
[
:text
]
result
[
:text
]
=
Slack
::
Notifier
::
LinkFormatter
.
format
(
result
[
:text
])
end
result
end
end
lib/gitlab/chat_commands/base_command.rb
View file @
0f277628
...
...
@@ -44,7 +44,7 @@ module Gitlab
end
def
presenter
Gitlab
::
ChatCommands
::
Presenter
.
new
(
params
[
:presenter_format
])
Gitlab
::
ChatCommands
::
Presenter
.
new
end
end
end
...
...
lib/gitlab/chat_commands/presenter.rb
View file @
0f277628
...
...
@@ -3,15 +3,9 @@ module Gitlab
class
Presenter
include
Gitlab
::
Routing
.
url_helpers
attr_reader
:format
def
initialize
(
format
)
@format
=
format
end
def
authorize_chat_name
(
url
)
message
=
if
url
":wave: Hi there! Before I do anything for you, please
#{
link
(
url
,
'connect your GitLab account'
)
}
."
":wave: Hi there! Before I do anything for you, please
[connect your GitLab account](
#{
url
}
)
."
else
":sweat_smile: Couldn't identify you, nor can I autorize you!"
end
...
...
@@ -49,7 +43,7 @@ module Gitlab
end
def
access_denied
ephemeral_response
(
"Whoops! That action is not allowed. This incident will be
#{
link
(
'https://xkcd.com/838/'
,
'reported'
)
}
."
)
ephemeral_response
(
"Whoops! That action is not allowed. This incident will be [reported](https://xkcd.com/838/)
."
)
end
private
...
...
@@ -94,7 +88,7 @@ module Gitlab
reference
=
resource
.
try
(
:to_reference
)
||
resource
.
try
(
:id
)
title
=
resource
.
try
(
:title
)
||
resource
.
try
(
:name
)
link
(
url
(
resource
),
"
#{
reference
}
#{
title
}
"
)
"[
#{
reference
}
#{
title
}
](
#{
url
(
resource
)
}
)"
end
def
header_with_list
(
header
,
items
)
...
...
@@ -132,19 +126,6 @@ module Gitlab
status:
200
}
end
def
link
(
url
,
title
)
case
format
when
'slack'
"<
#{
url
}
|
#{
title
}
>"
when
'mattermost'
"[
#{
title
}
](
#{
url
}
)"
else
title
end
end
end
end
end
spec/lib/gitlab/chat_commands/command_spec.rb
View file @
0f277628
...
...
@@ -3,12 +3,10 @@ require 'spec_helper'
describe
Gitlab
::
ChatCommands
::
Command
,
service:
true
do
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:format
)
{
nil
}
describe
'#execute'
do
subject
do
described_class
.
new
(
project
,
user
,
params
.
merge
(
presenter_format:
format
)).
execute
described_class
.
new
(
project
,
user
,
params
).
execute
end
context
'when no command is available'
do
...
...
@@ -51,16 +49,10 @@ describe Gitlab::ChatCommands::Command, service: true do
expect
(
subject
[
:text
]).
to
match
(
"my new issue"
)
end
%w(slack mattermost)
.
each
do
|
format
|
context
"for
#{
format
}
"
do
let
(
:format
)
{
format
}
it
'shows a link to the new issue'
do
expect
(
subject
[
:text
]).
to
match
(
/\/issues\/\d+/
)
end
end
end
end
context
'when trying to do deployment'
do
let
(
:params
)
{
{
text:
'deploy staging to production'
}
}
...
...
spec/models/project_services/mattermost_notification_service_spec.rb
View file @
0f277628
require
'spec_helper'
describe
MattermostNotificationService
,
models:
true
do
it_behaves_like
"slack or mattermost"
it_behaves_like
"slack or mattermost
notifications
"
end
spec/models/project_services/mattermost_slash_commands_service_spec.rb
View file @
0f277628
require
'spec_helper'
describe
MattermostSlashCommandsService
,
models:
true
do
it
{
is_expected
.
to
respond_to
:presenter_format
}
it
_behaves_like
"chat slash commands"
end
spec/models/project_services/slack_notification_service_spec.rb
View file @
0f277628
require
'spec_helper'
describe
SlackNotificationService
,
models:
true
do
it_behaves_like
"slack or mattermost"
it_behaves_like
"slack or mattermost
notifications
"
end
spec/models/project_services/slack_slash_commands_service.rb
View file @
0f277628
require
'spec_helper'
describe
SlackSlashCommandsService
,
models:
true
do
it
{
is_expected
.
to
respond_to
:presenter_format
}
it_behaves_like
"chat slash commands"
describe
'#trigger'
do
context
'when an auth url is generated'
do
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:params
)
do
{
team_domain:
'http://domain.tld'
,
team_id:
'T3423423'
,
user_id:
'U234234'
,
user_name:
'mepmep'
,
token:
'token'
}
end
let
(
:service
)
do
project
.
create_slack_slash_commands_service
(
properties:
{
token:
'token'
}
)
end
let
(
:authorize_url
)
do
'http://authorize.example.com/'
end
before
do
allow
(
service
).
to
receive
(
:authorize_chat_name_url
).
and_return
(
authorize_url
)
end
it
'uses slack compatible links'
do
response
=
service
.
trigger
(
params
)
expect
(
response
[
:text
]).
to
include
(
"<
#{
authorize_url
}
|connect your GitLab account>"
)
end
end
end
end
spec/
models/project_services/chat_slash_commands_service_spec
.rb
→
spec/
support/chat_slash_commands_shared_examples
.rb
View file @
0f277628
require
'spec_helper'
describe
ChatSlashCommandsService
,
models:
true
do
RSpec
.
shared_examples
'chat slash commands'
do
describe
"Associations"
do
it
{
is_expected
.
to
respond_to
:token
}
it
{
is_expected
.
to
have_many
:chat_names
}
...
...
@@ -29,10 +27,6 @@ describe ChatSlashCommandsService, models: true do
describe
'#trigger'
do
subject
{
described_class
.
new
}
before
do
allow
(
subject
).
to
receive
(
:presenter_format
).
and_return
(
'unknown'
)
end
context
'no token is passed'
do
let
(
:params
)
{
Hash
.
new
}
...
...
spec/support/slack_mattermost_shared_examples.rb
→
spec/support/slack_mattermost_
notifications_
shared_examples.rb
View file @
0f277628
Dir
[
Rails
.
root
.
join
(
"app/models/project_services/chat_message/*.rb"
)].
each
{
|
f
|
require
f
}
RSpec
.
shared_examples
'slack or mattermost'
do
RSpec
.
shared_examples
'slack or mattermost
notifications
'
do
let
(
:chat_service
)
{
described_class
.
new
}
let
(
:webhook_url
)
{
'https://example.gitlab.com/'
}
...
...
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