Открыть боковую панель
nt_test121
nt_project_9da4a5yt9x4b
Коммиты
dda6719b
Коммит
dda6719b
создал
Сен 13, 2016
по автору
Connor Shea
Просмотр файлов
Convert triggers.rb, this has a lot of failing tests, not entirely sure why.
владелец
960d1752
Изменения
2
Скрыть пробелы
Построчно
Рядом
lib/api/triggers.rb
Просмотр файла @
dda6719b
...
...
@@ -2,18 +2,19 @@ module API
# Triggers API
class
Triggers
<
Grape
::
API
resource
:projects
do
# Trigger a GitLab 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
# variables (optional) - The list of variables to be injected into build
# Example Request:
# POST /projects/:id/trigger/builds
desc
'Trigger a GitLab 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:
'The list of variables to be injected into build'
do
requires
:key
,
type:
String
requires
:value
,
type:
String
end
end
post
":id/trigger/builds"
do
required_attributes!
[
:ref
,
:token
]
project
=
Project
.
find_with_namespace
(
params
[
:id
])
||
Project
.
find_by
(
id:
params
[
:id
])
trigger
=
Ci
::
Trigger
.
find_by_token
(
params
[
:token
].
to_s
)
not_found!
unless
project
&&
trigger
...
...
@@ -22,14 +23,6 @@ class Triggers < Grape::API
# 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
end
...
...
@@ -44,14 +37,14 @@ class Triggers < Grape::API
end
end
#
Get triggers list
#
# Parameters:
# 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
desc
'
Get triggers list
'
do
success
Entities
::
Trigger
end
params
do
requires
:id
,
type:
Integer
,
desc:
'The ID of a project'
optional
:page
,
type:
Integer
,
desc:
'The page number for pagination'
optional
:per_page
,
type:
Integer
,
desc:
'The value of items per page to show'
end
get
':id/triggers'
do
authenticate!
authorize!
:admin_build
,
user_project
...
...
@@ -62,13 +55,13 @@ class Triggers < Grape::API
present
triggers
,
with:
Entities
::
Trigger
end
#
Get specific trigger of a project
#
# Parameters:
# id (required) - The ID of a project
#
token (required) - The `token` of a trigger
# Example Request:
# GET /projects/:id/triggers/:tok
en
desc
'
Get specific trigger of a project
'
do
success
Entities
::
Trigger
end
params
do
requires
:id
,
type:
Integer
,
desc:
'The ID of a project'
requires
:token
,
type:
String
,
desc:
'The token of a trigger'
en
d
get
':id/triggers/:token'
do
authenticate!
authorize!
:admin_build
,
user_project
...
...
@@ -79,12 +72,12 @@ class Triggers < Grape::API
present
trigger
,
with:
Entities
::
Trigger
end
#
Create trigger
#
# Parameters:
# id (required) - The ID of a project
# Example Request:
# POST /projects/:id/triggers
desc
'
Create trigger
'
do
success
Entities
::
Trigger
end
params
do
requires
:id
,
type:
Integer
,
desc:
'The ID of a project'
end
post
':id/triggers'
do
authenticate!
authorize!
:admin_build
,
user_project
...
...
@@ -94,13 +87,13 @@ class Triggers < Grape::API
present
trigger
,
with:
Entities
::
Trigger
end
#
Delete trigger
#
# Parameters:
# id (required) - The ID of a project
#
token (required) - The `token` of a trigger
# Example Request:
# DELETE /projects/:id/triggers/:tok
en
desc
'
Delete trigger
'
do
success
Entities
::
Trigger
end
params
do
requires
:id
,
type:
Integer
,
desc:
'The ID of a project'
requires
:token
,
type:
String
,
desc:
'The token of a trigger'
en
d
delete
':id/triggers/:token'
do
authenticate!
authorize!
:admin_build
,
user_project
...
...
spec/requests/api/triggers_spec.rb
Просмотр файла @
dda6719b
...
...
@@ -68,13 +68,13 @@
it
'validates variables to be a hash'
do
post
api
(
"/projects/
#{
project
.
id
}
/trigger/builds"
),
options
.
merge
(
variables:
'value'
,
ref:
'master'
)
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'
message'
]).
to
eq
(
'variables needs to be a hash
'
)
expect
(
json_response
[
'
error'
]).
to
include
(
'variables is invalid
'
)
end
it
'validates variables needs to be a map of key-valued strings'
do
post
api
(
"/projects/
#{
project
.
id
}
/trigger/builds"
),
options
.
merge
(
variables:
{
key:
%w(1 2)
},
ref:
'master'
)
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'
message'
]).
to
eq
(
'variables needs to be a map of key-valued str
ing
s
'
)
expect
(
json_response
[
'
error'
]).
to
include
(
'variables[value] is miss
ing'
)
end
it
'creates trigger request with variables'
do
...
...
Редактирование
Предварительный просмотр
Поддерживает Markdown
0%
Попробовать снова
или
прикрепить новый файл
.
Отмена
You are about to add
0
people
to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Отмена
Пожалуйста,
зарегистрируйтесь
или
войдите
чтобы прокомментировать