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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
e0ec69d9
Commit
e0ec69d9
authored
Jan 07, 2016
by
Tomasz Maczukin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change 'trigger_id' to 'token' as resource ID in triggers API
parent
b0a77a22
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
54 deletions
+27
-54
doc/api/triggers.md
doc/api/triggers.md
+4
-8
lib/api/entities.rb
lib/api/entities.rb
+1
-1
lib/api/triggers.rb
lib/api/triggers.rb
+8
-17
spec/requests/api/triggers_spec.rb
spec/requests/api/triggers_spec.rb
+14
-28
No files found.
doc/api/triggers.md
View file @
e0ec69d9
...
...
@@ -17,7 +17,6 @@ Parameters:
{
"created_at"
:
"2015-12-23T16:24:34.716Z"
,
"deleted_at"
:
null
,
"id"
:
1
,
"last_used"
:
"2016-01-04T15:41:21.986Z"
,
"token"
:
"fbdb730c2fbdb095a0862dbd8ab88b"
,
"updated_at"
:
"2015-12-23T16:24:34.716Z"
...
...
@@ -25,7 +24,6 @@ Parameters:
{
"created_at"
:
"2015-12-23T16:25:56.760Z"
,
"deleted_at"
:
null
,
"id"
:
2
,
"last_used"
:
null
,
"token"
:
"7b9148c158980bbd9bcea92c17522d"
,
"updated_at"
:
"2015-12-23T16:25:56.760Z"
...
...
@@ -38,19 +36,18 @@ Parameters:
Get details of trigger of a project
```
GET /projects/:id/triggers/:t
rigger_id
GET /projects/:id/triggers/:t
oken
```
Parameters:
-
`id`
(required) - The ID of a project
-
`t
rigger_id`
(required) - The ID
of a trigger
-
`t
oken`
(required) - The
`token`
of a trigger
```
json
{
"created_at"
:
"2015-12-23T16:25:56.760Z"
,
"deleted_at"
:
null
,
"id"
:
2
,
"last_used"
:
null
,
"token"
:
"7b9148c158980bbd9bcea92c17522d"
,
"updated_at"
:
"2015-12-23T16:25:56.760Z"
...
...
@@ -73,7 +70,6 @@ Parameters:
{
"created_at"
:
"2016-01-07T09:53:58.235Z"
,
"deleted_at"
:
null
,
"id"
:
5
,
"last_used"
:
null
,
"token"
:
"6d056f63e50fe6f8c5f8f4aa10edb7"
,
"updated_at"
:
"2016-01-07T09:53:58.235Z"
...
...
@@ -85,10 +81,10 @@ Parameters:
Remove a trigger of a project
```
DELETE /projects/:id/triggers/:t
rigger_id
DELETE /projects/:id/triggers/:t
oken
```
Parameters:
-
`id`
(required) - The ID of a project
-
`t
rigger_id`
(required) - The ID
of a trigger
-
`t
oken`
(required) - The
`token`
of a trigger
lib/api/entities.rb
View file @
e0ec69d9
...
...
@@ -367,7 +367,7 @@ module API
end
class
Trigger
<
Grape
::
Entity
expose
:
id
,
:
token
,
:created_at
,
:updated_at
,
:deleted_at
expose
:token
,
:created_at
,
:updated_at
,
:deleted_at
expose
:last_used
do
|
repo_obj
,
_options
|
if
repo_obj
.
respond_to?
(
:last_trigger_request
)
request
=
repo_obj
.
last_trigger_request
...
...
lib/api/triggers.rb
View file @
e0ec69d9
...
...
@@ -66,23 +66,14 @@ module API
#
# 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`
# token (required) - The `token` of a trigger
# Example Request:
# GET /projects/:id/triggers/:t
rigger_id
get
':id/triggers/:t
rigger_id
'
do
# GET /projects/:id/triggers/:t
oken
get
':id/triggers/:t
oken
'
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
triggers
=
user_project
.
triggers
.
where
(
token:
params
[
:token
])
return
not_found!
(
'Trigger'
)
if
triggers
.
empty?
present
triggers
.
first
,
with:
Entities
::
Trigger
...
...
@@ -108,14 +99,14 @@ module API
#
# Parameters:
# id (required) - The ID of a project
# t
rigger_id - The ID of trigger to delete
# t
oken (required) - The `token` of a trigger
# Example Request:
# DELETE /projects/:id/triggers/:t
rigger_id
delete
':id/triggers/:t
rigger_id
'
do
# DELETE /projects/:id/triggers/:t
oken
delete
':id/triggers/:t
oken
'
do
authenticate!
authorize_admin_project
trigger
=
user_project
.
triggers
.
where
(
id:
params
[
:trigger_id
].
to_i
).
first
trigger
=
user_project
.
triggers
.
where
(
token:
params
[
:token
]
).
first
return
not_found!
(
'Trigger'
)
unless
trigger
trigger
.
destroy
...
...
spec/requests/api/triggers_spec.rb
View file @
e0ec69d9
...
...
@@ -93,8 +93,7 @@ describe API::API do
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
json_response
).
to
be_a
(
Array
)
expect
(
json_response
[
0
][
'token'
]).
to
eq
(
trigger_token
)
expect
(
json_response
[
1
][
'token'
]).
to
eq
(
trigger_token_2
)
expect
(
json_response
[
0
]).
to
have_key
(
'token'
)
end
end
...
...
@@ -115,30 +114,17 @@ describe API::API do
end
end
describe
'GET /projects/:id/triggers/:t
riggers_id
'
do
describe
'GET /projects/:id/triggers/:t
oken
'
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
)
get
api
(
"/projects/
#{
project
.
id
}
/triggers/
abcdef012345
"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
end
...
...
@@ -146,7 +132,7 @@ describe API::API do
context
'authenticated user with invalid permissions'
do
it
'should not return triggers list'
do
get
api
(
"/projects/
#{
project
.
id
}
/triggers/
#{
trigger
.
id
}
"
,
user2
)
get
api
(
"/projects/
#{
project
.
id
}
/triggers/
#{
trigger
.
token
}
"
,
user2
)
expect
(
response
.
status
).
to
eq
(
403
)
end
...
...
@@ -154,7 +140,7 @@ describe API::API do
context
'unauthentikated user'
do
it
'should not return triggers list'
do
get
api
(
"/projects/
#{
project
.
id
}
/triggers/
#{
trigger
.
id
}
"
)
get
api
(
"/projects/
#{
project
.
id
}
/triggers/
#{
trigger
.
token
}
"
)
expect
(
response
.
status
).
to
eq
(
401
)
end
...
...
@@ -190,17 +176,17 @@ describe API::API do
end
end
describe
'DELETE /projects/:id/triggers/:t
rigger_id
'
do
describe
'DELETE /projects/:id/triggers/:t
oken
'
do
context
'authenticated user with valid permissions'
do
it
'should delete trigger'
do
expect
do
delete
api
(
"/projects/
#{
project
.
id
}
/triggers/
#{
trigger
.
id
}
"
,
user
)
delete
api
(
"/projects/
#{
project
.
id
}
/triggers/
#{
trigger
.
token
}
"
,
user
)
end
.
to
change
{
project
.
triggers
.
count
}.
by
(
-
1
)
expect
(
response
.
status
).
to
eq
(
200
)
end
it
'should responde with 404 Not Found if requesting non-existing trigger'
do
delete
api
(
"/projects/
#{
project
.
id
}
/triggers/
9999
"
,
user
)
delete
api
(
"/projects/
#{
project
.
id
}
/triggers/
abcdef012345
"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
end
...
...
@@ -208,7 +194,7 @@ describe API::API do
context
'authenticated user with invalid permissions'
do
it
'should not delete trigger'
do
delete
api
(
"/projects/
#{
project
.
id
}
/triggers/
#{
trigger
.
id
}
"
,
user2
)
delete
api
(
"/projects/
#{
project
.
id
}
/triggers/
#{
trigger
.
token
}
"
,
user2
)
expect
(
response
.
status
).
to
eq
(
403
)
end
...
...
@@ -216,7 +202,7 @@ describe API::API do
context
'unauthentikated user'
do
it
'should not delete trigger'
do
delete
api
(
"/projects/
#{
project
.
id
}
/triggers/
#{
trigger
.
id
}
"
)
delete
api
(
"/projects/
#{
project
.
id
}
/triggers/
#{
trigger
.
token
}
"
)
expect
(
response
.
status
).
to
eq
(
401
)
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