summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2015-04-15 15:56:21 +0200
committerDouwe Maan <douwe@gitlab.com>2015-04-15 17:57:31 +0200
commit959ebbcade63423048320daaa814634c41842a36 (patch)
treefb2f8392d60cdabe6ed9b0ad47a43909b3866762 /app/models
parentb73ffbd3cb7dd89f54351b74e0cf4d1df63f0310 (diff)
downloadgitlab-ce-959ebbcade63423048320daaa814634c41842a36.tar.gz
Clean up code around commit mentions.
Diffstat (limited to 'app/models')
-rw-r--r--app/models/commit.rb19
-rw-r--r--app/models/concerns/mentionable.rb4
-rw-r--r--app/models/note.rb8
3 files changed, 21 insertions, 10 deletions
diff --git a/app/models/commit.rb b/app/models/commit.rb
index 006fa62c8f9..f54696c378c 100644
--- a/app/models/commit.rb
+++ b/app/models/commit.rb
@@ -134,6 +134,25 @@ class Commit
User.find_for_commit(committer_email, committer_name)
end
+ def participants(project, current_user = nil)
+ users = []
+ users << author
+ users << committer
+ mentions = []
+ mentions << self.mentioned_users(current_user, project)
+
+ notes(project).each do |note|
+ users << note.author
+ mentions << note.mentioned_users(current_user, project)
+ end
+
+ users.concat(mentions.reduce([], :|)).uniq
+ end
+
+ def notes(project)
+ project.notes.for_commit_id(self.id)
+ end
+
def method_missing(m, *args, &block)
@raw.send(m, *args, &block)
end
diff --git a/app/models/concerns/mentionable.rb b/app/models/concerns/mentionable.rb
index b7882a2bb16..acd9a1edc48 100644
--- a/app/models/concerns/mentionable.rb
+++ b/app/models/concerns/mentionable.rb
@@ -42,10 +42,10 @@ module Mentionable
Note.cross_reference_exists?(target, local_reference)
end
- def mentioned_users(current_user = nil)
+ def mentioned_users(current_user = nil, p = project)
return [] if mentionable_text.blank?
- ext = Gitlab::ReferenceExtractor.new(self.project, current_user)
+ ext = Gitlab::ReferenceExtractor.new(p, current_user)
ext.analyze(mentionable_text)
ext.users.uniq
end
diff --git a/app/models/note.rb b/app/models/note.rb
index fdab4517df3..8ebeb371352 100644
--- a/app/models/note.rb
+++ b/app/models/note.rb
@@ -327,14 +327,6 @@ class Note < ActiveRecord::Base
current_application_settings.max_attachment_size.megabytes.to_i
end
- def commit_author
- @commit_author ||=
- project.team.users.find_by(email: noteable.author_email) ||
- project.team.users.find_by(name: noteable.author_name)
- rescue
- nil
- end
-
def cross_reference?
note.start_with?(self.class.cross_reference_note_prefix)
end