diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-15 06:09:24 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-15 06:09:24 +0300 |
commit | 5fe82ba3d39345ce6c6df14a10b13998b13c68b2 (patch) | |
tree | 33c18c58ff44cb1c8301798bf2f2edbb80ac746d /app/models/alert_management | |
parent | 09bd62c59d070ab2bbcb4079a44dcb78c76666b5 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/alert_management')
-rw-r--r-- | app/models/alert_management/alert.rb | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/app/models/alert_management/alert.rb b/app/models/alert_management/alert.rb index 36186157c5d..d1b5eaecc6a 100644 --- a/app/models/alert_management/alert.rb +++ b/app/models/alert_management/alert.rb @@ -12,6 +12,7 @@ module AlertManagement include Gitlab::SQL::Pattern include Presentable include Gitlab::Utils::StrongMemoize + include Referable STATUSES = { triggered: 0, @@ -170,6 +171,25 @@ module AlertManagement with_prometheus_alert.where(id: ids) end + def self.reference_prefix + '^alert#' + end + + def self.reference_pattern + @reference_pattern ||= %r{ + (#{Project.reference_pattern})? + #{Regexp.escape(reference_prefix)}(?<alert>\d+) + }x + end + + def self.link_reference_pattern + @link_reference_pattern ||= super("alert_management", /(?<alert>\d+)\/details(\#)?/) + end + + def self.reference_valid?(reference) + reference.to_i > 0 && reference.to_i <= Gitlab::Database::MAX_INT_VALUE + end + def prometheus? monitoring_tool == Gitlab::AlertManagement::AlertParams::MONITORING_TOOLS[:prometheus] end @@ -178,10 +198,10 @@ module AlertManagement increment!(:events) end - # required for todos (typically contains an identifier like issue iid) - # no-op; we could use iid, but we don't have a reference prefix - def to_reference(_from = nil, full: false) - '' + def to_reference(from = nil, full: false) + reference = "#{self.class.reference_prefix}#{iid}" + + "#{project.to_reference_base(from, full: full)}#{reference}" end def execute_services |