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
3221f9f3
Commit
3221f9f3
authored
Oct 27, 2020
by
Kerri Miller
Committed by
Nick Thomas
Oct 27, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow batch_diffs to filter returned diffs by file path
parent
98c9897a
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
53 additions
and
6 deletions
+53
-6
app/controllers/projects/merge_requests/diffs_controller.rb
app/controllers/projects/merge_requests/diffs_controller.rb
+4
-1
app/models/merge_request_diff_file.rb
app/models/merge_request_diff_file.rb
+4
-0
app/serializers/paginated_diff_entity.rb
app/serializers/paginated_diff_entity.rb
+7
-2
lib/gitlab/diff/file_collection/merge_request_diff_batch.rb
lib/gitlab/diff/file_collection/merge_request_diff_batch.rb
+13
-3
spec/controllers/projects/merge_requests/diffs_controller_spec.rb
...trollers/projects/merge_requests/diffs_controller_spec.rb
+25
-0
No files found.
app/controllers/projects/merge_requests/diffs_controller.rb
View file @
3221f9f3
...
...
@@ -20,7 +20,10 @@ class Projects::MergeRequests::DiffsController < Projects::MergeRequests::Applic
end
def
diffs_batch
diffs
=
@compare
.
diffs_in_batch
(
params
[
:page
],
params
[
:per_page
],
diff_options:
diff_options
)
diff_options_hash
=
diff_options
diff_options_hash
[
:paths
]
=
params
[
:paths
]
if
params
[
:paths
]
diffs
=
@compare
.
diffs_in_batch
(
params
[
:page
],
params
[
:per_page
],
diff_options:
diff_options_hash
)
positions
=
@merge_request
.
note_positions_for_paths
(
diffs
.
diff_file_paths
,
current_user
)
environment
=
@merge_request
.
environments_for
(
current_user
,
latest:
true
).
last
...
...
app/models/merge_request_diff_file.rb
View file @
3221f9f3
...
...
@@ -8,6 +8,10 @@ class MergeRequestDiffFile < ApplicationRecord
belongs_to
:merge_request_diff
,
inverse_of: :merge_request_diff_files
alias_attribute
:index
,
:relative_order
scope
:by_paths
,
->
(
paths
)
do
where
(
"new_path in (?) OR old_path in (?)"
,
paths
,
paths
)
end
def
utf8_diff
return
''
if
diff
.
blank?
...
...
app/serializers/paginated_diff_entity.rb
View file @
3221f9f3
...
...
@@ -11,8 +11,13 @@ class PaginatedDiffEntity < Grape::Entity
expose
:diff_files
do
|
diffs
,
options
|
submodule_links
=
Gitlab
::
SubmoduleLinks
.
new
(
merge_request
.
project
.
repository
)
DiffFileEntity
.
represent
(
diffs
.
diff_files
,
options
.
merge
(
submodule_links:
submodule_links
,
code_navigation_path:
code_navigation_path
(
diffs
)))
DiffFileEntity
.
represent
(
diffs
.
diff_files
,
options
.
merge
(
submodule_links:
submodule_links
,
code_navigation_path:
code_navigation_path
(
diffs
)
)
)
end
expose
:pagination
do
...
...
lib/gitlab/diff/file_collection/merge_request_diff_batch.rb
View file @
3221f9f3
...
...
@@ -18,10 +18,8 @@ module Gitlab
def
initialize
(
merge_request_diff
,
batch_page
,
batch_size
,
diff_options
:)
super
(
merge_request_diff
,
diff_options:
diff_options
)
batch_page
||=
DEFAULT_BATCH_PAGE
batch_size
||=
DEFAULT_BATCH_SIZE
@paginated_collection
=
load_paginated_collection
(
batch_page
,
batch_size
,
diff_options
)
@paginated_collection
=
relation
.
page
(
batch_page
).
per
(
batch_size
)
@pagination_data
=
{
current_page:
@paginated_collection
.
current_page
,
next_page:
@paginated_collection
.
next_page
,
...
...
@@ -63,6 +61,18 @@ module Gitlab
def
relation
@merge_request_diff
.
merge_request_diff_files
end
def
load_paginated_collection
(
batch_page
,
batch_size
,
diff_options
)
batch_page
||=
DEFAULT_BATCH_PAGE
batch_size
||=
DEFAULT_BATCH_SIZE
paths
=
diff_options
&
.
fetch
(
:paths
,
nil
)
paginated_collection
=
relation
.
page
(
batch_page
).
per
(
batch_size
)
paginated_collection
=
paginated_collection
.
by_paths
(
paths
)
if
paths
paginated_collection
end
end
end
end
...
...
spec/controllers/projects/merge_requests/diffs_controller_spec.rb
View file @
3221f9f3
...
...
@@ -454,6 +454,31 @@ RSpec.describe Projects::MergeRequests::DiffsController do
it_behaves_like
'successful request'
end
context
'with paths param'
do
let
(
:example_file_path
)
{
"README"
}
let
(
:file_path_option
)
{
{
paths:
[
example_file_path
]
}
}
subject
do
go
(
file_path_option
)
end
it_behaves_like
'serializes diffs with expected arguments'
do
let
(
:collection
)
{
Gitlab
::
Diff
::
FileCollection
::
MergeRequestDiffBatch
}
let
(
:expected_options
)
do
collection_arguments
(
current_page:
1
,
total_pages:
1
)
end
end
it_behaves_like
'successful request'
it
'filters down the response to the expected file path'
do
subject
expect
(
json_response
[
"diff_files"
].
size
).
to
eq
(
1
)
expect
(
json_response
[
"diff_files"
].
first
[
"file_path"
]).
to
eq
(
example_file_path
)
end
end
context
'with default params'
do
subject
{
go
}
...
...
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