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
Boxiang Sun
gitlab-ce
Commits
9aaf38d6
Commit
9aaf38d6
authored
Feb 22, 2017
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'grapify-ci-triggers-api' into 'master'
Grapfiy the CI::Triggers API See merge request !9439
parents
7813cedd
b8c88a83
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
28 deletions
+18
-28
lib/ci/api/triggers.rb
lib/ci/api/triggers.rb
+16
-27
spec/requests/ci/api/triggers_spec.rb
spec/requests/ci/api/triggers_spec.rb
+2
-1
No files found.
lib/ci/api/triggers.rb
View file @
9aaf38d6
module
Ci
module
API
# Build Trigger API
class
Triggers
<
Grape
::
API
resource
:projects
do
# Trigger a GitLab CI project build
#
# Parameters:
# id (required) - The ID of a CI project
# ref (required) - The name of project's branch or tag
# token (required) - The uniq token of trigger
# Example Request:
# POST /projects/:id/ref/:ref/trigger
desc
'Trigger a GitLab CI project build'
do
success
Entities
::
TriggerRequest
end
params
do
requires
:id
,
type:
Integer
,
desc:
'The ID of a CI project'
requires
:ref
,
type:
String
,
desc:
"The name of project's branch or tag"
requires
:token
,
type:
String
,
desc:
'The unique token of the trigger'
optional
:variables
,
type:
Hash
,
desc:
'Optional build variables'
end
post
":id/refs/:ref/trigger"
do
required_attributes!
[
:token
]
project
=
Project
.
find_by
(
ci_id:
params
[
:id
].
to_i
)
trigger
=
Ci
::
Trigger
.
find_by_token
(
params
[
:token
].
to_s
)
project
=
Project
.
find_by
(
ci_id:
params
[
:id
])
trigger
=
Ci
::
Trigger
.
find_by_token
(
params
[
:token
])
not_found!
unless
project
&&
trigger
unauthorized!
unless
trigger
.
project
==
project
# validate variables
variables
=
params
[
: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
)
}
render_api_error!
(
'variables needs to be a map of key-valued strings'
,
400
)
end
# convert variables from Mash to Hash
variables
=
variables
.
to_h
# Validate variables
variables
=
params
[
:variables
].
to_h
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
)
end
# create request and trigger builds
trigger_request
=
Ci
::
CreateTriggerRequestService
.
new
.
execute
(
project
,
trigger
,
params
[
:ref
]
.
to_s
,
variables
)
trigger_request
=
Ci
::
CreateTriggerRequestService
.
new
.
execute
(
project
,
trigger
,
params
[
:ref
],
variables
)
if
trigger_request
present
trigger_request
,
with:
Entities
::
TriggerRequest
else
...
...
spec/requests/ci/api/triggers_spec.rb
View file @
9aaf38d6
...
...
@@ -60,7 +60,8 @@ describe Ci::API::Triggers do
it
'validates variables to be a hash'
do
post
ci_api
(
"/projects/
#{
project
.
ci_id
}
/refs/master/trigger"
),
options
.
merge
(
variables:
'value'
)
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
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