diff options
author | Robert Schilling <2900-razer6@users.noreply.gitlab.com> | 2019-02-13 12:24:13 +0000 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2019-02-13 12:24:13 +0000 |
commit | 3328f097c9e0936635d580806857e870eb15c1b4 (patch) | |
tree | e2c05e8184866ef78e6a65995b26036a6297897e | |
parent | c0fa62b5d275508449ad97c8cecd8cd6bba1ef15 (diff) | |
download | gitlab-ce-3328f097c9e0936635d580806857e870eb15c1b4.tar.gz |
Add milestone progress to API
-rw-r--r-- | changelogs/unreleased/50559-add-milestone-progress-to-api.yml | 5 | ||||
-rw-r--r-- | doc/api/group_milestones.md | 1 | ||||
-rw-r--r-- | doc/api/milestones.md | 1 | ||||
-rw-r--r-- | lib/api/entities.rb | 3 | ||||
-rw-r--r-- | lib/api/milestone_responses.rb | 8 | ||||
-rw-r--r-- | spec/fixtures/api/schemas/public_api/v4/milestone.json | 1 | ||||
-rw-r--r-- | spec/support/api/milestones_shared_examples.rb | 5 |
7 files changed, 20 insertions, 4 deletions
diff --git a/changelogs/unreleased/50559-add-milestone-progress-to-api.yml b/changelogs/unreleased/50559-add-milestone-progress-to-api.yml new file mode 100644 index 00000000000..e68e4bd6059 --- /dev/null +++ b/changelogs/unreleased/50559-add-milestone-progress-to-api.yml @@ -0,0 +1,5 @@ +--- +title: 'API: Expose milestone progress' +merge_request: 25173 +author: Robert Schilling +type: added diff --git a/doc/api/group_milestones.md b/doc/api/group_milestones.md index 7be01ce9c6d..920acaf3e49 100644 --- a/doc/api/group_milestones.md +++ b/doc/api/group_milestones.md @@ -42,6 +42,7 @@ Example Response: "due_date": "2013-11-29", "start_date": "2013-11-10", "state": "active", + "percentage_complete" : 66, "updated_at": "2013-10-02T09:24:18Z", "created_at": "2013-10-02T09:24:18Z" } diff --git a/doc/api/milestones.md b/doc/api/milestones.md index fa8f8a0bcf0..21a390442bd 100644 --- a/doc/api/milestones.md +++ b/doc/api/milestones.md @@ -39,6 +39,7 @@ Example Response: "due_date": "2013-11-29", "start_date": "2013-11-10", "state": "active", + "percentage_complete" : 66, "updated_at": "2013-10-02T09:24:18Z", "created_at": "2013-10-02T09:24:18Z" } diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 0246f36a685..65f615b7d28 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -501,6 +501,9 @@ module API expose :state, :created_at, :updated_at expose :due_date expose :start_date + expose :percentage_complete do |milestone, options| + milestone.percent_complete(options[:current_user]) + end expose :web_url do |milestone, _options| Gitlab::UrlBuilder.build(milestone) diff --git a/lib/api/milestone_responses.rb b/lib/api/milestone_responses.rb index a0ca39b69d4..4c68c568aaa 100644 --- a/lib/api/milestone_responses.rb +++ b/lib/api/milestone_responses.rb @@ -35,19 +35,19 @@ module API milestones = filter_by_iid(milestones, params[:iids]) if params[:iids].present? milestones = filter_by_search(milestones, params[:search]) if params[:search] - present paginate(milestones), with: Entities::Milestone + present paginate(milestones), with: Entities::Milestone, current_user: current_user end def get_milestone_for(parent) milestone = parent.milestones.find(params[:milestone_id]) - present milestone, with: Entities::Milestone + present milestone, with: Entities::Milestone, current_user: current_user end def create_milestone_for(parent) milestone = ::Milestones::CreateService.new(parent, current_user, declared_params).execute if milestone.valid? - present milestone, with: Entities::Milestone + present milestone, with: Entities::Milestone, current_user: current_user else render_api_error!("Failed to create milestone #{milestone.errors.messages}", 400) end @@ -60,7 +60,7 @@ module API milestone = ::Milestones::UpdateService.new(parent, current_user, milestone_params).execute(milestone) if milestone.valid? - present milestone, with: Entities::Milestone + present milestone, with: Entities::Milestone, current_user: current_user else render_api_error!("Failed to update milestone #{milestone.errors.messages}", 400) end diff --git a/spec/fixtures/api/schemas/public_api/v4/milestone.json b/spec/fixtures/api/schemas/public_api/v4/milestone.json index 6ca2e88ae91..971f7980f46 100644 --- a/spec/fixtures/api/schemas/public_api/v4/milestone.json +++ b/spec/fixtures/api/schemas/public_api/v4/milestone.json @@ -8,6 +8,7 @@ "title": { "type": "string" }, "description": { "type": ["string", "null"] }, "state": { "type": "string" }, + "percentage_complete": { "type": "integer" }, "created_at": { "type": "date" }, "updated_at": { "type": "date" }, "start_date": { "type": "date" }, diff --git a/spec/support/api/milestones_shared_examples.rb b/spec/support/api/milestones_shared_examples.rb index 5f709831ce1..b426fadb001 100644 --- a/spec/support/api/milestones_shared_examples.rb +++ b/spec/support/api/milestones_shared_examples.rb @@ -8,12 +8,17 @@ shared_examples_for 'group and project milestones' do |route_definition| describe "GET #{route_definition}" do it 'returns milestones list' do + create(:issue, project: project, milestone: milestone) + create(:closed_issue, project: project, milestone: milestone) + create(:closed_issue, project: project, milestone: milestone) + get api(route, 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.first['title']).to eq(milestone.title) + expect(json_response.first['percentage_complete']).to eq(66) end it 'returns a 401 error if user not authenticated' do |