diff options
author | Travis Miller <travis@travismiller.com> | 2017-08-28 19:02:26 -0500 |
---|---|---|
committer | Travis Miller <travis@travismiller.com> | 2017-08-29 08:31:36 -0500 |
commit | 749c389345cf382b740277db62f7d4b849902d60 (patch) | |
tree | 6d82403ad8e46a380edb3a9ff18a00ded64fc568 /lib/api/entities.rb | |
parent | ce1ce82045f168143ccc143f5200ea9da820d990 (diff) | |
download | gitlab-ce-749c389345cf382b740277db62f7d4b849902d60.tar.gz |
Add time stats to issue and merge request API end points
Diffstat (limited to 'lib/api/entities.rb')
-rw-r--r-- | lib/api/entities.rb | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/lib/api/entities.rb b/lib/api/entities.rb index e18c69b7a3d..803b48dd88a 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -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 |