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
371a8983
Commit
371a8983
authored
Feb 05, 2020
by
Rajendra Kadam
Committed by
Stan Hu
Feb 05, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Separate merge request entities into own class files
parent
e5f8b338
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
212 additions
and
172 deletions
+212
-172
changelogs/unreleased/refactoring-entities-file-11.yml
changelogs/unreleased/refactoring-entities-file-11.yml
+5
-0
lib/api/entities.rb
lib/api/entities.rb
+0
-172
lib/api/entities/merge_request.rb
lib/api/entities/merge_request.rb
+53
-0
lib/api/entities/merge_request_basic.rb
lib/api/entities/merge_request_basic.rb
+94
-0
lib/api/entities/merge_request_changes.rb
lib/api/entities/merge_request_changes.rb
+11
-0
lib/api/entities/merge_request_diff.rb
lib/api/entities/merge_request_diff.rb
+10
-0
lib/api/entities/merge_request_diff_full.rb
lib/api/entities/merge_request_diff_full.rb
+13
-0
lib/api/entities/merge_request_simple.rb
lib/api/entities/merge_request_simple.rb
+12
-0
lib/api/entities/pipeline_basic.rb
lib/api/entities/pipeline_basic.rb
+14
-0
No files found.
changelogs/unreleased/refactoring-entities-file-11.yml
0 → 100644
View file @
371a8983
---
title
:
Separate merge request entities into own class files
merge_request
:
24373
author
:
Rajendra Kadam
type
:
added
lib/api/entities.rb
View file @
371a8983
...
...
@@ -128,178 +128,6 @@ module API
end
end
class
PipelineBasic
<
Grape
::
Entity
expose
:id
,
:sha
,
:ref
,
:status
expose
:created_at
,
:updated_at
expose
:web_url
do
|
pipeline
,
_options
|
Gitlab
::
Routing
.
url_helpers
.
project_pipeline_url
(
pipeline
.
project
,
pipeline
)
end
end
class
MergeRequestSimple
<
IssuableEntity
expose
:title
expose
:web_url
do
|
merge_request
,
options
|
Gitlab
::
UrlBuilder
.
build
(
merge_request
)
end
end
class
MergeRequestBasic
<
IssuableEntity
expose
:merged_by
,
using:
Entities
::
UserBasic
do
|
merge_request
,
_options
|
merge_request
.
metrics
&
.
merged_by
end
expose
:merged_at
do
|
merge_request
,
_options
|
merge_request
.
metrics
&
.
merged_at
end
expose
:closed_by
,
using:
Entities
::
UserBasic
do
|
merge_request
,
_options
|
merge_request
.
metrics
&
.
latest_closed_by
end
expose
:closed_at
do
|
merge_request
,
_options
|
merge_request
.
metrics
&
.
latest_closed_at
end
expose
:title_html
,
if:
->
(
_
,
options
)
{
options
[
:render_html
]
}
do
|
entity
|
MarkupHelper
.
markdown_field
(
entity
,
:title
)
end
expose
:description_html
,
if:
->
(
_
,
options
)
{
options
[
:render_html
]
}
do
|
entity
|
MarkupHelper
.
markdown_field
(
entity
,
:description
)
end
expose
:target_branch
,
:source_branch
expose
(
:user_notes_count
)
{
|
merge_request
,
options
|
issuable_metadata
(
merge_request
,
options
,
:user_notes_count
)
}
expose
(
:upvotes
)
{
|
merge_request
,
options
|
issuable_metadata
(
merge_request
,
options
,
:upvotes
)
}
expose
(
:downvotes
)
{
|
merge_request
,
options
|
issuable_metadata
(
merge_request
,
options
,
:downvotes
)
}
expose
:assignee
,
using:
::
API
::
Entities
::
UserBasic
do
|
merge_request
|
merge_request
.
assignee
end
expose
:author
,
:assignees
,
using:
Entities
::
UserBasic
expose
:source_project_id
,
:target_project_id
expose
:labels
do
|
merge_request
,
options
|
if
options
[
:with_labels_details
]
::
API
::
Entities
::
LabelBasic
.
represent
(
merge_request
.
labels
.
sort_by
(
&
:title
))
else
merge_request
.
labels
.
map
(
&
:title
).
sort
end
end
expose
:work_in_progress?
,
as: :work_in_progress
expose
:milestone
,
using:
Entities
::
Milestone
expose
:merge_when_pipeline_succeeds
# Ideally we should deprecate `MergeRequest#merge_status` exposure and
# use `MergeRequest#mergeable?` instead (boolean).
# See https://gitlab.com/gitlab-org/gitlab-foss/issues/42344 for more
# information.
expose
:merge_status
do
|
merge_request
|
merge_request
.
check_mergeability
(
async:
true
)
merge_request
.
merge_status
end
expose
:diff_head_sha
,
as: :sha
expose
:merge_commit_sha
expose
:squash_commit_sha
expose
:discussion_locked
expose
:should_remove_source_branch?
,
as: :should_remove_source_branch
expose
:force_remove_source_branch?
,
as: :force_remove_source_branch
expose
:allow_collaboration
,
if:
->
(
merge_request
,
_
)
{
merge_request
.
for_fork?
}
# Deprecated
expose
:allow_collaboration
,
as: :allow_maintainer_to_push
,
if:
->
(
merge_request
,
_
)
{
merge_request
.
for_fork?
}
# reference is deprecated in favour of references
# Introduced [Gitlab 12.6](https://gitlab.com/gitlab-org/gitlab/merge_requests/20354)
expose
:reference
do
|
merge_request
,
options
|
merge_request
.
to_reference
(
options
[
:project
])
end
expose
:references
,
with:
IssuableReferences
do
|
merge_request
|
merge_request
end
expose
:web_url
do
|
merge_request
|
Gitlab
::
UrlBuilder
.
build
(
merge_request
)
end
expose
:time_stats
,
using:
'API::Entities::IssuableTimeStats'
do
|
merge_request
|
merge_request
end
expose
:squash
expose
:task_completion_status
expose
:cannot_be_merged?
,
as: :has_conflicts
expose
:mergeable_discussions_state?
,
as: :blocking_discussions_resolved
end
class
MergeRequest
<
MergeRequestBasic
expose
:subscribed
,
if:
->
(
_
,
options
)
{
options
.
fetch
(
:include_subscribed
,
true
)
}
do
|
merge_request
,
options
|
merge_request
.
subscribed?
(
options
[
:current_user
],
options
[
:project
])
end
expose
:changes_count
do
|
merge_request
,
_options
|
merge_request
.
merge_request_diff
.
real_size
end
expose
:latest_build_started_at
,
if:
->
(
_
,
options
)
{
build_available?
(
options
)
}
do
|
merge_request
,
_options
|
merge_request
.
metrics
&
.
latest_build_started_at
end
expose
:latest_build_finished_at
,
if:
->
(
_
,
options
)
{
build_available?
(
options
)
}
do
|
merge_request
,
_options
|
merge_request
.
metrics
&
.
latest_build_finished_at
end
expose
:first_deployed_to_production_at
,
if:
->
(
_
,
options
)
{
build_available?
(
options
)
}
do
|
merge_request
,
_options
|
merge_request
.
metrics
&
.
first_deployed_to_production_at
end
expose
:pipeline
,
using:
Entities
::
PipelineBasic
,
if:
->
(
_
,
options
)
{
build_available?
(
options
)
}
do
|
merge_request
,
_options
|
merge_request
.
metrics
&
.
pipeline
end
expose
:head_pipeline
,
using:
'API::Entities::Pipeline'
,
if:
->
(
_
,
options
)
do
Ability
.
allowed?
(
options
[
:current_user
],
:read_pipeline
,
options
[
:project
])
end
expose
:diff_refs
,
using:
Entities
::
DiffRefs
# Allow the status of a rebase to be determined
expose
:merge_error
expose
:rebase_in_progress?
,
as: :rebase_in_progress
,
if:
->
(
_
,
options
)
{
options
[
:include_rebase_in_progress
]
}
expose
:diverged_commits_count
,
as: :diverged_commits_count
,
if:
->
(
_
,
options
)
{
options
[
:include_diverged_commits_count
]
}
def
build_available?
(
options
)
options
[
:project
]
&
.
feature_available?
(
:builds
,
options
[
:current_user
])
end
expose
:user
do
expose
:can_merge
do
|
merge_request
,
options
|
merge_request
.
can_be_merged_by?
(
options
[
:current_user
])
end
end
end
class
MergeRequestChanges
<
MergeRequest
expose
:diffs
,
as: :changes
,
using:
Entities
::
Diff
do
|
compare
,
_
|
compare
.
raw_diffs
(
limits:
false
).
to_a
end
end
class
MergeRequestDiff
<
Grape
::
Entity
expose
:id
,
:head_commit_sha
,
:base_commit_sha
,
:start_commit_sha
,
:created_at
,
:merge_request_id
,
:state
,
:real_size
end
class
MergeRequestDiffFull
<
MergeRequestDiff
expose
:commits
,
using:
Entities
::
Commit
expose
:diffs
,
using:
Entities
::
Diff
do
|
compare
,
_
|
compare
.
raw_diffs
(
limits:
false
).
to_a
end
end
class
SSHKey
<
Grape
::
Entity
expose
:id
,
:title
,
:key
,
:created_at
end
...
...
lib/api/entities/merge_request.rb
0 → 100644
View file @
371a8983
# frozen_string_literal: true
module
API
module
Entities
class
MergeRequest
<
MergeRequestBasic
expose
:subscribed
,
if:
->
(
_
,
options
)
{
options
.
fetch
(
:include_subscribed
,
true
)
}
do
|
merge_request
,
options
|
merge_request
.
subscribed?
(
options
[
:current_user
],
options
[
:project
])
end
expose
:changes_count
do
|
merge_request
,
_options
|
merge_request
.
merge_request_diff
.
real_size
end
expose
:latest_build_started_at
,
if:
->
(
_
,
options
)
{
build_available?
(
options
)
}
do
|
merge_request
,
_options
|
merge_request
.
metrics
&
.
latest_build_started_at
end
expose
:latest_build_finished_at
,
if:
->
(
_
,
options
)
{
build_available?
(
options
)
}
do
|
merge_request
,
_options
|
merge_request
.
metrics
&
.
latest_build_finished_at
end
expose
:first_deployed_to_production_at
,
if:
->
(
_
,
options
)
{
build_available?
(
options
)
}
do
|
merge_request
,
_options
|
merge_request
.
metrics
&
.
first_deployed_to_production_at
end
expose
:pipeline
,
using:
Entities
::
PipelineBasic
,
if:
->
(
_
,
options
)
{
build_available?
(
options
)
}
do
|
merge_request
,
_options
|
merge_request
.
metrics
&
.
pipeline
end
expose
:head_pipeline
,
using:
'API::Entities::Pipeline'
,
if:
->
(
_
,
options
)
do
Ability
.
allowed?
(
options
[
:current_user
],
:read_pipeline
,
options
[
:project
])
end
expose
:diff_refs
,
using:
Entities
::
DiffRefs
# Allow the status of a rebase to be determined
expose
:merge_error
expose
:rebase_in_progress?
,
as: :rebase_in_progress
,
if:
->
(
_
,
options
)
{
options
[
:include_rebase_in_progress
]
}
expose
:diverged_commits_count
,
as: :diverged_commits_count
,
if:
->
(
_
,
options
)
{
options
[
:include_diverged_commits_count
]
}
def
build_available?
(
options
)
options
[
:project
]
&
.
feature_available?
(
:builds
,
options
[
:current_user
])
end
expose
:user
do
expose
:can_merge
do
|
merge_request
,
options
|
merge_request
.
can_be_merged_by?
(
options
[
:current_user
])
end
end
end
end
end
lib/api/entities/merge_request_basic.rb
0 → 100644
View file @
371a8983
# frozen_string_literal: true
module
API
module
Entities
class
MergeRequestBasic
<
IssuableEntity
expose
:merged_by
,
using:
Entities
::
UserBasic
do
|
merge_request
,
_options
|
merge_request
.
metrics
&
.
merged_by
end
expose
:merged_at
do
|
merge_request
,
_options
|
merge_request
.
metrics
&
.
merged_at
end
expose
:closed_by
,
using:
Entities
::
UserBasic
do
|
merge_request
,
_options
|
merge_request
.
metrics
&
.
latest_closed_by
end
expose
:closed_at
do
|
merge_request
,
_options
|
merge_request
.
metrics
&
.
latest_closed_at
end
expose
:title_html
,
if:
->
(
_
,
options
)
{
options
[
:render_html
]
}
do
|
entity
|
MarkupHelper
.
markdown_field
(
entity
,
:title
)
end
expose
:description_html
,
if:
->
(
_
,
options
)
{
options
[
:render_html
]
}
do
|
entity
|
MarkupHelper
.
markdown_field
(
entity
,
:description
)
end
expose
:target_branch
,
:source_branch
expose
(
:user_notes_count
)
{
|
merge_request
,
options
|
issuable_metadata
(
merge_request
,
options
,
:user_notes_count
)
}
expose
(
:upvotes
)
{
|
merge_request
,
options
|
issuable_metadata
(
merge_request
,
options
,
:upvotes
)
}
expose
(
:downvotes
)
{
|
merge_request
,
options
|
issuable_metadata
(
merge_request
,
options
,
:downvotes
)
}
expose
:assignee
,
using:
::
API
::
Entities
::
UserBasic
do
|
merge_request
|
merge_request
.
assignee
end
expose
:author
,
:assignees
,
using:
Entities
::
UserBasic
expose
:source_project_id
,
:target_project_id
expose
:labels
do
|
merge_request
,
options
|
if
options
[
:with_labels_details
]
::
API
::
Entities
::
LabelBasic
.
represent
(
merge_request
.
labels
.
sort_by
(
&
:title
))
else
merge_request
.
labels
.
map
(
&
:title
).
sort
end
end
expose
:work_in_progress?
,
as: :work_in_progress
expose
:milestone
,
using:
Entities
::
Milestone
expose
:merge_when_pipeline_succeeds
# Ideally we should deprecate `MergeRequest#merge_status` exposure and
# use `MergeRequest#mergeable?` instead (boolean).
# See https://gitlab.com/gitlab-org/gitlab-foss/issues/42344 for more
# information.
expose
:merge_status
do
|
merge_request
|
merge_request
.
check_mergeability
(
async:
true
)
merge_request
.
merge_status
end
expose
:diff_head_sha
,
as: :sha
expose
:merge_commit_sha
expose
:squash_commit_sha
expose
:discussion_locked
expose
:should_remove_source_branch?
,
as: :should_remove_source_branch
expose
:force_remove_source_branch?
,
as: :force_remove_source_branch
expose
:allow_collaboration
,
if:
->
(
merge_request
,
_
)
{
merge_request
.
for_fork?
}
# Deprecated
expose
:allow_collaboration
,
as: :allow_maintainer_to_push
,
if:
->
(
merge_request
,
_
)
{
merge_request
.
for_fork?
}
# reference is deprecated in favour of references
# Introduced [Gitlab 12.6](https://gitlab.com/gitlab-org/gitlab/merge_requests/20354)
expose
:reference
do
|
merge_request
,
options
|
merge_request
.
to_reference
(
options
[
:project
])
end
expose
:references
,
with:
IssuableReferences
do
|
merge_request
|
merge_request
end
expose
:web_url
do
|
merge_request
|
Gitlab
::
UrlBuilder
.
build
(
merge_request
)
end
expose
:time_stats
,
using:
'API::Entities::IssuableTimeStats'
do
|
merge_request
|
merge_request
end
expose
:squash
expose
:task_completion_status
expose
:cannot_be_merged?
,
as: :has_conflicts
expose
:mergeable_discussions_state?
,
as: :blocking_discussions_resolved
end
end
end
lib/api/entities/merge_request_changes.rb
0 → 100644
View file @
371a8983
# frozen_string_literal: true
module
API
module
Entities
class
MergeRequestChanges
<
MergeRequest
expose
:diffs
,
as: :changes
,
using:
Entities
::
Diff
do
|
compare
,
_
|
compare
.
raw_diffs
(
limits:
false
).
to_a
end
end
end
end
lib/api/entities/merge_request_diff.rb
0 → 100644
View file @
371a8983
# frozen_string_literal: true
module
API
module
Entities
class
MergeRequestDiff
<
Grape
::
Entity
expose
:id
,
:head_commit_sha
,
:base_commit_sha
,
:start_commit_sha
,
:created_at
,
:merge_request_id
,
:state
,
:real_size
end
end
end
lib/api/entities/merge_request_diff_full.rb
0 → 100644
View file @
371a8983
# frozen_string_literal: true
module
API
module
Entities
class
MergeRequestDiffFull
<
MergeRequestDiff
expose
:commits
,
using:
Entities
::
Commit
expose
:diffs
,
using:
Entities
::
Diff
do
|
compare
,
_
|
compare
.
raw_diffs
(
limits:
false
).
to_a
end
end
end
end
lib/api/entities/merge_request_simple.rb
0 → 100644
View file @
371a8983
# frozen_string_literal: true
module
API
module
Entities
class
MergeRequestSimple
<
IssuableEntity
expose
:title
expose
:web_url
do
|
merge_request
,
options
|
Gitlab
::
UrlBuilder
.
build
(
merge_request
)
end
end
end
end
lib/api/entities/pipeline_basic.rb
0 → 100644
View file @
371a8983
# frozen_string_literal: true
module
API
module
Entities
class
PipelineBasic
<
Grape
::
Entity
expose
:id
,
:sha
,
:ref
,
:status
expose
:created_at
,
:updated_at
expose
:web_url
do
|
pipeline
,
_options
|
Gitlab
::
Routing
.
url_helpers
.
project_pipeline_url
(
pipeline
.
project
,
pipeline
)
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