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
0728588c
Commit
0728588c
authored
Apr 06, 2016
by
Robert Schilling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
API: Ability to filter milestones by state
parent
77e178b5
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
39 additions
and
2 deletions
+39
-2
CHANGELOG
CHANGELOG
+1
-0
doc/api/milestones.md
doc/api/milestones.md
+3
-0
lib/api/milestones.rb
lib/api/milestones.rb
+18
-2
spec/requests/api/milestones_spec.rb
spec/requests/api/milestones_spec.rb
+17
-0
No files found.
CHANGELOG
View file @
0728588c
...
@@ -25,6 +25,7 @@ v 8.7.0 (unreleased)
...
@@ -25,6 +25,7 @@ v 8.7.0 (unreleased)
- Build status notifications
- Build status notifications
- API: Ability to retrieve a specific tag (Robert Schilling)
- API: Ability to retrieve a specific tag (Robert Schilling)
- API: Expose user location (Robert Schilling)
- API: Expose user location (Robert Schilling)
- API: Ability to milter milestones by state `active` and `closed` (Robert Schilling)
v 8.6.5 (unreleased)
v 8.6.5 (unreleased)
- Check permissions when user attempts to import members from another project
- Check permissions when user attempts to import members from another project
...
...
doc/api/milestones.md
View file @
0728588c
...
@@ -7,6 +7,8 @@ Returns a list of project milestones.
...
@@ -7,6 +7,8 @@ Returns a list of project milestones.
```
```
GET /projects/:id/milestones
GET /projects/:id/milestones
GET /projects/:id/milestones?iid=42
GET /projects/:id/milestones?iid=42
GET /projects/:id/milestones?state=active
GET /projects/:id/milestones?state=closed
```
```
```
json
```
json
...
@@ -29,6 +31,7 @@ Parameters:
...
@@ -29,6 +31,7 @@ Parameters:
-
`id`
(required) - The ID of a project
-
`id`
(required) - The ID of a project
-
`iid`
(optional) - Return the milestone having the given
`iid`
-
`iid`
(optional) - Return the milestone having the given
`iid`
-
`state`
(optional) - Return "active" or "closed" milestones
## Get single milestone
## Get single milestone
...
...
lib/api/milestones.rb
View file @
0728588c
...
@@ -3,17 +3,33 @@ module API
...
@@ -3,17 +3,33 @@ module API
class
Milestones
<
Grape
::
API
class
Milestones
<
Grape
::
API
before
{
authenticate!
}
before
{
authenticate!
}
helpers
do
def
filter_milestones_state
(
milestones
,
state
)
case
state
when
'active'
then
milestones
.
active
when
'closed'
then
milestones
.
closed
else
milestones
end
end
end
resource
:projects
do
resource
:projects
do
# Get a list of project milestones
# Get a list of project milestones
#
#
# Parameters:
# Parameters:
# id (required) - The ID of a project
# id (required) - The ID of a project
# state (optional) - Return "active" or "closed" milestones
# Example Request:
# Example Request:
# GET /projects/:id/milestones
# GET /projects/:id/milestones
# GET /projects/:id/milestones?state=active
# GET /projects/:id/milestones?state=closed
get
":id/milestones"
do
get
":id/milestones"
do
authorize!
:read_milestone
,
user_project
authorize!
:read_milestone
,
user_project
present
paginate
(
user_project
.
milestones
),
with:
Entities
::
Milestone
milestones
=
user_project
.
milestones
milestones
=
filter_milestones_state
(
milestones
,
params
[
:state
])
unless
params
[
:state
].
nil?
present
paginate
(
milestones
),
with:
Entities
::
Milestone
end
end
# Get a single project milestone
# Get a single project milestone
...
...
spec/requests/api/milestones_spec.rb
View file @
0728588c
...
@@ -4,6 +4,7 @@ describe API::API, api: true do
...
@@ -4,6 +4,7 @@ describe API::API, api: true do
include
ApiHelpers
include
ApiHelpers
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let!
(
:project
)
{
create
(
:project
,
namespace:
user
.
namespace
)
}
let!
(
:project
)
{
create
(
:project
,
namespace:
user
.
namespace
)
}
let!
(
:closed_milestone
)
{
create
(
:closed_milestone
,
project:
project
,
state: :closed
)
}
let!
(
:milestone
)
{
create
(
:milestone
,
project:
project
)
}
let!
(
:milestone
)
{
create
(
:milestone
,
project:
project
)
}
before
{
project
.
team
<<
[
user
,
:developer
]
}
before
{
project
.
team
<<
[
user
,
:developer
]
}
...
@@ -20,6 +21,22 @@ describe API::API, api: true do
...
@@ -20,6 +21,22 @@ describe API::API, api: true do
get
api
(
"/projects/
#{
project
.
id
}
/milestones"
)
get
api
(
"/projects/
#{
project
.
id
}
/milestones"
)
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
.
status
).
to
eq
(
401
)
end
end
it
'should return an array of active milestones'
do
get
api
(
"/projects/
#{
project
.
id
}
/milestones?state=active"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
1
)
expect
(
json_response
.
first
[
'id'
]).
to
eq
(
milestone
.
id
)
end
it
'should return an array of closed milestones'
do
get
api
(
"/projects/
#{
project
.
id
}
/milestones?state=closed"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
1
)
expect
(
json_response
.
first
[
'id'
]).
to
eq
(
closed_milestone
.
id
)
end
end
end
describe
'GET /projects/:id/milestones/:milestone_id'
do
describe
'GET /projects/:id/milestones/:milestone_id'
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