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
ec66f1b5
Commit
ec66f1b5
authored
Jun 24, 2019
by
Lee Tickett
Committed by
Kamil Trzciński
Jun 24, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add name & search parameters to project environments API
parent
cf137da3
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
84 additions
and
2 deletions
+84
-2
app/finders/environments_finder.rb
app/finders/environments_finder.rb
+29
-0
changelogs/add-name-parameter-to-project-environments-api.yml
...gelogs/add-name-parameter-to-project-environments-api.yml
+5
-0
doc/api/environments.md
doc/api/environments.md
+3
-1
lib/api/environments.rb
lib/api/environments.rb
+6
-1
spec/requests/api/environments_spec.rb
spec/requests/api/environments_spec.rb
+41
-0
No files found.
app/finders/environments_finder.rb
View file @
ec66f1b5
...
...
@@ -47,6 +47,19 @@ class EnvironmentsFinder
end
# rubocop: enable CodeReuse/ActiveRecord
# This method will eventually take the place of `#execute` as an
# efficient way to get relevant environment entries.
# Currently, `#execute` method has a serious technical debt and
# we will likely rework on it in the future.
# See more https://gitlab.com/gitlab-org/gitlab-ce/issues/63381
def
find
environments
=
project
.
environments
environments
=
by_name
(
environments
)
environments
=
by_search
(
environments
)
environments
end
private
def
ref
...
...
@@ -56,4 +69,20 @@ class EnvironmentsFinder
def
commit
params
[
:commit
]
end
def
by_name
(
environments
)
if
params
[
:name
].
present?
environments
.
for_name
(
params
[
:name
])
else
environments
end
end
def
by_search
(
environments
)
if
params
[
:search
].
present?
environments
.
for_name_like
(
params
[
:search
],
limit:
nil
)
else
environments
end
end
end
changelogs/add-name-parameter-to-project-environments-api.yml
0 → 100644
View file @
ec66f1b5
---
title
:
Add `name` and `search` parameters to project environments API
merge_request
:
29385
author
:
Lee Tickett
type
:
added
doc/api/environments.md
View file @
ec66f1b5
...
...
@@ -11,9 +11,11 @@ GET /projects/:id/environments
| Attribute | Type | Required | Description |
| --------- | ------- | -------- | --------------------- |
|
`id`
| integer/string | yes | The ID or
[
URL-encoded path of the project
](
README.md#namespaced-path-encoding
)
owned by the authenticated user |
|
`name`
| string | no | Return the environment with this name. Mutually exclusive with
`search`
|
|
`search`
| string | no | Return list of environments matching the search criteria. Mutually exclusive with
`name`
|
```
bash
curl
--header
"PRIVATE-TOKEN: <your_access_token>"
https://gitlab.example.com/api/v4/projects/1/environments
curl
--header
"PRIVATE-TOKEN: <your_access_token>"
https://gitlab.example.com/api/v4/projects/1/environments
?name
=
review%2Ffix-foo
```
Example response:
...
...
lib/api/environments.rb
View file @
ec66f1b5
...
...
@@ -18,11 +18,16 @@ module API
end
params
do
use
:pagination
optional
:name
,
type:
String
,
desc:
'Returns the environment with this name'
optional
:search
,
type:
String
,
desc:
'Returns list of environments matching the search criteria'
mutually_exclusive
:name
,
:search
,
message:
'cannot be used together'
end
get
':id/environments'
do
authorize!
:read_environment
,
user_project
present
paginate
(
user_project
.
environments
),
with:
Entities
::
Environment
,
current_user:
current_user
environments
=
::
EnvironmentsFinder
.
new
(
user_project
,
current_user
,
params
).
find
present
paginate
(
environments
),
with:
Entities
::
Environment
,
current_user:
current_user
end
desc
'Creates a new environment'
do
...
...
spec/requests/api/environments_spec.rb
View file @
ec66f1b5
...
...
@@ -34,6 +34,47 @@ describe API::Environments do
expect
(
json_response
.
first
[
'project'
].
keys
).
to
contain_exactly
(
*
project_data_keys
)
expect
(
json_response
.
first
).
not_to
have_key
(
"last_deployment"
)
end
context
'when filtering'
do
let!
(
:environment2
)
{
create
(
:environment
,
project:
project
)
}
it
'returns environment by name'
do
get
api
(
"/projects/
#{
project
.
id
}
/environments?name=
#{
environment
.
name
}
"
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
include_pagination_headers
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
size
).
to
eq
(
1
)
expect
(
json_response
.
first
[
'name'
]).
to
eq
(
environment
.
name
)
end
it
'returns no environment by non-existent name'
do
get
api
(
"/projects/
#{
project
.
id
}
/environments?name=test"
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
include_pagination_headers
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
size
).
to
eq
(
0
)
end
it
'returns environments by name_like'
do
get
api
(
"/projects/
#{
project
.
id
}
/environments?search=envir"
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
include_pagination_headers
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
size
).
to
eq
(
2
)
end
it
'returns no environment by non-existent name_like'
do
get
api
(
"/projects/
#{
project
.
id
}
/environments?search=test"
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
include_pagination_headers
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
size
).
to
eq
(
0
)
end
end
end
context
'as non member'
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