Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
projects.thm.de
GitLab
Commits
1607efa4
Commit
1607efa4
authored
Nov 17, 2016
by
Z.J. van de Weg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for increased converage
parent
6737ada0
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
45 additions
and
37 deletions
+45
-37
lib/gitlab/chat_commands/base_command.rb
lib/gitlab/chat_commands/base_command.rb
+0
-8
lib/gitlab/chat_commands/command.rb
lib/gitlab/chat_commands/command.rb
+13
-3
lib/gitlab/chat_commands/issue_create.rb
lib/gitlab/chat_commands/issue_create.rb
+3
-3
lib/gitlab/chat_commands/issue_show.rb
lib/gitlab/chat_commands/issue_show.rb
+1
-1
lib/mattermost/presenter.rb
lib/mattermost/presenter.rb
+3
-2
spec/lib/gitlab/chat_commands/command_spec.rb
spec/lib/gitlab/chat_commands/command_spec.rb
+17
-5
spec/lib/gitlab/chat_commands/issue_create_spec.rb
spec/lib/gitlab/chat_commands/issue_create_spec.rb
+5
-10
spec/lib/gitlab/chat_commands/issue_show_spec.rb
spec/lib/gitlab/chat_commands/issue_show_spec.rb
+3
-5
No files found.
lib/gitlab/chat_commands/base_command.rb
View file @
1607efa4
...
...
@@ -35,14 +35,6 @@ def can?(object, action, subject)
Ability
.
allowed?
(
object
,
action
,
subject
)
end
def
present
(
resource
)
Mattermost
::
Presenter
.
present
(
resource
)
end
def
help
(
messages
)
Mattermost
::
Presenter
.
help
(
messages
)
end
def
find_by_iid
(
iid
)
resource
=
collection
.
find_by
(
iid:
iid
)
...
...
lib/gitlab/chat_commands/command.rb
View file @
1607efa4
...
...
@@ -9,9 +9,11 @@ class Command < BaseCommand
def
execute
klass
,
match
=
fetch_klass
return
help
(
help_messages
,
params
[
:command
])
unless
klass
.
try
(
:available?
,
project
)
klass
.
new
(
project
,
current_user
,
params
).
execute
(
match
)
if
klass
present
klass
.
new
(
project
,
current_user
,
params
).
execute
(
match
)
else
help
(
help_messages
)
end
end
private
...
...
@@ -40,6 +42,14 @@ def available_commands
def
command
params
[
:text
]
end
def
present
(
resource
)
Mattermost
::
Presenter
.
present
(
resource
)
end
def
help
(
messages
)
Mattermost
::
Presenter
.
help
(
messages
,
params
[
:command
])
end
end
end
end
lib/gitlab/chat_commands/issue_create.rb
View file @
1607efa4
module
Gitlab
module
ChatCommands
class
IssueCreate
<
IssueCommand
class
IssueCreate
<
IssueCommand
def
self
.
match
(
text
)
/\Aissue\s+create\s+(?<title>[^\n]*)\n*(?<description>.*)\z/
.
match
(
text
)
end
...
...
@@ -10,12 +10,12 @@ def self.help_message
end
def
execute
(
match
)
p
re
sent
nil
unless
can?
(
current_user
,
:create_issue
,
project
)
re
turn
nil
unless
can?
(
current_user
,
:create_issue
,
project
)
title
=
match
[
:title
]
description
=
match
[
:description
]
present
Issues
::
CreateService
.
new
(
project
,
current_user
,
title:
title
,
description:
description
).
execute
Issues
::
CreateService
.
new
(
project
,
current_user
,
title:
title
,
description:
description
).
execute
end
end
end
...
...
lib/gitlab/chat_commands/issue_show.rb
View file @
1607efa4
...
...
@@ -10,7 +10,7 @@ def self.help_message
end
def
execute
(
match
)
present
find_by_iid
(
match
[
:iid
])
find_by_iid
(
match
[
:iid
])
end
end
end
...
...
lib/mattermost/presenter.rb
View file @
1607efa4
...
...
@@ -4,19 +4,20 @@ class << self
include
Rails
.
application
.
routes
.
url_helpers
def
authorize_chat_name
(
url
)
message
=
"Hi there! We've yet to get acquainted! Please
[
introduce yourself](
#{
url
}
)!"
message
=
"Hi there! We've yet to get acquainted! Please introduce yourself
by [connection your GitLab profile
](
#{
url
}
)!"
ephemeral_response
(
message
)
end
def
help
(
messages
,
command
)
return
ephemeral_response
(
"No commands configured"
)
unless
messages
.
count
>
1
message
=
[
"Available commands:"
]
messages
.
each
do
|
messsage
|
message
<<
"-
#{
command
}
#{
message
}
"
end
ephemeral_response
(
message
s
.
join
(
"
\n
"
))
ephemeral_response
(
message
.
join
(
"
\n
"
))
end
def
not_found
...
...
spec/lib/gitlab/chat_commands/command_spec.rb
View file @
1607efa4
require
'spec_helper'
describe
Gitlab
::
ChatCommands
::
Command
,
service:
true
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:params
)
{
{
text:
'issue show 1'
}
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:user
)
{
create
(
:user
)
}
subject
{
described_class
.
new
(
project
,
user
,
params
).
execute
}
describe
'#execute'
do
context
'when the command is not available'
do
context
'when no command is not available'
do
let
(
:params
)
{
{
text:
'issue show 1'
}
}
let
(
:project
)
{
create
(
:project
,
has_external_issue_tracker:
true
)
}
it
'displays the help message'
do
expect
(
subject
[
:response_type
]).
to
be
(
:ephemeral
)
expect
(
subject
[
:text
]).
to
start_with
(
'
Available comma
nd
s
'
)
expect
(
subject
[
:text
]).
to
start_with
(
'
404 not fou
nd'
)
end
end
...
...
@@ -25,5 +25,17 @@
expect
(
subject
[
:text
]).
to
start_with
(
'Available commands'
)
end
end
context
'issue is succesfully created'
do
let
(
:params
)
{
{
text:
"issue create my new issue"
}
}
before
do
project
.
team
<<
[
user
,
:master
]
end
it
'presents the issue'
do
expect
(
subject
[
:text
]).
to
match
(
"my new issue"
)
end
end
end
end
spec/lib/gitlab/chat_commands/issue_create_spec.rb
View file @
1607efa4
...
...
@@ -2,8 +2,8 @@
describe
Gitlab
::
ChatCommands
::
IssueCreate
,
service:
true
do
describe
'#execute'
do
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:regex_match
)
{
described_class
.
match
(
"issue create bird is the word"
)
}
before
do
...
...
@@ -16,12 +16,9 @@
context
'without description'
do
it
'creates the issue'
do
expect
do
subject
# this trigger the execution
end
.
to
change
{
project
.
issues
.
count
}.
by
(
1
)
expect
{
subject
}.
to
change
{
project
.
issues
.
count
}.
by
(
1
)
expect
(
subject
[
:response_type
]).
to
be
:in_channel
expect
(
subject
[
:text
]).
to
match
(
'bird is the word'
)
expect
(
subject
.
title
).
to
eq
(
'bird is the word'
)
end
end
...
...
@@ -29,11 +26,9 @@
let
(
:description
)
{
"Surfin bird"
}
let
(
:regex_match
)
{
described_class
.
match
(
"issue create bird is the word
\n
#{
description
}
"
)
}
before
do
it
'creates the issue with description'
do
subject
end
it
'creates the issue with description'
do
expect
(
Issue
.
last
.
description
).
to
eq
(
description
)
end
end
...
...
spec/lib/gitlab/chat_commands/issue_show_spec.rb
View file @
1607efa4
...
...
@@ -17,17 +17,15 @@
context
'the issue exists'
do
it
'returns the issue'
do
expect
(
subject
[
:response_type
]).
to
be
(
:in_channel
)
expect
(
subject
[
:text
]).
to
match
(
issue
.
title
)
expect
(
subject
.
iid
).
to
be
issue
.
iid
end
end
context
'the issue does not exist'
do
let
(
:regex_match
)
{
described_class
.
match
(
"issue show
1
234"
)
}
let
(
:regex_match
)
{
described_class
.
match
(
"issue show 234
3242
"
)
}
it
"returns nil"
do
expect
(
subject
[
:response_type
]).
to
be
(
:ephemeral
)
expect
(
subject
[
:text
]).
to
start_with
(
'404 not found!'
)
expect
(
subject
).
to
be_nil
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