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
035c8af1
Commit
035c8af1
authored
Mar 27, 2019
by
Fabio Busatto
Committed by
Sean McGivern
Mar 27, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Resolve "Get milestone by title via API"
parent
978aa04f
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
26 additions
and
0 deletions
+26
-0
changelogs/unreleased/59296-add-filter-by-title-milestones-api.yml
...s/unreleased/59296-add-filter-by-title-milestones-api.yml
+5
-0
doc/api/group_milestones.md
doc/api/group_milestones.md
+2
-0
doc/api/milestones.md
doc/api/milestones.md
+2
-0
lib/api/helpers.rb
lib/api/helpers.rb
+6
-0
lib/api/milestone_responses.rb
lib/api/milestone_responses.rb
+2
-0
spec/support/api/milestones_shared_examples.rb
spec/support/api/milestones_shared_examples.rb
+9
-0
No files found.
changelogs/unreleased/59296-add-filter-by-title-milestones-api.yml
0 → 100644
View file @
035c8af1
---
title
:
Add select by title to milestones API
merge_request
:
26573
author
:
type
:
added
doc/api/group_milestones.md
View file @
035c8af1
...
@@ -12,6 +12,7 @@ GET /groups/:id/milestones?iids[]=42
...
@@ -12,6 +12,7 @@ GET /groups/:id/milestones?iids[]=42
GET /groups/:id/milestones?iids[]=42&iids[]=43
GET /groups/:id/milestones?iids[]=42&iids[]=43
GET /groups/:id/milestones?state=active
GET /groups/:id/milestones?state=active
GET /groups/:id/milestones?state=closed
GET /groups/:id/milestones?state=closed
GET /groups/:id/milestones?title=1.0
GET /groups/:id/milestones?search=version
GET /groups/:id/milestones?search=version
```
```
...
@@ -22,6 +23,7 @@ Parameters:
...
@@ -22,6 +23,7 @@ Parameters:
|
`id`
| integer/string | yes | The ID or
[
URL-encoded path of the group
](
README.md#namespaced-path-encoding
)
owned by the authenticated user |
|
`id`
| integer/string | yes | The ID or
[
URL-encoded path of the group
](
README.md#namespaced-path-encoding
)
owned by the authenticated user |
|
`iids[]`
| Array[integer] | optional | Return only the milestones having the given
`iid`
|
|
`iids[]`
| Array[integer] | optional | Return only the milestones having the given
`iid`
|
|
`state`
| string | optional | Return only
`active`
or
`closed`
milestones |
|
`state`
| string | optional | Return only
`active`
or
`closed`
milestones |
|
`title`
| string | optional | Return only the milestones having the given
`title`
|
|
`search`
| string | optional | Return only milestones with a title or description matching the provided string |
|
`search`
| string | optional | Return only milestones with a title or description matching the provided string |
```
bash
```
bash
...
...
doc/api/milestones.md
View file @
035c8af1
...
@@ -10,6 +10,7 @@ GET /projects/:id/milestones?iids[]=42
...
@@ -10,6 +10,7 @@ GET /projects/:id/milestones?iids[]=42
GET /projects/:id/milestones?iids[]=42&iids[]=43
GET /projects/:id/milestones?iids[]=42&iids[]=43
GET /projects/:id/milestones?state=active
GET /projects/:id/milestones?state=active
GET /projects/:id/milestones?state=closed
GET /projects/:id/milestones?state=closed
GET /projects/:id/milestones?title=1.0
GET /projects/:id/milestones?search=version
GET /projects/:id/milestones?search=version
```
```
...
@@ -20,6 +21,7 @@ Parameters:
...
@@ -20,6 +21,7 @@ Parameters:
|
`id`
| integer/string | yes | The ID or
[
URL-encoded path of the project
](
README.md#namespaced-path-encoding
)
owned by the authenticated user |
|
`id`
| integer/string | yes | The ID or
[
URL-encoded path of the project
](
README.md#namespaced-path-encoding
)
owned by the authenticated user |
|
`iids[]`
| Array[integer] | optional | Return only the milestones having the given
`iid`
|
|
`iids[]`
| Array[integer] | optional | Return only the milestones having the given
`iid`
|
|
`state`
| string | optional | Return only
`active`
or
`closed`
milestones |
|
`state`
| string | optional | Return only
`active`
or
`closed`
milestones |
|
`title`
| string | optional | Return only the milestones having the given
`title`
|
|
`search`
| string | optional | Return only milestones with a title or description matching the provided string |
|
`search`
| string | optional | Return only milestones with a title or description matching the provided string |
```
bash
```
bash
...
...
lib/api/helpers.rb
View file @
035c8af1
...
@@ -302,6 +302,12 @@ module API
...
@@ -302,6 +302,12 @@ module API
end
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def
filter_by_title
(
items
,
title
)
items
.
where
(
title:
title
)
end
# rubocop: enable CodeReuse/ActiveRecord
def
filter_by_search
(
items
,
text
)
def
filter_by_search
(
items
,
text
)
items
.
search
(
text
)
items
.
search
(
text
)
end
end
...
...
lib/api/milestone_responses.rb
View file @
035c8af1
...
@@ -16,6 +16,7 @@ module API
...
@@ -16,6 +16,7 @@ module API
optional
:state
,
type:
String
,
values:
%w[active closed all]
,
default:
'all'
,
optional
:state
,
type:
String
,
values:
%w[active closed all]
,
default:
'all'
,
desc:
'Return "active", "closed", or "all" milestones'
desc:
'Return "active", "closed", or "all" milestones'
optional
:iids
,
type:
Array
[
Integer
],
desc:
'The IIDs of the milestones'
optional
:iids
,
type:
Array
[
Integer
],
desc:
'The IIDs of the milestones'
optional
:title
,
type:
String
,
desc:
'The title of the milestones'
optional
:search
,
type:
String
,
desc:
'The search criteria for the title or description of the milestone'
optional
:search
,
type:
String
,
desc:
'The search criteria for the title or description of the milestone'
use
:pagination
use
:pagination
end
end
...
@@ -33,6 +34,7 @@ module API
...
@@ -33,6 +34,7 @@ module API
milestones
=
parent
.
milestones
.
order_id_desc
milestones
=
parent
.
milestones
.
order_id_desc
milestones
=
Milestone
.
filter_by_state
(
milestones
,
params
[
:state
])
milestones
=
Milestone
.
filter_by_state
(
milestones
,
params
[
:state
])
milestones
=
filter_by_iid
(
milestones
,
params
[
:iids
])
if
params
[
:iids
].
present?
milestones
=
filter_by_iid
(
milestones
,
params
[
:iids
])
if
params
[
:iids
].
present?
milestones
=
filter_by_title
(
milestones
,
params
[
:title
])
if
params
[
:title
]
milestones
=
filter_by_search
(
milestones
,
params
[
:search
])
if
params
[
:search
]
milestones
=
filter_by_search
(
milestones
,
params
[
:search
])
if
params
[
:search
]
present
paginate
(
milestones
),
with:
Entities
::
Milestone
present
paginate
(
milestones
),
with:
Entities
::
Milestone
...
...
spec/support/api/milestones_shared_examples.rb
View file @
035c8af1
...
@@ -72,6 +72,15 @@ shared_examples_for 'group and project milestones' do |route_definition|
...
@@ -72,6 +72,15 @@ shared_examples_for 'group and project milestones' do |route_definition|
expect
(
json_response
.
first
[
'id'
]).
to
eq
closed_milestone
.
id
expect
(
json_response
.
first
[
'id'
]).
to
eq
closed_milestone
.
id
end
end
it
'returns a milestone by title'
do
get
api
(
route
,
user
),
params:
{
title:
'version2'
}
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
json_response
.
size
).
to
eq
(
1
)
expect
(
json_response
.
first
[
'title'
]).
to
eq
milestone
.
title
expect
(
json_response
.
first
[
'id'
]).
to
eq
milestone
.
id
end
it
'returns a milestone by searching for title'
do
it
'returns a milestone by searching for title'
do
get
api
(
route
,
user
),
params:
{
search:
'version2'
}
get
api
(
route
,
user
),
params:
{
search:
'version2'
}
...
...
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