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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
37057870
Commit
37057870
authored
Dec 15, 2016
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename Mattermost::Presenter to Presenter
parent
ed880e49
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
133 additions
and
131 deletions
+133
-131
lib/gitlab/chat_commands/presenter.rb
lib/gitlab/chat_commands/presenter.rb
+133
-0
lib/gitlab/chat_commands/presenters/mattermost.rb
lib/gitlab/chat_commands/presenters/mattermost.rb
+0
-131
No files found.
lib/gitlab/chat_commands/presenter.rb
0 → 100644
View file @
37057870
module
Gitlab
class
ChatCommands
class
Presenter
class
<<
self
include
Gitlab
::
Routing
.
url_helpers
def
authorize_chat_name
(
url
)
message
=
if
url
":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
ephemeral_response
(
message
)
end
def
help
(
commands
,
trigger
)
if
commands
.
none?
ephemeral_response
(
"No commands configured"
)
else
commands
.
map!
{
|
command
|
"
#{
trigger
}
#{
command
}
"
}
message
=
header_with_list
(
"Available commands"
,
commands
)
ephemeral_response
(
message
)
end
end
def
present
(
subject
)
return
not_found
unless
subject
if
subject
.
is_a?
(
Gitlab
::
ChatCommands
::
Result
)
show_result
(
subject
)
elsif
subject
.
respond_to?
(
:count
)
if
subject
.
many?
multiple_resources
(
subject
)
elsif
subject
.
none?
not_found
else
single_resource
(
subject
)
end
else
single_resource
(
subject
)
end
end
def
access_denied
ephemeral_response
(
"Whoops! That action is not allowed. This incident will be [reported](https://xkcd.com/838/)."
)
end
private
def
show_result
(
result
)
case
result
.
type
when
:success
in_channel_response
(
result
.
message
)
else
ephemeral_response
(
result
.
message
)
end
end
def
not_found
ephemeral_response
(
"404 not found! GitLab couldn't find what you were looking for! :boom:"
)
end
def
single_resource
(
resource
)
return
error
(
resource
)
if
resource
.
errors
.
any?
||
!
resource
.
persisted?
message
=
"###
#{
title
(
resource
)
}
"
message
<<
"
\n\n
#{
resource
.
description
}
"
if
resource
.
try
(
:description
)
in_channel_response
(
message
)
end
def
multiple_resources
(
resources
)
resources
.
map!
{
|
resource
|
title
(
resource
)
}
message
=
header_with_list
(
"Multiple results were found:"
,
resources
)
ephemeral_response
(
message
)
end
def
error
(
resource
)
message
=
header_with_list
(
"The action was not successful, because:"
,
resource
.
errors
.
messages
)
ephemeral_response
(
message
)
end
def
title
(
resource
)
reference
=
resource
.
try
(
:to_reference
)
||
resource
.
try
(
:id
)
title
=
resource
.
try
(
:title
)
||
resource
.
try
(
:name
)
"[
#{
reference
}
#{
title
}
](
#{
url
(
resource
)
}
)"
end
def
header_with_list
(
header
,
items
)
message
=
[
header
]
items
.
each
do
|
item
|
message
<<
"-
#{
item
}
"
end
message
.
join
(
"
\n
"
)
end
def
url
(
resource
)
url_for
(
[
resource
.
project
.
namespace
.
becomes
(
Namespace
),
resource
.
project
,
resource
]
)
end
def
ephemeral_response
(
message
)
{
response_type: :ephemeral
,
text:
message
,
status:
200
}
end
def
in_channel_response
(
message
)
{
response_type: :in_channel
,
text:
message
,
status:
200
}
end
end
end
end
end
lib/gitlab/chat_commands/presenters/mattermost.rb
deleted
100644 → 0
View file @
ed880e49
module
Mattermost
class
Presenter
class
<<
self
include
Gitlab
::
Routing
.
url_helpers
def
authorize_chat_name
(
url
)
message
=
if
url
":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
ephemeral_response
(
message
)
end
def
help
(
commands
,
trigger
)
if
commands
.
none?
ephemeral_response
(
"No commands configured"
)
else
commands
.
map!
{
|
command
|
"
#{
trigger
}
#{
command
}
"
}
message
=
header_with_list
(
"Available commands"
,
commands
)
ephemeral_response
(
message
)
end
end
def
present
(
subject
)
return
not_found
unless
subject
if
subject
.
is_a?
(
Gitlab
::
ChatCommands
::
Result
)
show_result
(
subject
)
elsif
subject
.
respond_to?
(
:count
)
if
subject
.
many?
multiple_resources
(
subject
)
elsif
subject
.
none?
not_found
else
single_resource
(
subject
)
end
else
single_resource
(
subject
)
end
end
def
access_denied
ephemeral_response
(
"Whoops! That action is not allowed. This incident will be [reported](https://xkcd.com/838/)."
)
end
private
def
show_result
(
result
)
case
result
.
type
when
:success
in_channel_response
(
result
.
message
)
else
ephemeral_response
(
result
.
message
)
end
end
def
not_found
ephemeral_response
(
"404 not found! GitLab couldn't find what you were looking for! :boom:"
)
end
def
single_resource
(
resource
)
return
error
(
resource
)
if
resource
.
errors
.
any?
||
!
resource
.
persisted?
message
=
"###
#{
title
(
resource
)
}
"
message
<<
"
\n\n
#{
resource
.
description
}
"
if
resource
.
try
(
:description
)
in_channel_response
(
message
)
end
def
multiple_resources
(
resources
)
resources
.
map!
{
|
resource
|
title
(
resource
)
}
message
=
header_with_list
(
"Multiple results were found:"
,
resources
)
ephemeral_response
(
message
)
end
def
error
(
resource
)
message
=
header_with_list
(
"The action was not successful, because:"
,
resource
.
errors
.
messages
)
ephemeral_response
(
message
)
end
def
title
(
resource
)
reference
=
resource
.
try
(
:to_reference
)
||
resource
.
try
(
:id
)
title
=
resource
.
try
(
:title
)
||
resource
.
try
(
:name
)
"[
#{
reference
}
#{
title
}
](
#{
url
(
resource
)
}
)"
end
def
header_with_list
(
header
,
items
)
message
=
[
header
]
items
.
each
do
|
item
|
message
<<
"-
#{
item
}
"
end
message
.
join
(
"
\n
"
)
end
def
url
(
resource
)
url_for
(
[
resource
.
project
.
namespace
.
becomes
(
Namespace
),
resource
.
project
,
resource
]
)
end
def
ephemeral_response
(
message
)
{
response_type: :ephemeral
,
text:
message
,
status:
200
}
end
def
in_channel_response
(
message
)
{
response_type: :in_channel
,
text:
message
,
status:
200
}
end
end
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