Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
749c3893
Commit
749c3893
authored
Aug 28, 2017
by
Travis Miller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add time stats to issue and merge request API end points
parent
ce1ce820
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
13 deletions
+39
-13
lib/api/entities.rb
lib/api/entities.rb
+21
-1
lib/api/issues.rb
lib/api/issues.rb
+17
-11
lib/api/merge_requests.rb
lib/api/merge_requests.rb
+1
-1
No files found.
lib/api/entities.rb
View file @
749c3893
...
@@ -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
...
...
lib/api/issues.rb
View file @
749c3893
...
@@ -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
=
{
current_user:
current_user
,
with:
Entities
::
IssueBasic
,
project:
user_project
}
current_user:
current_user
,
options
[
:issuable_metadata
]
=
issuable_meta_data
(
issues
,
'Issue'
)
project:
user_project
,
issuable_metadata:
issuable_meta_data
(
issues
,
'Issue'
)
}
present
paginate
(
issues
),
options
present
paginate
(
issues
),
options
end
end
...
...
lib/api/merge_requests.rb
View file @
749c3893
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment