Skip to content
GitLab
Next
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
Primary navigation
Search or go to…
Project
GitLab FOSS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Privacy statement
Keyboard shortcuts
?
What's new
4
Snippets
Groups
Projects
Show more breadcrumbs
GitLab.org
GitLab FOSS
Commits
dfca704d
There was a problem fetching the pipeline summary.
Commit
dfca704d
authored
8 years ago
by
Z.J. van de Weg
Browse files
Options
Downloads
Patches
Plain Diff
Add API route slack slash commands
parent
365612ce
No related branches found
No related tags found
1 merge request
!8362
Add API route slack slash commands
Pipeline
#
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/api/services.rb
+7
-0
7 additions, 0 deletions
lib/api/services.rb
spec/requests/api/services_spec.rb
+57
-36
57 additions, 36 deletions
spec/requests/api/services_spec.rb
with
64 additions
and
36 deletions
lib/api/services.rb
+
7
−
0
View file @
dfca704d
...
...
@@ -543,6 +543,13 @@ class Services < Grape::API
type:
String
,
desc:
'The Mattermost token'
}
],
'slack-slash-commands'
=>
[
{
name: :token
,
type:
String
,
desc:
'The Slack token'
}
]
}.
freeze
...
...
This diff is collapsed.
Click to expand it.
spec/requests/api/services_spec.rb
+
57
−
36
View file @
dfca704d
...
...
@@ -6,7 +6,7 @@
let
(
:user
)
{
create
(
:user
)
}
let
(
:admin
)
{
create
(
:admin
)
}
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
|
describe
"PUT /projects/:id/services/
#{
service
.
dasherize
}
"
do
...
...
@@ -92,57 +92,78 @@
describe
'POST /projects/:id/services/:slug/trigger'
do
let!
(
:project
)
{
create
(
:empty_project
)
}
let
(
:service_name
)
{
'mattermost_slash_commands'
}
context
'no service is available'
do
it
'returns a not found message'
do
post
api
(
"/projects/
#{
project
.
id
}
/services/idonotexist/trigger"
)
describe
'Mattermost Service'
do
let
(
:service_name
)
{
'mattermost_slash_commands'
}
expect
(
response
).
to
have_http_status
(
404
)
expect
(
json_response
[
"error"
]).
to
eq
(
"404 Not Found"
)
context
'no service is available'
do
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
context
'the service exists'
do
let
(
:params
)
{
{
token:
'token'
}
}
context
'the service exists'
do
let
(
:params
)
{
{
token:
'token'
}
}
context
'the service is not active'
do
let!
(
:inactive_service
)
do
project
.
create_mattermost_slash_commands_service
(
active:
false
,
properties:
{
token:
'token'
}
)
end
context
'the service is not active'
do
before
do
project
.
create_mattermost_slash_commands_service
(
active:
false
,
properties:
params
)
end
it
'when the service is inactive'
do
post
api
(
"/projects/
#{
project
.
id
}
/services/
mattermost_slash_commands
/trigger"
),
params
it
'when the service is inactive'
do
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
context
'the service is active'
do
let!
(
:active_service
)
do
project
.
create_mattermost_slash_commands_service
(
active:
true
,
properties:
{
token:
'token'
}
)
context
'the service is active'
do
before
do
project
.
create_mattermost_slash_commands_service
(
active:
true
,
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
it
'returns status 200'
do
post
api
(
"/projects/
#{
project
.
id
}
/services/mattermost_slash_commands/trigger"
),
params
context
'when the project can not be found'
do
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
context
'when the project can not be found'
do
it
'returns a generic 404'
do
post
api
(
"/projects/404/services/mattermost_slash_commands/trigger"
),
params
describe
'Slack Service'
do
let
(
:service_name
)
{
'slack_slash_commands'
}
expect
(
response
).
to
have_http_status
(
404
)
expect
(
json_response
[
"message"
]).
to
eq
(
"404 Service Not Found"
)
end
before
do
project
.
create_slack_slash_commands_service
(
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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment