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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
b844bc75
Commit
b844bc75
authored
Feb 03, 2020
by
Rajendra Kadam
Committed by
Stan Hu
Feb 03, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Separate issue entities into own class files
parent
bbda4cf6
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
151 additions
and
121 deletions
+151
-121
changelogs/unreleased/refactoring-entities-file-10.yml
changelogs/unreleased/refactoring-entities-file-10.yml
+5
-0
lib/api/entities.rb
lib/api/entities.rb
+0
-121
lib/api/entities/external_issue.rb
lib/api/entities/external_issue.rb
+10
-0
lib/api/entities/issuable_time_stats.rb
lib/api/entities/issuable_time_stats.rb
+26
-0
lib/api/entities/issue.rb
lib/api/entities/issue.rb
+48
-0
lib/api/entities/issue_basic.rb
lib/api/entities/issue_basic.rb
+43
-0
lib/api/entities/milestone.rb
lib/api/entities/milestone.rb
+19
-0
No files found.
changelogs/unreleased/refactoring-entities-file-10.yml
0 → 100644
View file @
b844bc75
---
title
:
Separate issue entities into own class files
merge_request
:
24226
author
:
Rajendra Kadam
type
:
added
lib/api/entities.rb
View file @
b844bc75
...
...
@@ -128,127 +128,6 @@ module API
end
end
class
Milestone
<
Grape
::
Entity
expose
:id
,
:iid
expose
:project_id
,
if:
->
(
entity
,
options
)
{
entity
&
.
project_id
}
expose
:group_id
,
if:
->
(
entity
,
options
)
{
entity
&
.
group_id
}
expose
:title
,
:description
expose
:state
,
:created_at
,
:updated_at
expose
:due_date
expose
:start_date
expose
:web_url
do
|
milestone
,
_options
|
Gitlab
::
UrlBuilder
.
build
(
milestone
)
end
end
class
IssueBasic
<
IssuableEntity
expose
:closed_at
expose
:closed_by
,
using:
Entities
::
UserBasic
expose
:labels
do
|
issue
,
options
|
if
options
[
:with_labels_details
]
::
API
::
Entities
::
LabelBasic
.
represent
(
issue
.
labels
.
sort_by
(
&
:title
))
else
issue
.
labels
.
map
(
&
:title
).
sort
end
end
expose
:milestone
,
using:
Entities
::
Milestone
expose
:assignees
,
:author
,
using:
Entities
::
UserBasic
expose
:assignee
,
using:
::
API
::
Entities
::
UserBasic
do
|
issue
|
issue
.
assignees
.
first
end
expose
(
:user_notes_count
)
{
|
issue
,
options
|
issuable_metadata
(
issue
,
options
,
:user_notes_count
)
}
expose
(
:merge_requests_count
)
{
|
issue
,
options
|
issuable_metadata
(
issue
,
options
,
:merge_requests_count
,
options
[
:current_user
])
}
expose
(
:upvotes
)
{
|
issue
,
options
|
issuable_metadata
(
issue
,
options
,
:upvotes
)
}
expose
(
:downvotes
)
{
|
issue
,
options
|
issuable_metadata
(
issue
,
options
,
:downvotes
)
}
expose
:due_date
expose
:confidential
expose
:discussion_locked
expose
:web_url
do
|
issue
|
Gitlab
::
UrlBuilder
.
build
(
issue
)
end
expose
:time_stats
,
using:
'API::Entities::IssuableTimeStats'
do
|
issue
|
issue
end
expose
:task_completion_status
end
class
Issue
<
IssueBasic
include
::
API
::
Helpers
::
RelatedResourcesHelpers
expose
(
:has_tasks
)
do
|
issue
,
_
|
!
issue
.
task_list_items
.
empty?
end
expose
:task_status
,
if:
->
(
issue
,
_
)
do
!
issue
.
task_list_items
.
empty?
end
expose
:_links
do
expose
:self
do
|
issue
|
expose_url
(
api_v4_project_issue_path
(
id:
issue
.
project_id
,
issue_iid:
issue
.
iid
))
end
expose
:notes
do
|
issue
|
expose_url
(
api_v4_projects_issues_notes_path
(
id:
issue
.
project_id
,
noteable_id:
issue
.
iid
))
end
expose
:award_emoji
do
|
issue
|
expose_url
(
api_v4_projects_issues_award_emoji_path
(
id:
issue
.
project_id
,
issue_iid:
issue
.
iid
))
end
expose
:project
do
|
issue
|
expose_url
(
api_v4_projects_path
(
id:
issue
.
project_id
))
end
end
expose
:references
,
with:
IssuableReferences
do
|
issue
|
issue
end
# Calculating the value of subscribed field triggers Markdown
# processing. We can't do that for multiple issues / merge
# requests in a single API request.
expose
:subscribed
,
if:
->
(
_
,
options
)
{
options
.
fetch
(
:include_subscribed
,
true
)
}
do
|
issue
,
options
|
issue
.
subscribed?
(
options
[
:current_user
],
options
[
:project
]
||
issue
.
project
)
end
expose
:moved_to_id
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
with_options
(
format_with: :time_tracking_formatter
)
do
expose
:total_time_spent
,
as: :human_total_time_spent
end
# rubocop: disable CodeReuse/ActiveRecord
def
total_time_spent
# Avoids an N+1 query since timelogs are preloaded
object
.
timelogs
.
map
(
&
:time_spent
).
sum
end
# rubocop: enable CodeReuse/ActiveRecord
end
class
ExternalIssue
<
Grape
::
Entity
expose
:title
expose
:id
end
class
PipelineBasic
<
Grape
::
Entity
expose
:id
,
:sha
,
:ref
,
:status
expose
:created_at
,
:updated_at
...
...
lib/api/entities/external_issue.rb
0 → 100644
View file @
b844bc75
# frozen_string_literal: true
module
API
module
Entities
class
ExternalIssue
<
Grape
::
Entity
expose
:title
expose
:id
end
end
end
lib/api/entities/issuable_time_stats.rb
0 → 100644
View file @
b844bc75
# frozen_string_literal: true
module
API
module
Entities
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
with_options
(
format_with: :time_tracking_formatter
)
do
expose
:total_time_spent
,
as: :human_total_time_spent
end
# rubocop: disable CodeReuse/ActiveRecord
def
total_time_spent
# Avoids an N+1 query since timelogs are preloaded
object
.
timelogs
.
map
(
&
:time_spent
).
sum
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
end
lib/api/entities/issue.rb
0 → 100644
View file @
b844bc75
# frozen_string_literal: true
module
API
module
Entities
class
Issue
<
IssueBasic
include
::
API
::
Helpers
::
RelatedResourcesHelpers
expose
(
:has_tasks
)
do
|
issue
,
_
|
!
issue
.
task_list_items
.
empty?
end
expose
:task_status
,
if:
->
(
issue
,
_
)
do
!
issue
.
task_list_items
.
empty?
end
expose
:_links
do
expose
:self
do
|
issue
|
expose_url
(
api_v4_project_issue_path
(
id:
issue
.
project_id
,
issue_iid:
issue
.
iid
))
end
expose
:notes
do
|
issue
|
expose_url
(
api_v4_projects_issues_notes_path
(
id:
issue
.
project_id
,
noteable_id:
issue
.
iid
))
end
expose
:award_emoji
do
|
issue
|
expose_url
(
api_v4_projects_issues_award_emoji_path
(
id:
issue
.
project_id
,
issue_iid:
issue
.
iid
))
end
expose
:project
do
|
issue
|
expose_url
(
api_v4_projects_path
(
id:
issue
.
project_id
))
end
end
expose
:references
,
with:
IssuableReferences
do
|
issue
|
issue
end
# Calculating the value of subscribed field triggers Markdown
# processing. We can't do that for multiple issues / merge
# requests in a single API request.
expose
:subscribed
,
if:
->
(
_
,
options
)
{
options
.
fetch
(
:include_subscribed
,
true
)
}
do
|
issue
,
options
|
issue
.
subscribed?
(
options
[
:current_user
],
options
[
:project
]
||
issue
.
project
)
end
expose
:moved_to_id
end
end
end
lib/api/entities/issue_basic.rb
0 → 100644
View file @
b844bc75
# frozen_string_literal: true
module
API
module
Entities
class
IssueBasic
<
IssuableEntity
expose
:closed_at
expose
:closed_by
,
using:
Entities
::
UserBasic
expose
:labels
do
|
issue
,
options
|
if
options
[
:with_labels_details
]
::
API
::
Entities
::
LabelBasic
.
represent
(
issue
.
labels
.
sort_by
(
&
:title
))
else
issue
.
labels
.
map
(
&
:title
).
sort
end
end
expose
:milestone
,
using:
Entities
::
Milestone
expose
:assignees
,
:author
,
using:
Entities
::
UserBasic
expose
:assignee
,
using:
::
API
::
Entities
::
UserBasic
do
|
issue
|
issue
.
assignees
.
first
end
expose
(
:user_notes_count
)
{
|
issue
,
options
|
issuable_metadata
(
issue
,
options
,
:user_notes_count
)
}
expose
(
:merge_requests_count
)
{
|
issue
,
options
|
issuable_metadata
(
issue
,
options
,
:merge_requests_count
,
options
[
:current_user
])
}
expose
(
:upvotes
)
{
|
issue
,
options
|
issuable_metadata
(
issue
,
options
,
:upvotes
)
}
expose
(
:downvotes
)
{
|
issue
,
options
|
issuable_metadata
(
issue
,
options
,
:downvotes
)
}
expose
:due_date
expose
:confidential
expose
:discussion_locked
expose
:web_url
do
|
issue
|
Gitlab
::
UrlBuilder
.
build
(
issue
)
end
expose
:time_stats
,
using:
'API::Entities::IssuableTimeStats'
do
|
issue
|
issue
end
expose
:task_completion_status
end
end
end
lib/api/entities/milestone.rb
0 → 100644
View file @
b844bc75
# frozen_string_literal: true
module
API
module
Entities
class
Milestone
<
Grape
::
Entity
expose
:id
,
:iid
expose
:project_id
,
if:
->
(
entity
,
options
)
{
entity
&
.
project_id
}
expose
:group_id
,
if:
->
(
entity
,
options
)
{
entity
&
.
group_id
}
expose
:title
,
:description
expose
:state
,
:created_at
,
:updated_at
expose
:due_date
expose
:start_date
expose
:web_url
do
|
milestone
,
_options
|
Gitlab
::
UrlBuilder
.
build
(
milestone
)
end
end
end
end
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