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
86756646
Commit
86756646
authored
Jan 05, 2016
by
Tomasz Maczukin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Get show details feature to triggers API
parent
49c8bf4e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
77 additions
and
5 deletions
+77
-5
lib/api/triggers.rb
lib/api/triggers.rb
+26
-0
spec/requests/api/triggers_spec.rb
spec/requests/api/triggers_spec.rb
+51
-5
No files found.
lib/api/triggers.rb
View file @
86756646
...
...
@@ -62,6 +62,32 @@ module API
present
triggers
,
with:
Entities
::
Trigger
end
# Get specific trigger of a project
#
# Parameters:
# id (required) - The ID of a project
# trigger_id (required) - The ID or `token` of a trigger to show; if trigger_id contains only digits it's
# treated as ID other ways it's reated as `key`
# Example Request:
# GET /projects/:id/triggers/:trigger_id
get
':id/triggers/:trigger_id'
do
authenticate!
authorize_admin_project
trigger_id
=
params
[
:trigger_id
]
triggers
=
user_project
.
triggers
triggers
=
if
trigger_id
.
match
(
/^\d+$/
)
triggers
.
where
(
id:
trigger_id
.
to_i
)
else
triggers
.
where
(
token:
trigger_id
)
end
return
not_found!
(
'Trigger'
)
if
triggers
.
empty?
present
triggers
.
first
,
with:
Entities
::
Trigger
end
# Create trigger
#
# Parameters:
...
...
spec/requests/api/triggers_spec.rb
View file @
86756646
...
...
@@ -5,8 +5,8 @@ describe API::API do
let
(
:user
)
{
create
(
:user
)
}
let
(
:user2
)
{
create
(
:user
)
}
let!
(
:trigger_token
)
{
'secure
token'
}
let!
(
:trigger_token_2
)
{
'secure
token
2'
}
let!
(
:trigger_token
)
{
'secure
_
token'
}
let!
(
:trigger_token_2
)
{
'secure
_token_
2'
}
let!
(
:project
)
{
create
(
:project
,
creator_id:
user
.
id
)
}
let!
(
:master
)
{
create
(
:project_member
,
user:
user
,
project:
project
,
access_level:
ProjectMember
::
MASTER
)
}
let!
(
:developer
)
{
create
(
:project_member
,
user:
user2
,
project:
project
,
access_level:
ProjectMember
::
DEVELOPER
)
}
...
...
@@ -86,7 +86,7 @@ describe API::API do
end
end
describe
'GET /projects/:id/trigge
t
s'
do
describe
'GET /projects/:id/trigge
r
s'
do
context
'authenticated user with valid permissions'
do
it
'should return list of triggers'
do
get
api
(
"/projects/
#{
project
.
id
}
/triggers"
,
user
)
...
...
@@ -115,7 +115,53 @@ describe API::API do
end
end
describe
'POST /projects/:id/triggets'
do
describe
'GET /projects/:id/triggers/:triggers_id'
do
context
'authenticated user with valid permissions'
do
context
'ID is used as :trigger_id'
do
it
'should return trigger details'
do
get
api
(
"/projects/
#{
project
.
id
}
/triggers/
#{
trigger
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
json_response
).
to
be_a
(
Hash
)
expect
(
json_response
[
'token'
]).
to
eq
(
trigger_token
)
end
end
context
'`token` is used as :trigger_id'
do
it
'should return trigger details'
do
get
api
(
"/projects/
#{
project
.
id
}
/triggers/
#{
trigger
.
token
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
json_response
).
to
be_a
(
Hash
)
expect
(
json_response
[
'id'
]).
to
eq
(
trigger
.
id
)
end
end
it
'should responde with 404 Not Found if requesting non-existing trigger'
do
get
api
(
"/projects/
#{
project
.
id
}
/triggers/9999"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
end
end
context
'authenticated user with invalid permissions'
do
it
'should not return triggers list'
do
get
api
(
"/projects/
#{
project
.
id
}
/triggers/
#{
trigger
.
id
}
"
,
user2
)
expect
(
response
.
status
).
to
eq
(
403
)
end
end
context
'unauthentikated user'
do
it
'should not return triggers list'
do
get
api
(
"/projects/
#{
project
.
id
}
/triggers/
#{
trigger
.
id
}
"
)
expect
(
response
.
status
).
to
eq
(
401
)
end
end
end
describe
'POST /projects/:id/triggers'
do
context
'authenticated user with valid permissions'
do
it
'should create trigger'
do
expect
do
...
...
@@ -144,7 +190,7 @@ describe API::API do
end
end
describe
'DELETE /projects/:id/trigge
t
s/:trigger_id'
do
describe
'DELETE /projects/:id/trigge
r
s/:trigger_id'
do
context
'authenticated user with valid permissions'
do
it
'should delete trigger'
do
expect
do
...
...
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