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