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
48eda5a5
Commit
48eda5a5
authored
Feb 11, 2020
by
Rajendra Kadam
Committed by
Stan Hu
Feb 11, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Separate 5 classess into own class files
parent
ad890526
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
110 additions
and
80 deletions
+110
-80
changelogs/unreleased/refactoring-entities-file-14.yml
changelogs/unreleased/refactoring-entities-file-14.yml
+5
-0
lib/api/entities.rb
lib/api/entities.rb
+0
-80
lib/api/entities/event.rb
lib/api/entities/event.rb
+23
-0
lib/api/entities/namespace_basic.rb
lib/api/entities/namespace_basic.rb
+17
-0
lib/api/entities/project_group_link.rb
lib/api/entities/project_group_link.rb
+9
-0
lib/api/entities/push_event_payload.rb
lib/api/entities/push_event_payload.rb
+10
-0
lib/api/entities/todo.rb
lib/api/entities/todo.rb
+46
-0
No files found.
changelogs/unreleased/refactoring-entities-file-14.yml
0 → 100644
View file @
48eda5a5
---
title
:
Separate 5 classes into own entities files
merge_request
:
24745
author
:
Rajendra Kadam
type
:
added
lib/api/entities.rb
View file @
48eda5a5
...
@@ -129,86 +129,6 @@ module API
...
@@ -129,86 +129,6 @@ module API
end
end
end
end
class
PushEventPayload
<
Grape
::
Entity
expose
:commit_count
,
:action
,
:ref_type
,
:commit_from
,
:commit_to
,
:ref
,
:commit_title
,
:ref_count
end
class
Event
<
Grape
::
Entity
expose
:project_id
,
:action_name
expose
:target_id
,
:target_iid
,
:target_type
,
:author_id
expose
:target_title
expose
:created_at
expose
:note
,
using:
Entities
::
Note
,
if:
->
(
event
,
options
)
{
event
.
note?
}
expose
:author
,
using:
Entities
::
UserBasic
,
if:
->
(
event
,
options
)
{
event
.
author
}
expose
:push_event_payload
,
as: :push_data
,
using:
PushEventPayload
,
if:
->
(
event
,
_
)
{
event
.
push_action?
}
expose
:author_username
do
|
event
,
options
|
event
.
author
&
.
username
end
end
class
ProjectGroupLink
<
Grape
::
Entity
expose
:id
,
:project_id
,
:group_id
,
:group_access
,
:expires_at
end
class
Todo
<
Grape
::
Entity
expose
:id
expose
:project
,
using:
Entities
::
ProjectIdentity
,
if:
->
(
todo
,
_
)
{
todo
.
project_id
}
expose
:group
,
using:
'API::Entities::NamespaceBasic'
,
if:
->
(
todo
,
_
)
{
todo
.
group_id
}
expose
:author
,
using:
Entities
::
UserBasic
expose
:action_name
expose
:target_type
expose
:target
do
|
todo
,
options
|
todo_options
=
options
.
fetch
(
todo
.
target_type
,
{})
todo_target_class
(
todo
.
target_type
).
represent
(
todo
.
target
,
todo_options
)
end
expose
:target_url
do
|
todo
,
options
|
todo_target_url
(
todo
)
end
expose
:body
expose
:state
expose
:created_at
def
todo_target_class
(
target_type
)
# false as second argument prevents looking up in module hierarchy
# see also https://gitlab.com/gitlab-org/gitlab-foss/issues/59719
::
API
::
Entities
.
const_get
(
target_type
,
false
)
end
def
todo_target_url
(
todo
)
target_type
=
todo
.
target_type
.
underscore
target_url
=
"
#{
todo
.
resource_parent
.
class
.
to_s
.
underscore
}
_
#{
target_type
}
_url"
Gitlab
::
Routing
.
url_helpers
.
public_send
(
target_url
,
todo
.
resource_parent
,
todo
.
target
,
anchor:
todo_target_anchor
(
todo
))
# rubocop:disable GitlabSecurity/PublicSend
end
def
todo_target_anchor
(
todo
)
"note_
#{
todo
.
note_id
}
"
if
todo
.
note_id?
end
end
class
NamespaceBasic
<
Grape
::
Entity
expose
:id
,
:name
,
:path
,
:kind
,
:full_path
,
:parent_id
,
:avatar_url
expose
:web_url
do
|
namespace
|
if
namespace
.
user?
Gitlab
::
Routing
.
url_helpers
.
user_url
(
namespace
.
owner
)
else
namespace
.
web_url
end
end
end
class
Namespace
<
NamespaceBasic
class
Namespace
<
NamespaceBasic
expose
:members_count_with_descendants
,
if:
->
(
namespace
,
opts
)
{
expose_members_count_with_descendants?
(
namespace
,
opts
)
}
do
|
namespace
,
_
|
expose
:members_count_with_descendants
,
if:
->
(
namespace
,
opts
)
{
expose_members_count_with_descendants?
(
namespace
,
opts
)
}
do
|
namespace
,
_
|
namespace
.
users_with_descendants
.
count
namespace
.
users_with_descendants
.
count
...
...
lib/api/entities/event.rb
0 → 100644
View file @
48eda5a5
# frozen_string_literal: true
module
API
module
Entities
class
Event
<
Grape
::
Entity
expose
:project_id
,
:action_name
expose
:target_id
,
:target_iid
,
:target_type
,
:author_id
expose
:target_title
expose
:created_at
expose
:note
,
using:
Entities
::
Note
,
if:
->
(
event
,
options
)
{
event
.
note?
}
expose
:author
,
using:
Entities
::
UserBasic
,
if:
->
(
event
,
options
)
{
event
.
author
}
expose
:push_event_payload
,
as: :push_data
,
using:
Entities
::
PushEventPayload
,
if:
->
(
event
,
_
)
{
event
.
push_action?
}
expose
:author_username
do
|
event
,
options
|
event
.
author
&
.
username
end
end
end
end
lib/api/entities/namespace_basic.rb
0 → 100644
View file @
48eda5a5
# frozen_string_literal: true
module
API
module
Entities
class
NamespaceBasic
<
Grape
::
Entity
expose
:id
,
:name
,
:path
,
:kind
,
:full_path
,
:parent_id
,
:avatar_url
expose
:web_url
do
|
namespace
|
if
namespace
.
user?
Gitlab
::
Routing
.
url_helpers
.
user_url
(
namespace
.
owner
)
else
namespace
.
web_url
end
end
end
end
end
lib/api/entities/project_group_link.rb
0 → 100644
View file @
48eda5a5
# frozen_string_literal: true
module
API
module
Entities
class
ProjectGroupLink
<
Grape
::
Entity
expose
:id
,
:project_id
,
:group_id
,
:group_access
,
:expires_at
end
end
end
lib/api/entities/push_event_payload.rb
0 → 100644
View file @
48eda5a5
# frozen_string_literal: true
module
API
module
Entities
class
PushEventPayload
<
Grape
::
Entity
expose
:commit_count
,
:action
,
:ref_type
,
:commit_from
,
:commit_to
,
:ref
,
:commit_title
,
:ref_count
end
end
end
lib/api/entities/todo.rb
0 → 100644
View file @
48eda5a5
# frozen_string_literal: true
module
API
module
Entities
class
Todo
<
Grape
::
Entity
expose
:id
expose
:project
,
using:
Entities
::
ProjectIdentity
,
if:
->
(
todo
,
_
)
{
todo
.
project_id
}
expose
:group
,
using:
'API::Entities::NamespaceBasic'
,
if:
->
(
todo
,
_
)
{
todo
.
group_id
}
expose
:author
,
using:
Entities
::
UserBasic
expose
:action_name
expose
:target_type
expose
:target
do
|
todo
,
options
|
todo_options
=
options
.
fetch
(
todo
.
target_type
,
{})
todo_target_class
(
todo
.
target_type
).
represent
(
todo
.
target
,
todo_options
)
end
expose
:target_url
do
|
todo
,
options
|
todo_target_url
(
todo
)
end
expose
:body
expose
:state
expose
:created_at
def
todo_target_class
(
target_type
)
# false as second argument prevents looking up in module hierarchy
# see also https://gitlab.com/gitlab-org/gitlab-foss/issues/59719
::
API
::
Entities
.
const_get
(
target_type
,
false
)
end
def
todo_target_url
(
todo
)
target_type
=
todo
.
target_type
.
underscore
target_url
=
"
#{
todo
.
resource_parent
.
class
.
to_s
.
underscore
}
_
#{
target_type
}
_url"
Gitlab
::
Routing
.
url_helpers
.
public_send
(
target_url
,
todo
.
resource_parent
,
todo
.
target
,
anchor:
todo_target_anchor
(
todo
))
# rubocop:disable GitlabSecurity/PublicSend
end
def
todo_target_anchor
(
todo
)
"note_
#{
todo
.
note_id
}
"
if
todo
.
note_id?
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