2013-05-14 08:33:31 -04:00
|
|
|
module API
|
2012-08-16 14:51:31 -04:00
|
|
|
class Milestones < Grape::API
|
2016-12-04 12:11:19 -05:00
|
|
|
include PaginationParams
|
|
|
|
|
2012-08-16 14:51:31 -04:00
|
|
|
before { authenticate! }
|
|
|
|
|
2016-04-06 07:03:07 -04:00
|
|
|
helpers do
|
|
|
|
def filter_milestones_state(milestones, state)
|
|
|
|
case state
|
|
|
|
when 'active' then milestones.active
|
|
|
|
when 'closed' then milestones.closed
|
|
|
|
else milestones
|
|
|
|
end
|
|
|
|
end
|
2016-11-09 09:14:02 -05:00
|
|
|
|
|
|
|
params :optional_params do
|
|
|
|
optional :description, type: String, desc: 'The description of the milestone'
|
2016-11-15 12:48:30 -05:00
|
|
|
optional :due_date, type: String, desc: 'The due date of the milestone. The ISO 8601 date format (%Y-%m-%d)'
|
|
|
|
optional :start_date, type: String, desc: 'The start date of the milestone. The ISO 8601 date format (%Y-%m-%d)'
|
2016-11-09 09:14:02 -05:00
|
|
|
end
|
2016-04-06 07:03:07 -04:00
|
|
|
end
|
|
|
|
|
2016-11-09 09:14:02 -05:00
|
|
|
params do
|
|
|
|
requires :id, type: String, desc: 'The ID of a project'
|
|
|
|
end
|
2017-03-15 14:09:24 -04:00
|
|
|
resource :projects, requirements: { id: %r{[^/]+} } do
|
2016-11-09 09:14:02 -05:00
|
|
|
desc 'Get a list of project milestones' do
|
|
|
|
success Entities::Milestone
|
|
|
|
end
|
|
|
|
params do
|
|
|
|
optional :state, type: String, values: %w[active closed all], default: 'all',
|
|
|
|
desc: 'Return "active", "closed", or "all" milestones'
|
2017-02-09 09:28:19 -05:00
|
|
|
optional :iids, type: Array[Integer], desc: 'The IIDs of the milestones'
|
2017-02-28 07:23:40 -05:00
|
|
|
optional :search, type: String, desc: 'The search criteria for the title or description of the milestone'
|
2016-12-04 12:11:19 -05:00
|
|
|
use :pagination
|
2016-11-09 09:14:02 -05:00
|
|
|
end
|
2012-08-16 14:51:31 -04:00
|
|
|
get ":id/milestones" do
|
2012-09-21 06:22:30 -04:00
|
|
|
authorize! :read_milestone, user_project
|
|
|
|
|
2016-04-06 07:03:07 -04:00
|
|
|
milestones = user_project.milestones
|
2016-04-06 14:53:17 -04:00
|
|
|
milestones = filter_milestones_state(milestones, params[:state])
|
2017-02-09 09:28:19 -05:00
|
|
|
milestones = filter_by_iid(milestones, params[:iids]) if params[:iids].present?
|
2017-02-28 07:23:40 -05:00
|
|
|
milestones = filter_by_search(milestones, params[:search]) if params[:search]
|
2016-04-06 07:03:07 -04:00
|
|
|
|
|
|
|
present paginate(milestones), with: Entities::Milestone
|
2012-08-16 14:51:31 -04:00
|
|
|
end
|
|
|
|
|
2016-11-09 09:14:02 -05:00
|
|
|
desc 'Get a single project milestone' do
|
|
|
|
success Entities::Milestone
|
|
|
|
end
|
|
|
|
params do
|
|
|
|
requires :milestone_id, type: Integer, desc: 'The ID of a project milestone'
|
|
|
|
end
|
2012-08-16 14:51:31 -04:00
|
|
|
get ":id/milestones/:milestone_id" do
|
2012-09-21 06:22:30 -04:00
|
|
|
authorize! :read_milestone, user_project
|
|
|
|
|
2016-11-09 09:14:02 -05:00
|
|
|
milestone = user_project.milestones.find(params[:milestone_id])
|
|
|
|
present milestone, with: Entities::Milestone
|
2012-08-16 14:51:31 -04:00
|
|
|
end
|
|
|
|
|
2016-11-09 09:14:02 -05:00
|
|
|
desc 'Create a new project milestone' do
|
|
|
|
success Entities::Milestone
|
|
|
|
end
|
|
|
|
params do
|
|
|
|
requires :title, type: String, desc: 'The title of the milestone'
|
|
|
|
use :optional_params
|
|
|
|
end
|
2012-08-16 14:51:31 -04:00
|
|
|
post ":id/milestones" do
|
2014-06-10 11:07:52 -04:00
|
|
|
authorize! :admin_milestone, user_project
|
2016-11-09 09:14:02 -05:00
|
|
|
|
2016-11-10 10:32:59 -05:00
|
|
|
milestone = ::Milestones::CreateService.new(user_project, current_user, declared_params).execute
|
2013-02-20 16:51:59 -05:00
|
|
|
|
2014-06-10 11:07:52 -04:00
|
|
|
if milestone.valid?
|
|
|
|
present milestone, with: Entities::Milestone
|
|
|
|
else
|
2015-01-07 04:46:00 -05:00
|
|
|
render_api_error!("Failed to create milestone #{milestone.errors.messages}", 400)
|
2012-08-16 14:51:31 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-11-09 09:14:02 -05:00
|
|
|
desc 'Update an existing project milestone' do
|
|
|
|
success Entities::Milestone
|
|
|
|
end
|
|
|
|
params do
|
|
|
|
requires :milestone_id, type: Integer, desc: 'The ID of a project milestone'
|
|
|
|
optional :title, type: String, desc: 'The title of the milestone'
|
|
|
|
optional :state_event, type: String, values: %w[close activate],
|
|
|
|
desc: 'The state event of the milestone '
|
|
|
|
use :optional_params
|
|
|
|
at_least_one_of :title, :description, :due_date, :state_event
|
|
|
|
end
|
2012-08-16 14:51:31 -04:00
|
|
|
put ":id/milestones/:milestone_id" do
|
2014-06-10 11:07:52 -04:00
|
|
|
authorize! :admin_milestone, user_project
|
2016-11-10 10:32:59 -05:00
|
|
|
milestone = user_project.milestones.find(params.delete(:milestone_id))
|
2016-11-09 09:14:02 -05:00
|
|
|
|
2016-11-10 10:32:59 -05:00
|
|
|
milestone_params = declared_params(include_missing: false)
|
2016-11-09 09:14:02 -05:00
|
|
|
milestone = ::Milestones::UpdateService.new(user_project, current_user, milestone_params).execute(milestone)
|
2012-09-10 02:06:11 -04:00
|
|
|
|
2014-06-10 11:07:52 -04:00
|
|
|
if milestone.valid?
|
|
|
|
present milestone, with: Entities::Milestone
|
|
|
|
else
|
2015-01-07 04:46:00 -05:00
|
|
|
render_api_error!("Failed to update milestone #{milestone.errors.messages}", 400)
|
2012-08-16 14:51:31 -04:00
|
|
|
end
|
|
|
|
end
|
2014-06-02 19:10:38 -04:00
|
|
|
|
2016-11-09 09:14:02 -05:00
|
|
|
desc 'Get all issues for a single project milestone' do
|
2017-03-06 06:48:10 -05:00
|
|
|
success Entities::IssueBasic
|
2016-11-09 09:14:02 -05:00
|
|
|
end
|
|
|
|
params do
|
|
|
|
requires :milestone_id, type: Integer, desc: 'The ID of a project milestone'
|
2016-12-04 12:11:19 -05:00
|
|
|
use :pagination
|
2016-11-09 09:14:02 -05:00
|
|
|
end
|
2014-06-02 19:10:38 -04:00
|
|
|
get ":id/milestones/:milestone_id/issues" do
|
|
|
|
authorize! :read_milestone, user_project
|
|
|
|
|
2016-11-09 09:14:02 -05:00
|
|
|
milestone = user_project.milestones.find(params[:milestone_id])
|
2016-04-24 23:07:59 -04:00
|
|
|
|
|
|
|
finder_params = {
|
|
|
|
project_id: user_project.id,
|
2017-03-09 13:43:07 -05:00
|
|
|
milestone_title: milestone.title,
|
2017-06-07 17:14:23 -04:00
|
|
|
sort: 'label_priority'
|
2016-04-24 23:07:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
issues = IssuesFinder.new(current_user, finder_params).execute
|
2017-03-06 06:48:10 -05:00
|
|
|
present paginate(issues), with: Entities::IssueBasic, current_user: current_user, project: user_project
|
2014-06-02 19:10:38 -04:00
|
|
|
end
|
2017-02-16 04:08:18 -05:00
|
|
|
|
|
|
|
desc 'Get all merge requests for a single project milestone' do
|
|
|
|
detail 'This feature was introduced in GitLab 9.'
|
2017-03-06 06:48:10 -05:00
|
|
|
success Entities::MergeRequestBasic
|
2017-02-16 04:08:18 -05:00
|
|
|
end
|
|
|
|
params do
|
|
|
|
requires :milestone_id, type: Integer, desc: 'The ID of a project milestone'
|
|
|
|
use :pagination
|
|
|
|
end
|
|
|
|
get ':id/milestones/:milestone_id/merge_requests' do
|
|
|
|
authorize! :read_milestone, user_project
|
|
|
|
|
|
|
|
milestone = user_project.milestones.find(params[:milestone_id])
|
|
|
|
|
|
|
|
finder_params = {
|
|
|
|
project_id: user_project.id,
|
2017-03-31 05:38:40 -04:00
|
|
|
milestone_title: milestone.title,
|
2017-06-07 17:14:23 -04:00
|
|
|
sort: 'label_priority'
|
2017-02-16 04:08:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
merge_requests = MergeRequestsFinder.new(current_user, finder_params).execute
|
2017-03-06 06:48:10 -05:00
|
|
|
present paginate(merge_requests),
|
|
|
|
with: Entities::MergeRequestBasic,
|
|
|
|
current_user: current_user,
|
|
|
|
project: user_project
|
2017-02-16 04:08:18 -05:00
|
|
|
end
|
2012-08-16 14:51:31 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|