Commit f3791135 authored by Bob van de Vijver's avatar Bob van de Vijver Committed by Kushal Pandya

Fixes #22622: Include MR times in Milestone time overview

parent 972e5e68
......@@ -117,20 +117,20 @@ module Milestoneish
false
end
def total_issue_time_spent
@total_issue_time_spent ||= issues.joins(:timelogs).sum(:time_spent)
def total_time_spent
@total_time_spent ||= issues.joins(:timelogs).sum(:time_spent) + merge_requests.joins(:timelogs).sum(:time_spent)
end
def human_total_issue_time_spent
Gitlab::TimeTrackingFormatter.output(total_issue_time_spent)
def human_total_time_spent
Gitlab::TimeTrackingFormatter.output(total_time_spent)
end
def total_issue_time_estimate
@total_issue_time_estimate ||= issues.sum(:time_estimate)
def total_time_estimate
@total_time_estimate ||= issues.sum(:time_estimate) + merge_requests.sum(:time_estimate)
end
def human_total_issue_time_estimate
Gitlab::TimeTrackingFormatter.output(total_issue_time_estimate)
def human_total_time_estimate
Gitlab::TimeTrackingFormatter.output(total_time_estimate)
end
private
......
......@@ -94,7 +94,7 @@ class GlobalMilestone
end
def merge_requests
@merge_requests ||= MergeRequest.of_milestones(milestone).includes(:target_project, :assignee, :labels)
@merge_requests ||= MergeRequest.of_milestones(milestone).includes(:target_project, :assignees, :labels)
end
def labels
......
......@@ -93,10 +93,10 @@
= milestone.issues_visible_to_user(current_user).closed.count
.block
#issuable-time-tracker{ data: { time_estimate: @milestone.total_issue_time_estimate,
time_spent: @milestone.total_issue_time_spent,
human_time_estimate: @milestone.human_total_issue_time_estimate,
human_time_spent: @milestone.human_total_issue_time_spent,
#issuable-time-tracker{ data: { time_estimate: @milestone.total_time_estimate,
time_spent: @milestone.total_time_spent,
human_time_estimate: @milestone.human_total_time_estimate,
human_time_spent: @milestone.human_total_time_spent,
limit_to_hours: Gitlab::CurrentSettings.time_tracking_limit_to_hours.to_s } }
= render_if_exists 'shared/milestones/weight', milestone: milestone
......
---
title: Include MR times in Milestone time overview
merge_request: 28519
author: Bob van de Vijver
type: fixed
......@@ -133,7 +133,7 @@ The milestone sidebar on the milestone view shows the following:
- Percentage complete, which is calculated as number of closed issues divided by total number of issues.
- The start date and due date.
- The total time spent on all issues assigned to the milestone.
- The total time spent on all issues and merge requests assigned to the milestone.
- The total issue weight of all issues assigned to the milestone.
![Project milestone page](img/milestones_project_milestone_page.png)
......
......@@ -302,20 +302,55 @@ describe Milestone, 'Milestoneish' do
end
end
describe '#total_issue_time_spent' do
it 'calculates total issue time spent' do
describe '#total_time_spent' do
it 'calculates total time spent' do
closed_issue_1.spend_time(duration: 300, user_id: author.id)
closed_issue_1.save!
closed_issue_2.spend_time(duration: 600, user_id: assignee.id)
closed_issue_2.save!
expect(milestone.total_issue_time_spent).to eq(900)
expect(milestone.total_time_spent).to eq(900)
end
it 'includes merge request time spent' do
closed_issue_1.spend_time(duration: 300, user_id: author.id)
closed_issue_1.save!
merge_request.spend_time(duration: 900, user_id: author.id)
merge_request.save!
expect(milestone.total_time_spent).to eq(1200)
end
end
describe '#human_total_time_spent' do
it 'returns nil if no time has been spent' do
expect(milestone.human_total_time_spent).to be_nil
end
end
describe '#total_time_estimate' do
it 'calculates total estimate' do
closed_issue_1.time_estimate = 300
closed_issue_1.save!
closed_issue_2.time_estimate = 600
closed_issue_2.save!
expect(milestone.total_time_estimate).to eq(900)
end
it 'includes merge request time estimate' do
closed_issue_1.time_estimate = 300
closed_issue_1.save!
merge_request.time_estimate = 900
merge_request.save!
expect(milestone.total_time_estimate).to eq(1200)
end
end
describe '#human_total_issue_time_spent' do
describe '#human_total_time_estimate' do
it 'returns nil if no time has been spent' do
expect(milestone.human_total_issue_time_spent).to be_nil
expect(milestone.human_total_time_estimate).to be_nil
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment