Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-05-20 03:08:20 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-05-20 03:08:20 +0300
commit59accb4c4780f194554b86c7be3c4a916fb70737 (patch)
treedac53b413bbac9ba1bc2a523ec64bed2c94d6f7a /lib/gitlab/alert_management
parent680d18802596089dc407b7011bcf682d24846aec (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/alert_management')
-rw-r--r--lib/gitlab/alert_management/alert_status_counts.rb53
1 files changed, 53 insertions, 0 deletions
diff --git a/lib/gitlab/alert_management/alert_status_counts.rb b/lib/gitlab/alert_management/alert_status_counts.rb
new file mode 100644
index 00000000000..382026236e0
--- /dev/null
+++ b/lib/gitlab/alert_management/alert_status_counts.rb
@@ -0,0 +1,53 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module AlertManagement
+ # Represents counts of each status or category of statuses
+ class AlertStatusCounts
+ include Gitlab::Utils::StrongMemoize
+
+ STATUSES = ::AlertManagement::Alert::STATUSES
+
+ attr_reader :project
+
+ def self.declarative_policy_class
+ 'AlertManagement::AlertPolicy'
+ end
+
+ def initialize(current_user, project, params)
+ @project = project
+ @current_user = current_user
+ @params = params
+ end
+
+ # Define method for each status
+ STATUSES.each_key do |status|
+ define_method(status) { counts[status] }
+ end
+
+ def open
+ counts[:triggered] + counts[:acknowledged]
+ end
+
+ def all
+ counts.values.sum # rubocop:disable CodeReuse/ActiveRecord
+ end
+
+ private
+
+ attr_reader :current_user, :params
+
+ def counts
+ strong_memoize(:counts) do
+ Hash.new(0).merge(counts_by_status)
+ end
+ end
+
+ def counts_by_status
+ ::AlertManagement::AlertsFinder
+ .counts_by_status(current_user, project, params)
+ .transform_keys { |status_id| STATUSES.key(status_id) }
+ end
+ end
+ end
+end