summaryrefslogtreecommitdiff
path: root/app/models/diff_note.rb
diff options
context:
space:
mode:
authorDouwe Maan <douwe@selenight.nl>2016-06-20 19:22:39 +0200
committerDouwe Maan <douwe@selenight.nl>2016-07-06 18:51:00 -0400
commit710c4886911682742d439b15c5a7add7ca0bd898 (patch)
tree36c238f097c9ccb8cf328f6918810e06cf131444 /app/models/diff_note.rb
parent8d7dc26d39b65b3ef6e8ec80ed5995ae307c3d3c (diff)
downloadgitlab-ce-710c4886911682742d439b15c5a7add7ca0bd898.tar.gz
Automatically update diff note positions when MR is pushed to
Diffstat (limited to 'app/models/diff_note.rb')
-rw-r--r--app/models/diff_note.rb22
1 files changed, 21 insertions, 1 deletions
diff --git a/app/models/diff_note.rb b/app/models/diff_note.rb
index 70fbcb4c4e9..881ae5d1cad 100644
--- a/app/models/diff_note.rb
+++ b/app/models/diff_note.rb
@@ -12,7 +12,7 @@ class DiffNote < Note
validate :positions_complete
validate :verify_supported
- before_validation :set_original_position, on: :create
+ before_validation :set_original_position, :update_position, on: :create
before_validation :set_line_code
class << self
@@ -71,6 +71,26 @@ class DiffNote < Note
self.position.diff_refs == diff_refs
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
def supported?