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
98f96742
Commit
98f96742
authored
Jun 22, 2020
by
David Kim
Committed by
Nick Thomas
Jun 22, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix incorrect Batched suggestions applications
parent
7196be85
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
297 additions
and
120 deletions
+297
-120
lib/gitlab/suggestions/file_suggestion.rb
lib/gitlab/suggestions/file_suggestion.rb
+14
-39
lib/gitlab/suggestions/suggestion_set.rb
lib/gitlab/suggestions/suggestion_set.rb
+6
-16
spec/lib/gitlab/suggestions/file_suggestion_spec.rb
spec/lib/gitlab/suggestions/file_suggestion_spec.rb
+275
-62
spec/lib/gitlab/suggestions/suggestion_set_spec.rb
spec/lib/gitlab/suggestions/suggestion_set_spec.rb
+2
-3
No files found.
lib/gitlab/suggestions/file_suggestion.rb
View file @
98f96742
...
...
@@ -7,17 +7,14 @@ module Gitlab
SuggestionForDifferentFileError
=
Class
.
new
(
StandardError
)
def
initialize
@suggestions
=
[]
end
def
add_suggestion
(
new_suggestion
)
if
for_different_file?
(
new_suggestion
)
raise
SuggestionForDifferentFileError
,
'Only add suggestions for the same file.'
end
attr_reader
:file_path
attr_reader
:blob
attr_reader
:suggestions
suggestions
<<
new_suggestion
def
initialize
(
file_path
,
suggestions
)
@file_path
=
file_path
@suggestions
=
suggestions
.
sort_by
(
&
:from_line_index
)
@blob
=
suggestions
.
first
&
.
diff_file
&
.
new_blob
end
def
line_conflict?
...
...
@@ -30,18 +27,8 @@ module Gitlab
@new_content
||=
_new_content
end
def
file_path
@file_path
||=
_file_path
end
private
attr_accessor
:suggestions
def
blob
first_suggestion
&
.
diff_file
&
.
new_blob
end
def
blob_data_lines
blob
.
load_all_data!
blob
.
data
.
lines
...
...
@@ -53,31 +40,19 @@ module Gitlab
def
_new_content
current_content
.
tap
do
|
content
|
# NOTE: We need to cater for line number changes when the range is more than one line.
offset
=
0
suggestions
.
each
do
|
suggestion
|
range
=
line_range
(
suggestion
)
range
=
line_range
(
suggestion
,
offset
)
content
[
range
]
=
suggestion
.
to_content
offset
+=
range
.
count
-
1
end
end
.
join
end
def
line_range
(
suggestion
)
suggestion
.
from_line_index
..
suggestion
.
to_line_index
end
def
for_different_file?
(
suggestion
)
file_path
&&
file_path
!=
suggestion_file_path
(
suggestion
)
end
def
suggestion_file_path
(
suggestion
)
suggestion
&
.
diff_file
&
.
file_path
end
def
first_suggestion
suggestions
.
first
end
def
_file_path
suggestion_file_path
(
first_suggestion
)
def
line_range
(
suggestion
,
offset
=
0
)
(
suggestion
.
from_line_index
-
offset
)
..
(
suggestion
.
to_line_index
-
offset
)
end
def
_line_conflict?
...
...
lib/gitlab/suggestions/suggestion_set.rb
View file @
98f96742
...
...
@@ -26,10 +26,10 @@ module Gitlab
end
def
actions
@actions
||=
suggestions_per_file
.
map
do
|
file_
path
,
file_
suggestion
|
@actions
||=
suggestions_per_file
.
map
do
|
file_suggestion
|
{
action:
'update'
,
file_path:
file_path
,
file_path:
file_
suggestion
.
file_
path
,
content:
file_suggestion
.
new_content
}
end
...
...
@@ -50,19 +50,9 @@ module Gitlab
end
def
_suggestions_per_file
suggestions
.
each_with_object
({})
do
|
suggestion
,
result
|
file_path
=
suggestion
.
diff_file
.
file_path
file_suggestion
=
result
[
file_path
]
||=
FileSuggestion
.
new
file_suggestion
.
add_suggestion
(
suggestion
)
end
end
def
file_suggestions
suggestions_per_file
.
values
end
def
first_file_suggestion
file_suggestions
.
first
suggestions
.
group_by
{
|
suggestion
|
suggestion
.
diff_file
.
file_path
}
.
map
{
|
file_path
,
group
|
FileSuggestion
.
new
(
file_path
,
group
)
}
end
def
_error_message
...
...
@@ -72,7 +62,7 @@ module Gitlab
return
message
if
message
end
has_line_conflict
=
file_suggestions
.
any?
do
|
file_suggestion
|
has_line_conflict
=
suggestions_per_file
.
any?
do
|
file_suggestion
|
file_suggestion
.
line_conflict?
end
...
...
spec/lib/gitlab/suggestions/file_suggestion_spec.rb
View file @
98f96742
This diff is collapsed.
Click to expand it.
spec/lib/gitlab/suggestions/suggestion_set_spec.rb
View file @
98f96742
...
...
@@ -87,11 +87,10 @@ describe Gitlab::Suggestions::SuggestionSet do
it
'returns an array of hashes with proper key/value pairs'
do
first_action
=
suggestion_set
.
actions
.
first
file_path
,
file_suggestion
=
suggestion_set
.
send
(
:suggestions_per_file
).
first
file_suggestion
=
suggestion_set
.
send
(
:suggestions_per_file
).
first
expect
(
first_action
[
:action
]).
to
be
(
'update'
)
expect
(
first_action
[
:file_path
]).
to
eq
(
file_path
)
expect
(
first_action
[
:file_path
]).
to
eq
(
file_
suggestion
.
file_
path
)
expect
(
first_action
[
:content
]).
to
eq
(
file_suggestion
.
new_content
)
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