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
d7f298c1
Commit
d7f298c1
authored
Jan 30, 2017
by
Z.J. van de Weg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Incorporate feedback
parent
3df15b95
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
49 additions
and
18 deletions
+49
-18
lib/gitlab/chat_commands/command.rb
lib/gitlab/chat_commands/command.rb
+1
-1
lib/gitlab/chat_commands/help.rb
lib/gitlab/chat_commands/help.rb
+2
-2
lib/gitlab/chat_commands/presenters/access.rb
lib/gitlab/chat_commands/presenters/access.rb
+14
-0
lib/gitlab/chat_commands/presenters/help.rb
lib/gitlab/chat_commands/presenters/help.rb
+7
-5
lib/gitlab/chat_commands/presenters/issue_new.rb
lib/gitlab/chat_commands/presenters/issue_new.rb
+3
-1
lib/gitlab/chat_commands/presenters/issue_search.rb
lib/gitlab/chat_commands/presenters/issue_search.rb
+3
-1
lib/gitlab/chat_commands/presenters/issue_show.rb
lib/gitlab/chat_commands/presenters/issue_show.rb
+8
-3
spec/lib/gitlab/chat_commands/command_spec.rb
spec/lib/gitlab/chat_commands/command_spec.rb
+1
-5
spec/lib/gitlab/chat_commands/presenters/issue_show_spec.rb
spec/lib/gitlab/chat_commands/presenters/issue_show_spec.rb
+10
-0
No files found.
lib/gitlab/chat_commands/command.rb
View file @
d7f298c1
...
@@ -18,7 +18,7 @@ module Gitlab
...
@@ -18,7 +18,7 @@ module Gitlab
Gitlab
::
ChatCommands
::
Presenters
::
Access
.
new
.
access_denied
Gitlab
::
ChatCommands
::
Presenters
::
Access
.
new
.
access_denied
end
end
else
else
Gitlab
::
ChatCommands
::
Help
.
new
(
project
,
current_user
,
params
).
execute
(
available_commands
)
Gitlab
::
ChatCommands
::
Help
.
new
(
project
,
current_user
,
params
).
execute
(
available_commands
,
params
[
:text
]
)
end
end
end
end
...
...
lib/gitlab/chat_commands/help.rb
View file @
d7f298c1
...
@@ -16,8 +16,8 @@ module Gitlab
...
@@ -16,8 +16,8 @@ module Gitlab
true
true
end
end
def
execute
(
commands
)
def
execute
(
commands
,
text
)
Gitlab
::
ChatCommands
::
Presenters
::
Help
.
new
(
commands
).
present
(
trigger
)
Gitlab
::
ChatCommands
::
Presenters
::
Help
.
new
(
commands
).
present
(
trigger
,
text
)
end
end
def
trigger
def
trigger
...
...
lib/gitlab/chat_commands/presenters/access.rb
View file @
d7f298c1
...
@@ -20,6 +20,20 @@ module Gitlab
...
@@ -20,6 +20,20 @@ module Gitlab
ephemeral_response
(
text:
message
)
ephemeral_response
(
text:
message
)
end
end
def
unknown_command
(
commands
)
ephemeral_response
(
text:
help_message
(
trigger
))
end
private
def
help_message
(
trigger
)
header_with_list
(
"Command not found, these are the commands you can use"
,
full_commands
(
trigger
))
end
def
full_commands
(
trigger
)
@resource
.
map
{
|
command
|
"
#{
trigger
}
#{
command
.
help_message
}
"
}
end
end
end
end
end
end
end
...
...
lib/gitlab/chat_commands/presenters/help.rb
View file @
d7f298c1
...
@@ -2,17 +2,19 @@ module Gitlab
...
@@ -2,17 +2,19 @@ module Gitlab
module
ChatCommands
module
ChatCommands
module
Presenters
module
Presenters
class
Help
<
Presenters
::
Base
class
Help
<
Presenters
::
Base
def
present
(
trigger
)
def
present
(
trigger
,
text
)
ephemeral_response
(
text:
help_message
(
trigger
))
ephemeral_response
(
text:
help_message
(
trigger
,
text
))
end
end
private
private
def
help_message
(
trigger
)
def
help_message
(
trigger
,
text
)
if
@resource
.
present?
return
"No commands available :thinking_face:"
unless
@resource
.
present?
if
text
.
start_with?
(
'help'
)
header_with_list
(
"Available commands"
,
full_commands
(
trigger
))
header_with_list
(
"Available commands"
,
full_commands
(
trigger
))
else
else
"No commands available :thinking_face:"
header_with_list
(
"Unknown command, these commands are available"
,
full_commands
(
trigger
))
end
end
end
end
...
...
lib/gitlab/chat_commands/presenters/issue_new.rb
View file @
d7f298c1
...
@@ -24,7 +24,9 @@ module Gitlab
...
@@ -24,7 +24,9 @@ module Gitlab
fields:
fields
,
fields:
fields
,
mrkdwn_in:
[
mrkdwn_in:
[
:title
,
:title
,
:text
:pretext
,
:text
,
:fields
]
]
}
}
]
]
...
...
lib/gitlab/chat_commands/presenters/issue_search.rb
View file @
d7f298c1
...
@@ -7,6 +7,8 @@ module Gitlab
...
@@ -7,6 +7,8 @@ module Gitlab
def
present
def
present
text
=
if
@resource
.
count
>=
5
text
=
if
@resource
.
count
>=
5
"Here are the first 5 issues I found:"
"Here are the first 5 issues I found:"
elsif
@resource
.
one?
"Here is the only issue I found:"
else
else
"Here are the
#{
@resource
.
count
}
issues I found:"
"Here are the
#{
@resource
.
count
}
issues I found:"
end
end
...
@@ -26,7 +28,7 @@ module Gitlab
...
@@ -26,7 +28,7 @@ module Gitlab
text:
"
#{
url
}
·
#{
issue
.
title
}
(
#{
status_text
(
issue
)
}
)"
,
text:
"
#{
url
}
·
#{
issue
.
title
}
(
#{
status_text
(
issue
)
}
)"
,
mrkdwn_in:
[
mrkdwn_in:
[
"text"
:text
]
]
}
}
end
end
...
...
lib/gitlab/chat_commands/presenters/issue_show.rb
View file @
d7f298c1
...
@@ -5,7 +5,11 @@ module Gitlab
...
@@ -5,7 +5,11 @@ module Gitlab
include
Presenters
::
Issuable
include
Presenters
::
Issuable
def
present
def
present
in_channel_response
(
show_issue
)
if
@resource
.
confidential?
ephemeral_response
(
show_issue
)
else
in_channel_response
(
show_issue
)
end
end
end
private
private
...
@@ -25,7 +29,8 @@ module Gitlab
...
@@ -25,7 +29,8 @@ module Gitlab
fields:
fields
,
fields:
fields
,
mrkdwn_in:
[
mrkdwn_in:
[
:pretext
,
:pretext
,
:text
:text
,
:fields
]
]
}
}
]
]
...
@@ -48,7 +53,7 @@ module Gitlab
...
@@ -48,7 +53,7 @@ module Gitlab
end
end
def
pretext
def
pretext
"Issue *
#{
@resource
.
to_reference
}
from
#{
project
.
name_with_namespace
}
"
"Issue *
#{
@resource
.
to_reference
}
*
from
#{
project
.
name_with_namespace
}
"
end
end
end
end
end
end
...
...
spec/lib/gitlab/chat_commands/command_spec.rb
View file @
d7f298c1
...
@@ -5,7 +5,6 @@ describe Gitlab::ChatCommands::Command, service: true do
...
@@ -5,7 +5,6 @@ describe Gitlab::ChatCommands::Command, service: true do
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
describe
'#execute'
do
describe
'#execute'
do
<<<<<<<
HEAD
subject
do
subject
do
described_class
.
new
(
project
,
user
,
params
).
execute
described_class
.
new
(
project
,
user
,
params
).
execute
end
end
...
@@ -19,16 +18,13 @@ describe Gitlab::ChatCommands::Command, service: true do
...
@@ -19,16 +18,13 @@ describe Gitlab::ChatCommands::Command, service: true do
expect
(
subject
[
:text
]).
to
start_with
(
'404 not found'
)
expect
(
subject
[
:text
]).
to
start_with
(
'404 not found'
)
end
end
end
end
=======
subject
{
described_class
.
new
(
project
,
user
,
params
).
execute
}
>>>>>>>
Chat
Commands
have
presenters
context
'when an unknown command is triggered'
do
context
'when an unknown command is triggered'
do
let
(
:params
)
{
{
command:
'/gitlab'
,
text:
"unknown command 123"
}
}
let
(
:params
)
{
{
command:
'/gitlab'
,
text:
"unknown command 123"
}
}
it
'displays the help message'
do
it
'displays the help message'
do
expect
(
subject
[
:response_type
]).
to
be
(
:ephemeral
)
expect
(
subject
[
:response_type
]).
to
be
(
:ephemeral
)
expect
(
subject
[
:text
]).
to
start_with
(
'
Available commands
'
)
expect
(
subject
[
:text
]).
to
start_with
(
'
Unknown command
'
)
expect
(
subject
[
:text
]).
to
match
(
'/gitlab issue show'
)
expect
(
subject
[
:text
]).
to
match
(
'/gitlab issue show'
)
end
end
end
end
...
...
spec/lib/gitlab/chat_commands/presenters/issue_show_spec.rb
View file @
d7f298c1
...
@@ -21,7 +21,17 @@ describe Gitlab::ChatCommands::Presenters::IssueShow do
...
@@ -21,7 +21,17 @@ describe Gitlab::ChatCommands::Presenters::IssueShow do
end
end
it
'shows the upvote count'
do
it
'shows the upvote count'
do
expect
(
subject
[
:response_type
]).
to
be
(
:in_channel
)
expect
(
attachment
[
:text
]).
to
start_with
(
"**Open** · :+1: 1"
)
expect
(
attachment
[
:text
]).
to
start_with
(
"**Open** · :+1: 1"
)
end
end
end
end
context
'confidential issue'
do
let
(
:issue
)
{
create
(
:issue
,
project:
project
)
}
it
'shows an ephemeral response'
do
expect
(
subject
[
:response_type
]).
to
be
(
:in_channel
)
expect
(
attachment
[
:text
]).
to
start_with
(
"**Open**"
)
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