summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2015-04-17 11:03:33 +0200
committerDouwe Maan <douwe@gitlab.com>2015-04-17 11:03:33 +0200
commit630e879066156e8593a8b42b531ef727227c60bf (patch)
tree287b45affe4feb4129a10f2dbf379c3ce9c77fbf
parent990b476faae2720321d9ad604fab52efc25bf82f (diff)
downloadgitlab-ce-630e879066156e8593a8b42b531ef727227c60bf.tar.gz
Clean up code somewhat.better-commit-mentions
-rw-r--r--app/models/commit.rb7
-rw-r--r--app/models/concerns/issuable.rb9
-rw-r--r--app/models/snippet.rb6
-rw-r--r--app/services/projects/participants_service.rb28
4 files changed, 24 insertions, 26 deletions
diff --git a/app/models/commit.rb b/app/models/commit.rb
index 6677dcb1e34..1cabc060c2a 100644
--- a/app/models/commit.rb
+++ b/app/models/commit.rb
@@ -139,15 +139,14 @@ class Commit
users << author
users << committer
- mentions = []
- mentions << self.mentioned_users(current_user, project)
+ users.push *self.mentioned_users(current_user, project)
notes(project).each do |note|
users << note.author
- mentions << note.mentioned_users(current_user, project)
+ users.push *note.mentioned_users(current_user, project)
end
- users.concat(mentions.reduce([], :|)).uniq
+ users.uniq
end
def notes(project)
diff --git a/app/models/concerns/issuable.rb b/app/models/concerns/issuable.rb
index 1cad5894267..a21d9bdfe8a 100644
--- a/app/models/concerns/issuable.rb
+++ b/app/models/concerns/issuable.rb
@@ -122,16 +122,15 @@ module Issuable
users = []
users << author
users << assignee if is_assigned?
-
- mentions = []
- mentions << self.mentioned_users(current_user)
+
+ users.push *self.mentioned_users(current_user)
notes.each do |note|
users << note.author
- mentions << note.mentioned_users(current_user)
+ users.push *note.mentioned_users(current_user)
end
- users.concat(mentions.reduce([], :|)).uniq
+ users.uniq
end
def subscribed?(user)
diff --git a/app/models/snippet.rb b/app/models/snippet.rb
index 13703f4115f..c11c28805eb 100644
--- a/app/models/snippet.rb
+++ b/app/models/snippet.rb
@@ -90,15 +90,13 @@ class Snippet < ActiveRecord::Base
def participants(current_user = self.author)
users = []
users << author
-
- mentions = []
notes.each do |note|
users << note.author
- mentions << note.mentioned_users(current_user)
+ users.push *note.mentioned_users(current_user)
end
- users.concat(mentions.reduce([], :|)).uniq
+ users.uniq
end
class << self
diff --git a/app/services/projects/participants_service.rb b/app/services/projects/participants_service.rb
index dcbf348153d..c2d8f48f6e4 100644
--- a/app/services/projects/participants_service.rb
+++ b/app/services/projects/participants_service.rb
@@ -13,19 +13,21 @@ module Projects
end
def participants_in(type, id)
- users = case type
- when "Issue"
- issue = project.issues.find_by_iid(id)
- issue ? issue.participants(current_user) : []
- when "MergeRequest"
- merge_request = project.merge_requests.find_by_iid(id)
- merge_request ? merge_request.participants(current_user) : []
- when "Commit"
- commit = project.repository.commit(id)
- commit ? commit.participants(project, current_user) : []
- else
- []
- end
+ users =
+ case type
+ when "Issue"
+ issue = project.issues.find_by_iid(id)
+ issue.participants(current_user) if issue
+ when "MergeRequest"
+ merge_request = project.merge_requests.find_by_iid(id)
+ merge_request.participants(current_user) if merge_request
+ when "Commit"
+ commit = project.repository.commit(id)
+ commit.participants(project, current_user) if commit
+ end
+
+ return [] unless users
+
sorted(users)
end