Commit 749c3893 authored by Travis Miller's avatar Travis Miller

Add time stats to issue and merge request API end points

parent ce1ce820
......@@ -354,6 +354,10 @@ module API
expose :web_url do |issue, options|
Gitlab::UrlBuilder.build(issue)
end
expose :time_stats, using: 'API::Entities::IssuableTimeStats' do |issue|
issue
end
end
class Issue < IssueBasic
......@@ -383,10 +387,22 @@ module API
end
class IssuableTimeStats < Grape::Entity
format_with(:time_tracking_formatter) do |time_spent|
Gitlab::TimeTrackingFormatter.output(time_spent)
end
expose :time_estimate
expose :total_time_spent
expose :human_time_estimate
expose :human_total_time_spent
with_options(format_with: :time_tracking_formatter) do
expose :total_time_spent, as: :human_total_time_spent
end
def total_time_spent
# Avoids an N+1 query since timelogs are preloaded
object.timelogs.map(&:time_spent).sum
end
end
class ExternalIssue < Grape::Entity
......@@ -436,6 +452,10 @@ module API
expose :web_url do |merge_request, options|
Gitlab::UrlBuilder.build(merge_request)
end
expose :time_stats, using: 'API::Entities::IssuableTimeStats' do |merge_request|
merge_request
end
end
class MergeRequest < MergeRequestBasic
......
......@@ -15,7 +15,7 @@ module API
args[:label_name] = args.delete(:labels)
issues = IssuesFinder.new(current_user, args).execute
.preload(:assignees, :labels, :notes)
.preload(:assignees, :labels, :notes, :timelogs)
issues.reorder(args[:order_by] => args[:sort])
end
......@@ -68,9 +68,11 @@ module API
get do
issues = find_issues
options = { with: Entities::IssueBasic,
current_user: current_user }
options[:issuable_metadata] = issuable_meta_data(issues, 'Issue')
options = {
with: Entities::IssueBasic,
current_user: current_user,
issuable_metadata: issuable_meta_data(issues, 'Issue')
}
present paginate(issues), options
end
......@@ -93,9 +95,11 @@ module API
issues = find_issues(group_id: group.id)
options = { with: Entities::IssueBasic,
current_user: current_user }
options[:issuable_metadata] = issuable_meta_data(issues, 'Issue')
options = {
with: Entities::IssueBasic,
current_user: current_user,
issuable_metadata: issuable_meta_data(issues, 'Issue')
}
present paginate(issues), options
end
......@@ -120,10 +124,12 @@ module API
issues = find_issues(project_id: project.id)
options = { with: Entities::IssueBasic,
current_user: current_user,
project: user_project }
options[:issuable_metadata] = issuable_meta_data(issues, 'Issue')
options = {
with: Entities::IssueBasic,
current_user: current_user,
project: user_project,
issuable_metadata: issuable_meta_data(issues, 'Issue')
}
present paginate(issues), options
end
......
......@@ -21,7 +21,7 @@ module API
return merge_requests if args[:view] == 'simple'
merge_requests
.preload(:notes, :author, :assignee, :milestone, :merge_request_diff, :labels)
.preload(:notes, :author, :assignee, :milestone, :merge_request_diff, :labels, :timelogs)
end
params :merge_requests_params do
......
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