summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/finders/branches_finder.rb51
-rw-r--r--app/finders/git_refs_finder.rb56
-rw-r--r--app/finders/tags_finder.rb28
-rw-r--r--app/models/notification_reason.rb4
-rw-r--r--app/models/user.rb3
-rw-r--r--app/services/notification_recipient_service.rb4
6 files changed, 68 insertions, 78 deletions
diff --git a/app/finders/branches_finder.rb b/app/finders/branches_finder.rb
index 291a24c1405..8001c70a9b2 100644
--- a/app/finders/branches_finder.rb
+++ b/app/finders/branches_finder.rb
@@ -1,9 +1,8 @@
# frozen_string_literal: true
-class BranchesFinder
+class BranchesFinder < GitRefsFinder
def initialize(repository, params = {})
- @repository = repository
- @params = params
+ super(repository, params)
end
def execute
@@ -15,56 +14,10 @@ class BranchesFinder
private
- attr_reader :repository, :params
-
def names
@params[:names].presence
end
- def search
- @params[:search].presence
- end
-
- def sort
- @params[:sort].presence || 'name'
- end
-
- def by_search(branches)
- return branches unless search
-
- case search
- when ->(v) { v.starts_with?('^') }
- filter_branches_with_prefix(branches, search.slice(1..-1).upcase)
- when ->(v) { v.ends_with?('$') }
- filter_branches_with_suffix(branches, search.chop.upcase)
- else
- matches = filter_branches_by_name(branches, search.upcase)
- set_exact_match_as_first_result(matches, search)
- end
- end
-
- def filter_branches_with_prefix(branches, prefix)
- branches.select { |branch| branch.name.upcase.starts_with?(prefix) }
- end
-
- def filter_branches_with_suffix(branches, suffix)
- branches.select { |branch| branch.name.upcase.ends_with?(suffix) }
- end
-
- def filter_branches_by_name(branches, term)
- branches.select { |branch| branch.name.upcase.include?(term) }
- end
-
- def set_exact_match_as_first_result(matches, term)
- exact_match_index = find_exact_match_index(matches, term)
- matches.insert(0, matches.delete_at(exact_match_index)) if exact_match_index
- matches
- end
-
- def find_exact_match_index(matches, term)
- matches.index { |branch| branch.name.casecmp(term) == 0 }
- end
-
def by_names(branches)
return branches unless names
diff --git a/app/finders/git_refs_finder.rb b/app/finders/git_refs_finder.rb
new file mode 100644
index 00000000000..2289b34e562
--- /dev/null
+++ b/app/finders/git_refs_finder.rb
@@ -0,0 +1,56 @@
+# frozen_string_literal: true
+
+class GitRefsFinder
+ def initialize(repository, params = {})
+ @repository = repository
+ @params = params
+ end
+
+ protected
+
+ attr_reader :repository, :params
+
+ def search
+ @params[:search].presence
+ end
+
+ def sort
+ @params[:sort].presence || 'name'
+ end
+
+ def by_search(refs)
+ return refs unless search
+
+ case search
+ when ->(v) { v.starts_with?('^') }
+ filter_refs_with_prefix(refs, search.slice(1..-1))
+ when ->(v) { v.ends_with?('$') }
+ filter_refs_with_suffix(refs, search.chop)
+ else
+ matches = filter_refs_by_name(refs, search)
+ set_exact_match_as_first_result(matches, search)
+ end
+ end
+
+ def filter_refs_with_prefix(refs, prefix)
+ refs.select { |ref| ref.name.upcase.starts_with?(prefix.upcase) }
+ end
+
+ def filter_refs_with_suffix(refs, suffix)
+ refs.select { |ref| ref.name.upcase.ends_with?(suffix.upcase) }
+ end
+
+ def filter_refs_by_name(refs, term)
+ refs.select { |ref| ref.name.upcase.include?(term.upcase) }
+ end
+
+ def set_exact_match_as_first_result(matches, term)
+ exact_match_index = find_exact_match_index(matches, term)
+ matches.insert(0, matches.delete_at(exact_match_index)) if exact_match_index
+ matches
+ end
+
+ def find_exact_match_index(matches, term)
+ matches.index { |ref| ref.name.casecmp(term) == 0 }
+ end
+end
diff --git a/app/finders/tags_finder.rb b/app/finders/tags_finder.rb
index 2ffd46245e9..fd58f478b45 100644
--- a/app/finders/tags_finder.rb
+++ b/app/finders/tags_finder.rb
@@ -1,31 +1,13 @@
# frozen_string_literal: true
-class TagsFinder
+class TagsFinder < GitRefsFinder
def initialize(repository, params)
- @repository = repository
- @params = params
+ super(repository, params)
end
def execute
- tags = @repository.tags_sorted_by(sort)
- filter_by_name(tags)
- end
-
- private
-
- def sort
- @params[:sort].presence
- end
-
- def search
- @params[:search].presence
- end
-
- def filter_by_name(tags)
- if search
- tags.select { |tag| tag.name.include?(search) }
- else
- tags
- end
+ tags = repository.tags_sorted_by(sort)
+ tags = by_search(tags)
+ tags
end
end
diff --git a/app/models/notification_reason.rb b/app/models/notification_reason.rb
index 6856d397413..a7967239417 100644
--- a/app/models/notification_reason.rb
+++ b/app/models/notification_reason.rb
@@ -6,12 +6,14 @@ class NotificationReason
OWN_ACTIVITY = 'own_activity'
ASSIGNED = 'assigned'
MENTIONED = 'mentioned'
+ SUBSCRIBED = 'subscribed'
# Priority list for selecting which reason to return in the notification
REASON_PRIORITY = [
OWN_ACTIVITY,
ASSIGNED,
- MENTIONED
+ MENTIONED,
+ SUBSCRIBED
].freeze
# returns the priority of a reason as an integer
diff --git a/app/models/user.rb b/app/models/user.rb
index eec8ad6edbb..277d73cc2ed 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -56,9 +56,6 @@ class User < ApplicationRecord
BLOCKED_MESSAGE = "Your account has been blocked. Please contact your GitLab " \
"administrator if you think this is an error."
- # Removed in GitLab 12.3. Keep until after 2019-09-22.
- self.ignored_columns += %i[support_bot]
-
MINIMUM_INACTIVE_DAYS = 180
# Override Devise::Models::Trackable#update_tracked_fields!
diff --git a/app/services/notification_recipient_service.rb b/app/services/notification_recipient_service.rb
index 9afbb678f5d..0bdf6a0e6bc 100644
--- a/app/services/notification_recipient_service.rb
+++ b/app/services/notification_recipient_service.rb
@@ -181,7 +181,7 @@ module NotificationRecipientService
def add_subscribed_users
return unless target.respond_to? :subscribers
- add_recipients(target.subscribers(project), :subscription, nil)
+ add_recipients(target.subscribers(project), :subscription, NotificationReason::SUBSCRIBED)
end
# rubocop: disable CodeReuse/ActiveRecord
@@ -240,7 +240,7 @@ module NotificationRecipientService
return unless target.respond_to? :labels
(labels || target.labels).each do |label|
- add_recipients(label.subscribers(project), :subscription, nil)
+ add_recipients(label.subscribers(project), :subscription, NotificationReason::SUBSCRIBED)
end
end
end