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
73039a0a
Commit
73039a0a
authored
Jan 31, 2020
by
Rajendra Kadam
Committed by
Stan Hu
Jan 31, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Separate snippet entities into own class files
parent
c9097f27
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
104 additions
and
69 deletions
+104
-69
changelogs/unreleased/refactoring-entities-file-8.yml
changelogs/unreleased/refactoring-entities-file-8.yml
+5
-0
lib/api/entities.rb
lib/api/entities.rb
+0
-69
lib/api/entities/basic_ref.rb
lib/api/entities/basic_ref.rb
+9
-0
lib/api/entities/branch.rb
lib/api/entities/branch.rb
+41
-0
lib/api/entities/personal_snippet.rb
lib/api/entities/personal_snippet.rb
+11
-0
lib/api/entities/project_snippet.rb
lib/api/entities/project_snippet.rb
+8
-0
lib/api/entities/snippet.rb
lib/api/entities/snippet.rb
+15
-0
lib/api/entities/tree_object.rb
lib/api/entities/tree_object.rb
+15
-0
No files found.
changelogs/unreleased/refactoring-entities-file-8.yml
0 → 100644
View file @
73039a0a
---
title
:
Separate snippet entities into own class files
merge_request
:
24183
author
:
Rajendra Kadam
type
:
added
lib/api/entities.rb
View file @
73039a0a
...
@@ -128,75 +128,6 @@ module API
...
@@ -128,75 +128,6 @@ module API
end
end
end
end
class
BasicRef
<
Grape
::
Entity
expose
:type
,
:name
end
class
Branch
<
Grape
::
Entity
expose
:name
expose
:commit
,
using:
Entities
::
Commit
do
|
repo_branch
,
options
|
options
[
:project
].
repository
.
commit
(
repo_branch
.
dereferenced_target
)
end
expose
:merged
do
|
repo_branch
,
options
|
if
options
[
:merged_branch_names
]
options
[
:merged_branch_names
].
include?
(
repo_branch
.
name
)
else
options
[
:project
].
repository
.
merged_to_root_ref?
(
repo_branch
)
end
end
expose
:protected
do
|
repo_branch
,
options
|
::
ProtectedBranch
.
protected?
(
options
[
:project
],
repo_branch
.
name
)
end
expose
:developers_can_push
do
|
repo_branch
,
options
|
::
ProtectedBranch
.
developers_can?
(
:push
,
repo_branch
.
name
,
protected_refs:
options
[
:project
].
protected_branches
)
end
expose
:developers_can_merge
do
|
repo_branch
,
options
|
::
ProtectedBranch
.
developers_can?
(
:merge
,
repo_branch
.
name
,
protected_refs:
options
[
:project
].
protected_branches
)
end
expose
:can_push
do
|
repo_branch
,
options
|
Gitlab
::
UserAccess
.
new
(
options
[
:current_user
],
project:
options
[
:project
]).
can_push_to_branch?
(
repo_branch
.
name
)
end
expose
:default
do
|
repo_branch
,
options
|
options
[
:project
].
default_branch
==
repo_branch
.
name
end
end
class
TreeObject
<
Grape
::
Entity
expose
:id
,
:name
,
:type
,
:path
expose
:mode
do
|
obj
,
options
|
filemode
=
obj
.
mode
filemode
=
"0"
+
filemode
if
filemode
.
length
<
6
filemode
end
end
class
Snippet
<
Grape
::
Entity
expose
:id
,
:title
,
:file_name
,
:description
,
:visibility
expose
:author
,
using:
Entities
::
UserBasic
expose
:updated_at
,
:created_at
expose
:project_id
expose
:web_url
do
|
snippet
|
Gitlab
::
UrlBuilder
.
build
(
snippet
)
end
end
class
ProjectSnippet
<
Snippet
end
class
PersonalSnippet
<
Snippet
expose
:raw_url
do
|
snippet
|
Gitlab
::
UrlBuilder
.
build
(
snippet
,
raw:
true
)
end
end
class
IssuableEntity
<
Grape
::
Entity
class
IssuableEntity
<
Grape
::
Entity
expose
:id
,
:iid
expose
:id
,
:iid
expose
(
:project_id
)
{
|
entity
|
entity
&
.
project
.
try
(
:id
)
}
expose
(
:project_id
)
{
|
entity
|
entity
&
.
project
.
try
(
:id
)
}
...
...
lib/api/entities/basic_ref.rb
0 → 100644
View file @
73039a0a
# frozen_string_literal: true
module
API
module
Entities
class
BasicRef
<
Grape
::
Entity
expose
:type
,
:name
end
end
end
lib/api/entities/branch.rb
0 → 100644
View file @
73039a0a
# frozen_string_literal: true
module
API
module
Entities
class
Branch
<
Grape
::
Entity
expose
:name
expose
:commit
,
using:
Entities
::
Commit
do
|
repo_branch
,
options
|
options
[
:project
].
repository
.
commit
(
repo_branch
.
dereferenced_target
)
end
expose
:merged
do
|
repo_branch
,
options
|
if
options
[
:merged_branch_names
]
options
[
:merged_branch_names
].
include?
(
repo_branch
.
name
)
else
options
[
:project
].
repository
.
merged_to_root_ref?
(
repo_branch
)
end
end
expose
:protected
do
|
repo_branch
,
options
|
::
ProtectedBranch
.
protected?
(
options
[
:project
],
repo_branch
.
name
)
end
expose
:developers_can_push
do
|
repo_branch
,
options
|
::
ProtectedBranch
.
developers_can?
(
:push
,
repo_branch
.
name
,
protected_refs:
options
[
:project
].
protected_branches
)
end
expose
:developers_can_merge
do
|
repo_branch
,
options
|
::
ProtectedBranch
.
developers_can?
(
:merge
,
repo_branch
.
name
,
protected_refs:
options
[
:project
].
protected_branches
)
end
expose
:can_push
do
|
repo_branch
,
options
|
Gitlab
::
UserAccess
.
new
(
options
[
:current_user
],
project:
options
[
:project
]).
can_push_to_branch?
(
repo_branch
.
name
)
end
expose
:default
do
|
repo_branch
,
options
|
options
[
:project
].
default_branch
==
repo_branch
.
name
end
end
end
end
lib/api/entities/personal_snippet.rb
0 → 100644
View file @
73039a0a
# frozen_string_literal: true
module
API
module
Entities
class
PersonalSnippet
<
Snippet
expose
:raw_url
do
|
snippet
|
Gitlab
::
UrlBuilder
.
build
(
snippet
,
raw:
true
)
end
end
end
end
lib/api/entities/project_snippet.rb
0 → 100644
View file @
73039a0a
# frozen_String_literal: true
module
API
module
Entities
class
ProjectSnippet
<
Entities
::
Snippet
end
end
end
lib/api/entities/snippet.rb
0 → 100644
View file @
73039a0a
# frozen_string_literal: true
module
API
module
Entities
class
Snippet
<
Grape
::
Entity
expose
:id
,
:title
,
:file_name
,
:description
,
:visibility
expose
:author
,
using:
Entities
::
UserBasic
expose
:updated_at
,
:created_at
expose
:project_id
expose
:web_url
do
|
snippet
|
Gitlab
::
UrlBuilder
.
build
(
snippet
)
end
end
end
end
lib/api/entities/tree_object.rb
0 → 100644
View file @
73039a0a
# frozen_string_literal: true
module
API
module
Entities
class
TreeObject
<
Grape
::
Entity
expose
:id
,
:name
,
:type
,
:path
expose
:mode
do
|
obj
,
options
|
filemode
=
obj
.
mode
filemode
=
"0"
+
filemode
if
filemode
.
length
<
6
filemode
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