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
Léo-Paul Géneau
gitlab-ce
Commits
3d6f18ce
Commit
3d6f18ce
authored
Oct 12, 2016
by
Z.J. van de Weg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
GrapeDSL for variables
parent
5aa7b13c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
47 deletions
+42
-47
lib/api/variables.rb
lib/api/variables.rb
+42
-47
No files found.
lib/api/variables.rb
View file @
3d6f18ce
...
@@ -4,27 +4,29 @@ module API
...
@@ -4,27 +4,29 @@ module API
before
{
authenticate!
}
before
{
authenticate!
}
before
{
authorize!
:admin_build
,
user_project
}
before
{
authorize!
:admin_build
,
user_project
}
params
do
requires
:id
,
type:
String
,
desc:
'The ID of a project'
end
resource
:projects
do
resource
:projects
do
# Get project variables
desc
'Get project variables'
do
#
success
Entities
::
Variable
# Parameters:
end
# id (required) - The ID of a project
params
do
# page (optional) - The page number for pagination
optional
:page
,
type:
Integer
,
desc:
'The page number for pagination'
# per_page (optional) - The value of items per page to show
optional
:per_page
,
type:
Integer
,
desc:
'The value of items per page to show'
# Example Request:
end
# GET /projects/:id/variables
get
':id/variables'
do
get
':id/variables'
do
variables
=
user_project
.
variables
variables
=
user_project
.
variables
present
paginate
(
variables
),
with:
Entities
::
Variable
present
paginate
(
variables
),
with:
Entities
::
Variable
end
end
# Get specific variable of a project
desc
'Get a specific variable from a project'
do
#
success
Entities
::
Variable
# Parameters:
end
# id (required) - The ID of a project
params
do
# key (required) - The `key` of variable
requires
:key
,
type:
String
,
desc:
'The key of the variable'
# Example Request:
end
# GET /projects/:id/variables/:key
get
':id/variables/:key'
do
get
':id/variables/:key'
do
key
=
params
[
:key
]
key
=
params
[
:key
]
variable
=
user_project
.
variables
.
find_by
(
key:
key
.
to_s
)
variable
=
user_project
.
variables
.
find_by
(
key:
key
.
to_s
)
...
@@ -34,18 +36,15 @@ module API
...
@@ -34,18 +36,15 @@ module API
present
variable
,
with:
Entities
::
Variable
present
variable
,
with:
Entities
::
Variable
end
end
# Create a new variable in project
desc
'Create a new variable in a project'
do
#
success
Entities
::
Variable
# Parameters:
end
# id (required) - The ID of a project
params
do
# key (required) - The key of variable
requires
:key
,
type:
String
,
desc:
'The key of the variable'
# value (required) - The value of variable
requires
:value
,
type:
String
,
desc:
'The value of the variable'
# Example Request:
end
# POST /projects/:id/variables
post
':id/variables'
do
post
':id/variables'
do
required_attributes!
[
:key
,
:value
]
variable
=
user_project
.
variables
.
create
(
declared
(
params
,
include_parent_namespaces:
false
).
to_h
)
variable
=
user_project
.
variables
.
create
(
key:
params
[
:key
],
value:
params
[
:value
])
if
variable
.
valid?
if
variable
.
valid?
present
variable
,
with:
Entities
::
Variable
present
variable
,
with:
Entities
::
Variable
...
@@ -54,41 +53,37 @@ module API
...
@@ -54,41 +53,37 @@ module API
end
end
end
end
# Update existing variable of a project
desc
'Update an existing variable from a project'
do
#
success
Entities
::
Variable
# Parameters:
end
# id (required) - The ID of a project
params
do
# key (optional) - The `key` of variable
optional
:key
,
type:
String
,
desc:
'The key of the variable'
# value (optional) - New value for `value` field of variable
optional
:value
,
type:
String
,
desc:
'The value of the variable'
# Example Request:
end
# PUT /projects/:id/variables/:key
put
':id/variables/:key'
do
put
':id/variables/:key'
do
variable
=
user_project
.
variables
.
find_by
(
key:
params
[
:key
]
.
to_s
)
variable
=
user_project
.
variables
.
find_by
(
key:
params
[
:key
])
return
not_found!
(
'Variable'
)
unless
variable
return
not_found!
(
'Variable'
)
unless
variable
attrs
=
attributes_for_keys
[
:value
]
if
variable
.
update
(
value:
params
[
:value
])
if
variable
.
update
(
attrs
)
present
variable
,
with:
Entities
::
Variable
present
variable
,
with:
Entities
::
Variable
else
else
render_validation_error!
(
variable
)
render_validation_error!
(
variable
)
end
end
end
end
# Delete existing variable of a project
desc
'Delete an existing variable from a project'
do
#
success
Entities
::
Variable
# Parameters:
end
# id (required) - The ID of a project
params
do
# key (required) - The ID of a variable
requires
:key
,
type:
String
,
desc:
'The key of the variable'
# Example Request:
end
# DELETE /projects/:id/variables/:key
delete
':id/variables/:key'
do
delete
':id/variables/:key'
do
variable
=
user_project
.
variables
.
find_by
(
key:
params
[
:key
]
.
to_s
)
variable
=
user_project
.
variables
.
find_by
(
key:
params
[
:key
])
return
not_found!
(
'Variable'
)
unless
variable
return
not_found!
(
'Variable'
)
unless
variable
variable
.
destroy
present
variable
,
with:
Entities
::
Variable
present
variable
.
destroy
,
with:
Entities
::
Variable
end
end
end
end
end
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