summaryrefslogtreecommitdiff
path: root/app/models/note.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/note.rb')
-rw-r--r--app/models/note.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/app/models/note.rb b/app/models/note.rb
index 561391a55b6..670a981a78f 100644
--- a/app/models/note.rb
+++ b/app/models/note.rb
@@ -290,6 +290,19 @@ class Note < ApplicationRecord
@commit ||= project.commit(commit_id) if commit_id.present?
end
+ # Notes on merge requests and commits can be traced back to one or several
+ # MRs. This method returns a relation if the note is for one of these types,
+ # or nil if it is a note on some other object.
+ def merge_requests
+ if for_commit?
+ project.merge_requests.by_commit_sha(commit_id)
+ elsif for_merge_request?
+ MergeRequest.id_in(noteable_id)
+ else
+ nil
+ end
+ end
+
# override to return commits, which are not active record
def noteable
return commit if for_commit?