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
6737ada0
Commit
6737ada0
authored
Nov 17, 2016
by
Z.J. van de Weg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove some commands for now
parent
d4def9cb
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
30 additions
and
200 deletions
+30
-200
changelogs/unreleased/zj-slash-commands-mattermost.yml
changelogs/unreleased/zj-slash-commands-mattermost.yml
+4
-0
lib/gitlab/chat_commands/command.rb
lib/gitlab/chat_commands/command.rb
+0
-4
lib/gitlab/chat_commands/issue_create.rb
lib/gitlab/chat_commands/issue_create.rb
+5
-1
lib/gitlab/chat_commands/issue_search.rb
lib/gitlab/chat_commands/issue_search.rb
+0
-17
lib/gitlab/chat_commands/merge_request_command.rb
lib/gitlab/chat_commands/merge_request_command.rb
+0
-17
lib/gitlab/chat_commands/merge_request_search.rb
lib/gitlab/chat_commands/merge_request_search.rb
+0
-17
lib/gitlab/chat_commands/merge_request_show.rb
lib/gitlab/chat_commands/merge_request_show.rb
+0
-17
lib/mattermost/presenter.rb
lib/mattermost/presenter.rb
+6
-6
spec/lib/gitlab/chat_commands/command_spec.rb
spec/lib/gitlab/chat_commands/command_spec.rb
+15
-5
spec/lib/gitlab/chat_commands/issue_search_spec.rb
spec/lib/gitlab/chat_commands/issue_search_spec.rb
+0
-39
spec/lib/gitlab/chat_commands/merge_request_search_spec.rb
spec/lib/gitlab/chat_commands/merge_request_search_spec.rb
+0
-40
spec/lib/gitlab/chat_commands/merge_request_show_spec.rb
spec/lib/gitlab/chat_commands/merge_request_show_spec.rb
+0
-37
No files found.
changelogs/unreleased/zj-slash-commands-mattermost.yml
0 → 100644
View file @
6737ada0
---
title
:
Add first slash commands
merge_request
:
7438
author
:
lib/gitlab/chat_commands/command.rb
View file @
6737ada0
...
...
@@ -3,11 +3,7 @@ module Gitlab
class
Command
<
BaseCommand
COMMANDS
=
[
Gitlab
::
ChatCommands
::
IssueShow
,
Gitlab
::
ChatCommands
::
IssueSearch
,
Gitlab
::
ChatCommands
::
IssueCreate
,
Gitlab
::
ChatCommands
::
MergeRequestShow
,
Gitlab
::
ChatCommands
::
MergeRequestSearch
,
].
freeze
def
execute
...
...
lib/gitlab/chat_commands/issue_create.rb
View file @
6737ada0
module
Gitlab
module
ChatCommands
class
IssueCreate
<
BaseCommand
class
IssueCreate
<
IssueCommand
def
self
.
match
(
text
)
/\Aissue\s+create\s+(?<title>[^\n]*)\n*(?<description>.*)\z/
.
match
(
text
)
end
def
self
.
help_message
'issue create <title>\n<description>'
end
def
execute
(
match
)
present
nil
unless
can?
(
current_user
,
:create_issue
,
project
)
...
...
lib/gitlab/chat_commands/issue_search.rb
deleted
100644 → 0
View file @
d4def9cb
module
Gitlab
module
ChatCommands
class
IssueSearch
<
IssueCommand
def
self
.
match
(
text
)
/\Aissue\s+search\s+(?<query>.*)\s*/
.
match
(
text
)
end
def
self
.
help_message
"issue search <query>"
end
def
execute
(
match
)
present
search_results
(
match
[
:query
])
end
end
end
end
lib/gitlab/chat_commands/merge_request_command.rb
deleted
100644 → 0
View file @
d4def9cb
module
Gitlab
module
ChatCommands
class
MergeRequestCommand
<
BaseCommand
def
self
.
available?
(
project
)
project
.
merge_requests_enabled?
end
def
collection
project
.
merge_requests
end
def
readable?
(
merge_request
)
can?
(
current_user
,
:read_merge_request
,
merge_request
)
end
end
end
end
lib/gitlab/chat_commands/merge_request_search.rb
deleted
100644 → 0
View file @
d4def9cb
module
Gitlab
module
ChatCommands
class
MergeRequestSearch
<
MergeRequestCommand
def
self
.
match
(
text
)
/\Amergerequest\s+search\s+(?<query>.*)\s*/
.
match
(
text
)
end
def
self
.
help_message
"mergerequest search <query>"
end
def
execute
(
match
)
present
search_results
(
match
[
:query
])
end
end
end
end
lib/gitlab/chat_commands/merge_request_show.rb
deleted
100644 → 0
View file @
d4def9cb
module
Gitlab
module
ChatCommands
class
MergeRequestShow
<
MergeRequestCommand
def
self
.
match
(
text
)
/\Amergerequest\s+show\s+(?<iid>\d+)/
.
match
(
text
)
end
def
self
.
help_message
"mergerequest show <id>"
end
def
execute
(
match
)
present
find_by_iid
(
match
[
:iid
])
end
end
end
end
lib/mattermost/presenter.rb
View file @
6737ada0
module
Mattermost
class
Presenter
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
}
)!"
...
...
@@ -59,7 +61,7 @@ module Mattermost
message
=
"The action was not succesfull because:
\n
"
message
<<
resource
.
errors
.
messages
.
map
{
|
message
|
"-
#{
message
}
"
}.
join
(
"
\n
"
)
ephemeral_response
(
resource
.
errors
.
messages
.
join
(
"
\n
"
)
ephemeral_response
(
resource
.
errors
.
messages
.
join
(
"
\n
"
)
)
end
def
title
(
resource
)
...
...
@@ -67,14 +69,12 @@ module Mattermost
end
def
url
(
resource
)
polymorphic_url
(
url_for
(
[
resource
.
project
.
namespace
.
becomes
(
Namespace
),
resource
.
project
,
resource
],
id:
resource_id
,
routing_type: :url
resource
]
)
end
...
...
spec/lib/gitlab/chat_commands/command_spec.rb
View file @
6737ada0
...
...
@@ -7,12 +7,22 @@ describe Gitlab::ChatCommands::Command, service: true do
subject
{
described_class
.
new
(
project
,
user
,
params
).
execute
}
xdescribe
'#execute'
do
context
'when issue show is triggered'
do
it
'calls IssueShowService'
do
expect_any_instance_of
(
Mattermost
::
Commands
::
IssueShowService
).
to
receive
(
:new
).
with
(
project
,
user
,
params
)
describe
'#execute'
do
context
'when the command is not available'
do
let
(
:project
)
{
create
(
:project
,
has_external_issue_tracker:
true
)
}
subject
it
'displays the help message'
do
expect
(
subject
[
:response_type
]).
to
be
(
:ephemeral
)
expect
(
subject
[
:text
]).
to
start_with
(
'Available commands'
)
end
end
context
'when an unknown command is triggered'
do
let
(
:params
)
{
{
text:
"unknown command 123"
}
}
it
'displays the help message'
do
expect
(
subject
[
:response_type
]).
to
be
(
:ephemeral
)
expect
(
subject
[
:text
]).
to
start_with
(
'Available commands'
)
end
end
end
...
...
spec/lib/gitlab/chat_commands/issue_search_spec.rb
deleted
100644 → 0
View file @
d4def9cb
require
'spec_helper'
describe
Gitlab
::
ChatCommands
::
IssueSearch
,
service:
true
do
describe
'#execute'
do
let!
(
:issue
)
{
create
(
:issue
,
title:
'The bird is the word'
)
}
let
(
:project
)
{
issue
.
project
}
let
(
:user
)
{
issue
.
author
}
let
(
:regex_match
)
{
described_class
.
match
(
"issue search bird is the"
)
}
before
{
project
.
team
<<
[
user
,
:master
]
}
subject
{
described_class
.
new
(
project
,
user
).
execute
(
regex_match
)
}
context
'without results'
do
let
(
:regex_match
)
{
described_class
.
match
(
"issue search no results for this one"
)
}
it
"returns nil"
do
expect
(
subject
[
:response_type
]).
to
be
:ephemeral
expect
(
subject
[
:text
]).
to
start_with
'404 not found!'
end
end
context
'with 1 result'
do
it
'returns the issue'
do
expect
(
subject
[
:response_type
]).
to
be
:in_channel
expect
(
subject
[
:text
]).
to
match
issue
.
title
end
end
context
'with 2 or more results'
do
let!
(
:issue2
)
{
create
(
:issue
,
project:
project
,
title:
'bird is the word!'
)
}
it
'returns multiple resources'
do
expect
(
subject
[
:response_type
]).
to
be
:ephemeral
expect
(
subject
[
:text
]).
to
start_with
'Multiple results were found'
end
end
end
end
spec/lib/gitlab/chat_commands/merge_request_search_spec.rb
deleted
100644 → 0
View file @
d4def9cb
require
'spec_helper'
describe
Gitlab
::
ChatCommands
::
MergeRequestSearch
,
service:
true
do
describe
'#execute'
do
let!
(
:merge_request
)
{
create
(
:merge_request
,
title:
'The bird is the word'
)
}
let
(
:project
)
{
merge_request
.
source_project
}
let
(
:user
)
{
merge_request
.
author
}
let
(
:regex_match
)
{
described_class
.
match
(
"mergerequest search
#{
merge_request
.
title
}
"
)
}
before
do
project
.
team
<<
[
user
,
:master
]
end
subject
do
described_class
.
new
(
project
,
user
).
execute
(
regex_match
)
end
context
'the merge request exists'
do
it
'returns the merge request'
do
expect
(
subject
[
:response_type
]).
to
be
(
:in_channel
)
expect
(
subject
[
:text
]).
to
match
(
merge_request
.
title
)
end
end
context
'no results can be found'
do
let
(
:regex_match
)
{
described_class
.
match
(
"mergerequest search 12334"
)
}
it
"returns a 404 message"
do
expect
(
subject
[
:response_type
]).
to
be
(
:ephemeral
)
expect
(
subject
[
:text
]).
to
start_with
(
'404 not found!'
)
end
end
end
describe
'self.match'
do
it
'matches a valid query'
do
expect
(
described_class
.
match
(
"mergerequest search my title here"
)).
to
be_truthy
end
end
end
spec/lib/gitlab/chat_commands/merge_request_show_spec.rb
deleted
100644 → 0
View file @
d4def9cb
require
'spec_helper'
describe
Gitlab
::
ChatCommands
::
MergeRequestShow
,
service:
true
do
describe
'#execute'
do
let!
(
:merge_request
)
{
create
(
:merge_request
)
}
let
(
:project
)
{
merge_request
.
source_project
}
let
(
:user
)
{
merge_request
.
author
}
let
(
:regex_match
)
{
described_class
.
match
(
"mergerequest show
#{
merge_request
.
iid
}
"
)
}
before
{
project
.
team
<<
[
user
,
:master
]
}
subject
{
described_class
.
new
(
project
,
user
).
execute
(
regex_match
)
}
context
'the merge request exists'
do
it
'returns the merge request'
do
expect
(
subject
[
:response_type
]).
to
be
:in_channel
expect
(
subject
[
:text
]).
to
match
merge_request
.
title
end
end
context
'the merge request does not exist'
do
let
(
:regex_match
)
{
described_class
.
match
(
"mergerequest show 12345"
)
}
it
"returns nil"
do
expect
(
subject
[
:response_type
]).
to
be
:ephemeral
expect
(
subject
[
:text
]).
to
start_with
'404 not found!'
end
end
end
describe
"self.match"
do
it
'matches valid strings'
do
expect
(
described_class
.
match
(
"mergerequest show 123"
)).
to
be_truthy
expect
(
described_class
.
match
(
"mergerequest show sdf23"
)).
to
be_falsy
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