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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
710c4886
Commit
710c4886
authored
Jun 20, 2016
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Automatically update diff note positions when MR is pushed to
parent
8d7dc26d
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
94 additions
and
9 deletions
+94
-9
app/models/diff_note.rb
app/models/diff_note.rb
+21
-1
app/models/merge_request.rb
app/models/merge_request.rb
+40
-5
app/services/merge_requests/refresh_service.rb
app/services/merge_requests/refresh_service.rb
+2
-2
app/services/merge_requests/reopen_service.rb
app/services/merge_requests/reopen_service.rb
+1
-1
app/services/notes/diff_position_update_service.rb
app/services/notes/diff_position_update_service.rb
+30
-0
No files found.
app/models/diff_note.rb
View file @
710c4886
...
@@ -12,7 +12,7 @@ class DiffNote < Note
...
@@ -12,7 +12,7 @@ class DiffNote < Note
validate
:positions_complete
validate
:positions_complete
validate
:verify_supported
validate
:verify_supported
before_validation
:set_original_position
,
on: :create
before_validation
:set_original_position
,
:update_position
,
on: :create
before_validation
:set_line_code
before_validation
:set_line_code
class
<<
self
class
<<
self
...
@@ -71,6 +71,26 @@ class DiffNote < Note
...
@@ -71,6 +71,26 @@ class DiffNote < Note
self
.
position
.
diff_refs
==
diff_refs
self
.
position
.
diff_refs
==
diff_refs
end
end
def
update_position
return
unless
supported?
return
if
for_commit?
return
if
active?
Notes
::
DiffPositionUpdateService
.
new
(
self
.
project
,
nil
,
old_diff_refs:
self
.
position
.
diff_refs
,
new_diff_refs:
self
.
noteable
.
diff_refs
,
paths:
self
.
position
.
paths
).
execute
(
self
)
end
def
update_position!
update_position
&&
Gitlab
::
Timeless
.
timeless
(
self
,
&
:save
)
end
private
private
def
supported?
def
supported?
...
...
app/models/merge_request.rb
View file @
710c4886
...
@@ -288,14 +288,23 @@ class MergeRequest < ActiveRecord::Base
...
@@ -288,14 +288,23 @@ class MergeRequest < ActiveRecord::Base
def
update_merge_request_diff
def
update_merge_request_diff
if
source_branch_changed?
||
target_branch_changed?
if
source_branch_changed?
||
target_branch_changed?
reload_
code
reload_
diff
end
end
end
end
def
reload_code
def
reload_diff
if
merge_request_diff
&&
open
?
return
unless
merge_request_diff
&&
open
?
old_diff_refs
=
self
.
diff_refs
merge_request_diff
.
reload_content
merge_request_diff
.
reload_content
end
new_diff_refs
=
self
.
diff_refs
update_diff_notes_positions
(
old_diff_refs:
old_diff_refs
,
new_diff_refs:
new_diff_refs
)
end
end
def
check_if_can_be_merged
def
check_if_can_be_merged
...
@@ -646,6 +655,32 @@ class MergeRequest < ActiveRecord::Base
...
@@ -646,6 +655,32 @@ class MergeRequest < ActiveRecord::Base
diff_refs
&&
diff_refs
.
complete?
diff_refs
&&
diff_refs
.
complete?
end
end
def
update_diff_notes_positions
(
old_diff_refs
:,
new_diff_refs
:)
return
unless
support_new_diff_notes?
return
if
new_diff_refs
==
old_diff_refs
active_diff_notes
=
self
.
notes
.
diff_notes
.
select
do
|
note
|
note
.
new_diff_note?
&&
note
.
active?
(
old_diff_refs
)
end
return
if
active_diff_notes
.
empty?
paths
=
active_diff_notes
.
flat_map
{
|
n
|
n
.
diff_file
.
paths
}.
uniq
service
=
Notes
::
DiffPositionUpdateService
.
new
(
self
.
project
,
nil
,
old_diff_refs:
old_diff_refs
,
new_diff_refs:
new_diff_refs
,
paths:
paths
)
active_diff_notes
.
each
do
|
note
|
service
.
execute
(
note
)
Gitlab
::
Timeless
.
timeless
(
note
,
&
:save
)
end
end
def
keep_around_commit
def
keep_around_commit
project
.
repository
.
keep_around
(
self
.
merge_commit_sha
)
project
.
repository
.
keep_around
(
self
.
merge_commit_sha
)
end
end
...
...
app/services/merge_requests/refresh_service.rb
View file @
710c4886
...
@@ -60,7 +60,7 @@ module MergeRequests
...
@@ -60,7 +60,7 @@ module MergeRequests
merge_requests
.
each
do
|
merge_request
|
merge_requests
.
each
do
|
merge_request
|
if
merge_request
.
source_branch
==
@branch_name
||
force_push?
if
merge_request
.
source_branch
==
@branch_name
||
force_push?
merge_request
.
reload_
code
merge_request
.
reload_
diff
merge_request
.
mark_as_unchecked
merge_request
.
mark_as_unchecked
else
else
mr_commit_ids
=
merge_request
.
commits
.
map
(
&
:id
)
mr_commit_ids
=
merge_request
.
commits
.
map
(
&
:id
)
...
@@ -68,7 +68,7 @@ module MergeRequests
...
@@ -68,7 +68,7 @@ module MergeRequests
matches
=
mr_commit_ids
&
push_commit_ids
matches
=
mr_commit_ids
&
push_commit_ids
if
matches
.
any?
if
matches
.
any?
merge_request
.
reload_
code
merge_request
.
reload_
diff
merge_request
.
mark_as_unchecked
merge_request
.
mark_as_unchecked
else
else
merge_request
.
mark_as_unchecked
merge_request
.
mark_as_unchecked
...
...
app/services/merge_requests/reopen_service.rb
View file @
710c4886
...
@@ -6,7 +6,7 @@ module MergeRequests
...
@@ -6,7 +6,7 @@ module MergeRequests
create_note
(
merge_request
)
create_note
(
merge_request
)
notification_service
.
reopen_mr
(
merge_request
,
current_user
)
notification_service
.
reopen_mr
(
merge_request
,
current_user
)
execute_hooks
(
merge_request
,
'reopen'
)
execute_hooks
(
merge_request
,
'reopen'
)
merge_request
.
reload_
code
merge_request
.
reload_
diff
merge_request
.
mark_as_unchecked
merge_request
.
mark_as_unchecked
end
end
...
...
app/services/notes/diff_position_update_service.rb
0 → 100644
View file @
710c4886
module
Notes
class
DiffPositionUpdateService
<
BaseService
def
execute
(
note
)
new_position
=
tracer
.
trace
(
note
.
position
)
# Don't update the position if the type doesn't match, since that means
# the diff line commented on was changed, and the comment is now outdated
old_position
=
note
.
position
if
new_position
&&
new_position
!=
old_position
&&
new_position
.
type
==
old_position
.
type
note
.
position
=
new_position
end
note
end
private
def
tracer
@tracer
||=
Gitlab
::
Diff
::
PositionTracer
.
new
(
repository:
project
.
repository
,
old_diff_refs:
params
[
:old_diff_refs
],
new_diff_refs:
params
[
:new_diff_refs
],
paths:
params
[
:paths
]
)
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