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
Jérome Perrin
gitlab-ce
Commits
2965883e
Commit
2965883e
authored
Nov 09, 2016
by
Robert Schilling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Grapify token API
parent
0c99e5d0
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
47 deletions
+31
-47
lib/api/triggers.rb
lib/api/triggers.rb
+30
-46
spec/requests/api/triggers_spec.rb
spec/requests/api/triggers_spec.rb
+1
-1
No files found.
lib/api/triggers.rb
View file @
2965883e
module
API
module
API
# Triggers API
class
Triggers
<
Grape
::
API
class
Triggers
<
Grape
::
API
params
do
requires
:id
,
type:
String
,
desc:
'The ID of a project'
end
resource
:projects
do
resource
:projects
do
# Trigger a GitLab project build
desc
'Trigger a GitLab project build'
do
#
success
Entities
::
TriggerRequest
# Parameters:
end
# id (required) - The ID of a CI project
params
do
# ref (required) - The name of project's branch or tag
requires
:ref
,
type:
String
,
desc:
'The commit sha or name of a branch or tag'
# token (required) - The uniq token of trigger
requires
:token
,
type:
String
,
desc:
'The unique token of trigger'
# variables (optional) - The list of variables to be injected into build
optional
:variables
,
type:
Hash
,
desc:
'The list of variables to be injected into build'
# Example Request:
end
# POST /projects/:id/trigger/builds
post
":id/trigger/builds"
do
post
":id/trigger/builds"
do
required_attributes!
[
:ref
,
:token
]
project
=
Project
.
find_with_namespace
(
params
[
:id
])
||
Project
.
find_by
(
id:
params
[
:id
])
project
=
Project
.
find_with_namespace
(
params
[
:id
])
||
Project
.
find_by
(
id:
params
[
:id
])
trigger
=
Ci
::
Trigger
.
find_by_token
(
params
[
:token
].
to_s
)
trigger
=
Ci
::
Trigger
.
find_by_token
(
params
[
:token
].
to_s
)
not_found!
unless
project
&&
trigger
not_found!
unless
project
&&
trigger
...
@@ -22,10 +21,6 @@ module API
...
@@ -22,10 +21,6 @@ module API
# validate variables
# validate variables
variables
=
params
[
:variables
]
variables
=
params
[
:variables
]
if
variables
if
variables
unless
variables
.
is_a?
(
Hash
)
render_api_error!
(
'variables needs to be a hash'
,
400
)
end
unless
variables
.
all?
{
|
key
,
value
|
key
.
is_a?
(
String
)
&&
value
.
is_a?
(
String
)
}
unless
variables
.
all?
{
|
key
,
value
|
key
.
is_a?
(
String
)
&&
value
.
is_a?
(
String
)
}
render_api_error!
(
'variables needs to be a map of key-valued strings'
,
400
)
render_api_error!
(
'variables needs to be a map of key-valued strings'
,
400
)
end
end
...
@@ -44,31 +39,24 @@ module API
...
@@ -44,31 +39,24 @@ module API
end
end
end
end
# Get triggers list
desc
'Get triggers list'
do
#
success
Entities
::
Trigger
# Parameters:
end
# id (required) - The ID of a project
# page (optional) - The page number for pagination
# per_page (optional) - The value of items per page to show
# Example Request:
# GET /projects/:id/triggers
get
':id/triggers'
do
get
':id/triggers'
do
authenticate!
authenticate!
authorize!
:admin_build
,
user_project
authorize!
:admin_build
,
user_project
triggers
=
user_project
.
triggers
.
includes
(
:trigger_requests
)
triggers
=
user_project
.
triggers
.
includes
(
:trigger_requests
)
triggers
=
paginate
(
triggers
)
present
triggers
,
with:
Entities
::
Trigger
present
paginate
(
triggers
)
,
with:
Entities
::
Trigger
end
end
# Get specific trigger of a project
desc
'Get specific trigger of a project'
do
#
success
Entities
::
Trigger
# Parameters:
end
# id (required) - The ID of a project
params
do
# token (required) - The `token` of a trigger
requires
:token
,
type:
String
,
desc:
'The unique token of trigger'
# Example Request:
end
# GET /projects/:id/triggers/:token
get
':id/triggers/:token'
do
get
':id/triggers/:token'
do
authenticate!
authenticate!
authorize!
:admin_build
,
user_project
authorize!
:admin_build
,
user_project
...
@@ -79,12 +67,9 @@ module API
...
@@ -79,12 +67,9 @@ module API
present
trigger
,
with:
Entities
::
Trigger
present
trigger
,
with:
Entities
::
Trigger
end
end
# Create trigger
desc
'Create a trigger'
do
#
success
Entities
::
Trigger
# Parameters:
end
# id (required) - The ID of a project
# Example Request:
# POST /projects/:id/triggers
post
':id/triggers'
do
post
':id/triggers'
do
authenticate!
authenticate!
authorize!
:admin_build
,
user_project
authorize!
:admin_build
,
user_project
...
@@ -94,13 +79,12 @@ module API
...
@@ -94,13 +79,12 @@ module API
present
trigger
,
with:
Entities
::
Trigger
present
trigger
,
with:
Entities
::
Trigger
end
end
# Delete trigger
desc
'Delete a trigger'
do
#
success
Entities
::
Trigger
# Parameters:
end
# id (required) - The ID of a project
params
do
# token (required) - The `token` of a trigger
requires
:token
,
type:
String
,
desc:
'The unique token of trigger'
# Example Request:
end
# DELETE /projects/:id/triggers/:token
delete
':id/triggers/:token'
do
delete
':id/triggers/:token'
do
authenticate!
authenticate!
authorize!
:admin_build
,
user_project
authorize!
:admin_build
,
user_project
...
...
spec/requests/api/triggers_spec.rb
View file @
2965883e
...
@@ -68,7 +68,7 @@ describe API::API do
...
@@ -68,7 +68,7 @@ describe API::API do
it
'validates variables to be a hash'
do
it
'validates variables to be a hash'
do
post
api
(
"/projects/
#{
project
.
id
}
/trigger/builds"
),
options
.
merge
(
variables:
'value'
,
ref:
'master'
)
post
api
(
"/projects/
#{
project
.
id
}
/trigger/builds"
),
options
.
merge
(
variables:
'value'
,
ref:
'master'
)
expect
(
response
).
to
have_http_status
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'
message'
]).
to
eq
(
'variables needs to be a hash
'
)
expect
(
json_response
[
'
error'
]).
to
eq
(
'variables is invalid
'
)
end
end
it
'validates variables needs to be a map of key-valued strings'
do
it
'validates variables needs to be a map of key-valued strings'
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