summaryrefslogtreecommitdiff
path: root/app/models/diff_note.rb
diff options
context:
space:
mode:
authorDouwe Maan <douwe@selenight.nl>2017-06-29 16:19:09 -0500
committermicael.bergeron <micaelbergeron@gmail.com>2017-12-07 09:01:19 -0500
commite4eba908cd85c3ad7b9861c3edbd3c81623242a0 (patch)
tree51704b1351f78fcd3de4a59399b10c5c3f64d70d /app/models/diff_note.rb
parent17542a7895f288b8e7bc92836039f4dcbb7c17d2 (diff)
downloadgitlab-ce-e4eba908cd85c3ad7b9861c3edbd3c81623242a0.tar.gz
Allow commenting on individual commits inside an MR
Diffstat (limited to 'app/models/diff_note.rb')
-rw-r--r--app/models/diff_note.rb7
1 files changed, 7 insertions, 0 deletions
diff --git a/app/models/diff_note.rb b/app/models/diff_note.rb
index ae5f138a920..b53d44cda95 100644
--- a/app/models/diff_note.rb
+++ b/app/models/diff_note.rb
@@ -17,6 +17,7 @@ class DiffNote < Note
validates :noteable_type, inclusion: { in: NOTEABLE_TYPES }
validate :positions_complete
validate :verify_supported
+ validate :diff_refs_match_commit, if: :for_commit?
before_validation :set_original_position, on: :create
before_validation :update_position, on: :create, if: :on_text?
@@ -135,6 +136,12 @@ class DiffNote < Note
errors.add(:position, "is invalid")
end
+ def diff_refs_match_commit
+ return if self.original_position.diff_refs == self.commit.diff_refs
+
+ errors.add(:commit_id, 'does not match the diff refs')
+ end
+
def keep_around_commits
project.repository.keep_around(self.original_position.base_sha)
project.repository.keep_around(self.original_position.start_sha)