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
708cc8ad
Commit
708cc8ad
authored
Feb 02, 2020
by
Rajendra Kadam
Committed by
Stan Hu
Feb 02, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Separate protected and issuable entities into own class files
parent
e83f1da7
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
89 additions
and
54 deletions
+89
-54
changelogs/unreleased/refactoring-entities-file-9.yml
changelogs/unreleased/refactoring-entities-file-9.yml
+5
-0
lib/api/entities.rb
lib/api/entities.rb
+0
-54
lib/api/entities/diff.rb
lib/api/entities/diff.rb
+13
-0
lib/api/entities/issuable_entity.rb
lib/api/entities/issuable_entity.rb
+18
-0
lib/api/entities/issuable_references.rb
lib/api/entities/issuable_references.rb
+19
-0
lib/api/entities/protected_branch.rb
lib/api/entities/protected_branch.rb
+12
-0
lib/api/entities/protected_ref_access.rb
lib/api/entities/protected_ref_access.rb
+12
-0
lib/api/entities/protected_tag.rb
lib/api/entities/protected_tag.rb
+10
-0
No files found.
changelogs/unreleased/refactoring-entities-file-9.yml
0 → 100644
View file @
708cc8ad
---
title
:
Separate protected and issuable entities into own class files
merge_request
:
24221
author
:
Rajendra Kadam
type
:
added
lib/api/entities.rb
View file @
708cc8ad
...
...
@@ -128,60 +128,6 @@ module API
end
end
class
IssuableEntity
<
Grape
::
Entity
expose
:id
,
:iid
expose
(
:project_id
)
{
|
entity
|
entity
&
.
project
.
try
(
:id
)
}
expose
:title
,
:description
expose
:state
,
:created_at
,
:updated_at
# Avoids an N+1 query when metadata is included
def
issuable_metadata
(
subject
,
options
,
method
,
args
=
nil
)
cached_subject
=
options
.
dig
(
:issuable_metadata
,
subject
.
id
)
(
cached_subject
||
subject
).
public_send
(
method
,
*
args
)
# rubocop: disable GitlabSecurity/PublicSend
end
end
class
IssuableReferences
<
Grape
::
Entity
expose
:short
do
|
issuable
|
issuable
.
to_reference
end
expose
:relative
do
|
issuable
,
options
|
issuable
.
to_reference
(
options
[
:group
]
||
options
[
:project
])
end
expose
:full
do
|
issuable
|
issuable
.
to_reference
(
full:
true
)
end
end
class
Diff
<
Grape
::
Entity
expose
:old_path
,
:new_path
,
:a_mode
,
:b_mode
expose
:new_file?
,
as: :new_file
expose
:renamed_file?
,
as: :renamed_file
expose
:deleted_file?
,
as: :deleted_file
expose
:json_safe_diff
,
as: :diff
end
class
ProtectedRefAccess
<
Grape
::
Entity
expose
:access_level
expose
:access_level_description
do
|
protected_ref_access
|
protected_ref_access
.
humanize
end
end
class
ProtectedBranch
<
Grape
::
Entity
expose
:id
expose
:name
expose
:push_access_levels
,
using:
Entities
::
ProtectedRefAccess
expose
:merge_access_levels
,
using:
Entities
::
ProtectedRefAccess
end
class
ProtectedTag
<
Grape
::
Entity
expose
:name
expose
:create_access_levels
,
using:
Entities
::
ProtectedRefAccess
end
class
Milestone
<
Grape
::
Entity
expose
:id
,
:iid
expose
:project_id
,
if:
->
(
entity
,
options
)
{
entity
&
.
project_id
}
...
...
lib/api/entities/diff.rb
0 → 100644
View file @
708cc8ad
# frozen_string_literal: true
module
API
module
Entities
class
Diff
<
Grape
::
Entity
expose
:old_path
,
:new_path
,
:a_mode
,
:b_mode
expose
:new_file?
,
as: :new_file
expose
:renamed_file?
,
as: :renamed_file
expose
:deleted_file?
,
as: :deleted_file
expose
:json_safe_diff
,
as: :diff
end
end
end
lib/api/entities/issuable_entity.rb
0 → 100644
View file @
708cc8ad
# frozen_string_literal: true
module
API
module
Entities
class
IssuableEntity
<
Grape
::
Entity
expose
:id
,
:iid
expose
(
:project_id
)
{
|
entity
|
entity
&
.
project
.
try
(
:id
)
}
expose
:title
,
:description
expose
:state
,
:created_at
,
:updated_at
# Avoids an N+1 query when metadata is included
def
issuable_metadata
(
subject
,
options
,
method
,
args
=
nil
)
cached_subject
=
options
.
dig
(
:issuable_metadata
,
subject
.
id
)
(
cached_subject
||
subject
).
public_send
(
method
,
*
args
)
# rubocop: disable GitlabSecurity/PublicSend
end
end
end
end
lib/api/entities/issuable_references.rb
0 → 100644
View file @
708cc8ad
# frozen_string_literal: true
module
API
module
Entities
class
IssuableReferences
<
Grape
::
Entity
expose
:short
do
|
issuable
|
issuable
.
to_reference
end
expose
:relative
do
|
issuable
,
options
|
issuable
.
to_reference
(
options
[
:group
]
||
options
[
:project
])
end
expose
:full
do
|
issuable
|
issuable
.
to_reference
(
full:
true
)
end
end
end
end
lib/api/entities/protected_branch.rb
0 → 100644
View file @
708cc8ad
# frozen_string_literal: true
module
API
module
Entities
class
ProtectedBranch
<
Grape
::
Entity
expose
:id
expose
:name
expose
:push_access_levels
,
using:
Entities
::
ProtectedRefAccess
expose
:merge_access_levels
,
using:
Entities
::
ProtectedRefAccess
end
end
end
lib/api/entities/protected_ref_access.rb
0 → 100644
View file @
708cc8ad
# frozen_string_literal: true
module
API
module
Entities
class
ProtectedRefAccess
<
Grape
::
Entity
expose
:access_level
expose
:access_level_description
do
|
protected_ref_access
|
protected_ref_access
.
humanize
end
end
end
end
lib/api/entities/protected_tag.rb
0 → 100644
View file @
708cc8ad
# frozen_string_literal: true
module
API
module
Entities
class
ProtectedTag
<
Grape
::
Entity
expose
:name
expose
:create_access_levels
,
using:
Entities
::
ProtectedRefAccess
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