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
dfca704d
Commit
dfca704d
authored
Dec 29, 2016
by
Z.J. van de Weg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add API route slack slash commands
parent
365612ce
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
36 deletions
+64
-36
lib/api/services.rb
lib/api/services.rb
+7
-0
spec/requests/api/services_spec.rb
spec/requests/api/services_spec.rb
+57
-36
No files found.
lib/api/services.rb
View file @
dfca704d
...
@@ -543,6 +543,13 @@ module API
...
@@ -543,6 +543,13 @@ module API
type:
String
,
type:
String
,
desc:
'The Mattermost token'
desc:
'The Mattermost token'
}
}
],
'slack-slash-commands'
=>
[
{
name: :token
,
type:
String
,
desc:
'The Slack token'
}
]
]
}.
freeze
}.
freeze
...
...
spec/requests/api/services_spec.rb
View file @
dfca704d
...
@@ -6,7 +6,7 @@ describe API::Services, api: true do
...
@@ -6,7 +6,7 @@ describe API::Services, api: true do
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:admin
)
{
create
(
:admin
)
}
let
(
:admin
)
{
create
(
:admin
)
}
let
(
:user2
)
{
create
(
:user
)
}
let
(
:user2
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
,
creator_id:
user
.
id
,
namespace:
user
.
namespace
)
}
let
(
:project
)
{
create
(
:
empty_
project
,
creator_id:
user
.
id
,
namespace:
user
.
namespace
)
}
Service
.
available_services_names
.
each
do
|
service
|
Service
.
available_services_names
.
each
do
|
service
|
describe
"PUT /projects/:id/services/
#{
service
.
dasherize
}
"
do
describe
"PUT /projects/:id/services/
#{
service
.
dasherize
}
"
do
...
@@ -92,57 +92,78 @@ describe API::Services, api: true do
...
@@ -92,57 +92,78 @@ describe API::Services, api: true do
describe
'POST /projects/:id/services/:slug/trigger'
do
describe
'POST /projects/:id/services/:slug/trigger'
do
let!
(
:project
)
{
create
(
:empty_project
)
}
let!
(
:project
)
{
create
(
:empty_project
)
}
let
(
:service_name
)
{
'mattermost_slash_commands'
}
context
'no service is available'
do
describe
'Mattermost Service'
do
it
'returns a not found message'
do
let
(
:service_name
)
{
'mattermost_slash_commands'
}
post
api
(
"/projects/
#{
project
.
id
}
/services/idonotexist/trigger"
)
expect
(
response
).
to
have_http_status
(
404
)
context
'no service is available'
do
expect
(
json_response
[
"error"
]).
to
eq
(
"404 Not Found"
)
it
'returns a not found message'
do
post
api
(
"/projects/
#{
project
.
id
}
/services/idonotexist/trigger"
)
expect
(
response
).
to
have_http_status
(
404
)
expect
(
json_response
[
"error"
]).
to
eq
(
"404 Not Found"
)
end
end
end
end
context
'the service exists'
do
context
'the service exists'
do
let
(
:params
)
{
{
token:
'token'
}
}
let
(
:params
)
{
{
token:
'token'
}
}
context
'the service is not active'
do
context
'the service is not active'
do
let!
(
:inactive_service
)
do
before
do
project
.
create_mattermost_slash_commands_service
(
project
.
create_mattermost_slash_commands_service
(
active:
false
,
active:
false
,
properties:
{
token:
'token'
}
properties:
params
)
)
end
end
it
'when the service is inactive'
do
it
'when the service is inactive'
do
post
api
(
"/projects/
#{
project
.
id
}
/services/mattermost_slash_commands
/trigger"
),
params
post
api
(
"/projects/
#{
project
.
id
}
/services/
#{
service_name
}
/trigger"
),
params
expect
(
response
).
to
have_http_status
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
end
context
'the service is active'
do
context
'the service is active'
do
let!
(
:active_service
)
do
before
do
project
.
create_mattermost_slash_commands_service
(
project
.
create_mattermost_slash_commands_service
(
active:
true
,
active:
true
,
properties:
{
token:
'token'
}
properties:
params
)
)
end
it
'returns status 200'
do
post
api
(
"/projects/
#{
project
.
id
}
/services/
#{
service_name
}
/trigger"
),
params
expect
(
response
).
to
have_http_status
(
200
)
end
end
end
it
'returns status 200'
do
context
'when the project can not be found'
do
post
api
(
"/projects/
#{
project
.
id
}
/services/mattermost_slash_commands/trigger"
),
params
it
'returns a generic 404'
do
post
api
(
"/projects/404/services/
#{
service_name
}
/trigger"
),
params
expect
(
response
).
to
have_http_status
(
200
)
expect
(
response
).
to
have_http_status
(
404
)
expect
(
json_response
[
"message"
]).
to
eq
(
"404 Service Not Found"
)
end
end
end
end
end
end
context
'when the project can not be found'
do
describe
'Slack Service'
do
it
'returns a generic 404'
do
let
(
:service_name
)
{
'slack_slash_commands'
}
post
api
(
"/projects/404/services/mattermost_slash_commands/trigger"
),
params
expect
(
response
).
to
have_http_status
(
404
)
before
do
expect
(
json_response
[
"message"
]).
to
eq
(
"404 Service Not Found"
)
project
.
create_slack_slash_commands_service
(
end
active:
true
,
properties:
{
token:
'token'
}
)
end
it
'returns status 200'
do
post
api
(
"/projects/
#{
project
.
id
}
/services/
#{
service_name
}
/trigger"
),
token:
'token'
,
text:
'help'
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'response_type'
]).
to
eq
(
"ephemeral"
)
end
end
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