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
Kazuhiko Shiozaki
gitlab-ce
Commits
b0a901fe
Commit
b0a901fe
authored
Aug 16, 2012
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add API for Milestones
parent
05da3801
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
147 additions
and
0 deletions
+147
-0
lib/api.rb
lib/api.rb
+1
-0
lib/api/milestones.rb
lib/api/milestones.rb
+93
-0
spec/api/milestones_spec.rb
spec/api/milestones_spec.rb
+53
-0
No files found.
lib/api.rb
View file @
b0a901fe
...
@@ -16,5 +16,6 @@ module Gitlab
...
@@ -16,5 +16,6 @@ module Gitlab
mount
Users
mount
Users
mount
Projects
mount
Projects
mount
Issues
mount
Issues
mount
Milestones
end
end
end
end
lib/api/milestones.rb
0 → 100644
View file @
b0a901fe
module
Gitlab
# Milestones API
class
Milestones
<
Grape
::
API
before
{
authenticate!
}
resource
:projects
do
# Get a list of project milestones
#
# Parameters:
# id (required) - The ID or code name of a project
# Example Request:
# GET /projects/:id/milestones
get
":id/milestones"
do
present
user_project
.
milestones
,
with:
Entities
::
Milestone
end
# Get a single project milestone
#
# Parameters:
# id (required) - The ID or code name of a project
# milestone_id (required) - The ID of a project milestone
# Example Request:
# GET /projects/:id/milestones/:milestone_id
get
":id/milestones/:milestone_id"
do
@milestone
=
user_project
.
milestones
.
find
(
params
[
:milestone_id
])
present
@milestone
,
with:
Entities
::
Milestone
end
# Create a new project milestone
#
# Parameters:
# id (required) - The ID or code name of the project
# title (required) - The title of the milestone
# description (optional) - The description of the milestone
# due_date (optional) - The due date of the milestone
# closed (optional) - The status of the milestone
# Example Request:
# POST /projects/:id/milestones
post
":id/milestones"
do
@milestone
=
user_project
.
milestones
.
new
(
title:
params
[
:title
],
description:
params
[
:description
],
due_date:
params
[
:due_date
],
closed:
(
params
[
:closed
]
||
false
)
)
if
@milestone
.
save
present
@milestone
,
with:
Entities
::
Milestone
else
error!
({
'message'
=>
'404 Not found'
},
404
)
end
end
# Update an existing project milestone
#
# Parameters:
# id (required) - The ID or code name of a project
# title (optional) - The title of a milestone
# description (optional) - The description of a milestone
# due_date (optional) - The due date of a milestone
# closed (optional) - The status of the milestone
# Example Request:
# PUT /projects/:id/milestones/:milestone_id
put
":id/milestones/:milestone_id"
do
@milestone
=
user_project
.
milestones
.
find
(
params
[
:milestone_id
])
parameters
=
{
title:
(
params
[
:title
]
||
@milestone
.
title
),
description:
(
params
[
:description
]
||
@milestone
.
description
),
due_date:
(
params
[
:due_date
]
||
@milestone
.
due_date
),
closed:
(
params
[
:closed
]
||
@milestone
.
closed
)
}
if
@milestone
.
update_attributes
(
parameters
)
present
@milestone
,
with:
Entities
::
Milestone
else
error!
({
'message'
=>
'404 Not found'
},
404
)
end
end
# Delete a project milestone
#
# Parameters:
# id (required) - The ID or code name of a project
# milestone_id (required) - The ID of a project milestone
# Example Request:
# DELETE /projects/:id/milestones/:milestone_id
delete
":id/milestones/:milestone_id"
do
@milestone
=
user_project
.
milestones
.
find
(
params
[
:milestone_id
])
@milestone
.
destroy
end
end
end
end
spec/api/milestones_spec.rb
0 → 100644
View file @
b0a901fe
require
'spec_helper'
describe
Gitlab
::
API
do
let
(
:user
)
{
Factory
:user
}
let!
(
:project
)
{
Factory
:project
,
owner:
user
}
let!
(
:milestone
)
{
Factory
:milestone
,
project:
project
}
before
{
project
.
add_access
(
user
,
:read
)
}
describe
"GET /projects/:id/milestones"
do
it
"should return project milestones"
do
get
"
#{
api_prefix
}
/projects/
#{
project
.
code
}
/milestones?private_token=
#{
user
.
private_token
}
"
response
.
status
.
should
==
200
json_response
.
should
be_an
Array
json_response
.
first
[
'title'
].
should
==
milestone
.
title
end
end
describe
"GET /projects/:id/milestones/:milestone_id"
do
it
"should return a project milestone by id"
do
get
"
#{
api_prefix
}
/projects/
#{
project
.
code
}
/milestones/
#{
milestone
.
id
}
?private_token=
#{
user
.
private_token
}
"
response
.
status
.
should
==
200
json_response
[
'title'
].
should
==
milestone
.
title
end
end
describe
"POST /projects/:id/milestones"
do
it
"should create a new project milestone"
do
post
"
#{
api_prefix
}
/projects/
#{
project
.
code
}
/milestones?private_token=
#{
user
.
private_token
}
"
,
title:
'new milestone'
response
.
status
.
should
==
201
json_response
[
'title'
].
should
==
'new milestone'
json_response
[
'description'
].
should
be_nil
end
end
describe
"PUT /projects/:id/milestones/:milestone_id"
do
it
"should update a project milestone"
do
put
"
#{
api_prefix
}
/projects/
#{
project
.
code
}
/milestones/
#{
milestone
.
id
}
?private_token=
#{
user
.
private_token
}
"
,
title:
'updated title'
response
.
status
.
should
==
200
json_response
[
'title'
].
should
==
'updated title'
end
end
describe
"DELETE /projects/:id/milestones/:milestone_id"
do
it
"should delete a project milestone"
do
expect
{
delete
"
#{
api_prefix
}
/projects/
#{
project
.
code
}
/milestones/
#{
milestone
.
id
}
?private_token=
#{
user
.
private_token
}
"
}.
to
change
{
Milestone
.
count
}.
by
(
-
1
)
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