Commit 105498f7 authored by Vitali Tatarintev's avatar Vitali Tatarintev Committed by Shinya Maeda

Allow reading severity of Issuable

Issuable returns incident severity
parent 1a9d624a
# frozen_string_literal: true
module Types
class IssuableSeverityEnum < BaseEnum
graphql_name 'IssuableSeverity'
description 'Incident severity'
::IssuableSeverity.severities.keys.each do |severity|
value severity.upcase, value: severity, description: "#{severity.titleize} severity"
end
end
end
......@@ -106,6 +106,9 @@ module Types
Types::AlertManagement::AlertType,
null: true,
description: 'Alert associated to this issue'
field :severity, Types::IssuableSeverityEnum, null: true,
description: 'Severity level of the incident'
end
end
......
......@@ -189,6 +189,12 @@ module Issuable
is_a?(Issue) && super
end
def severity
return IssuableSeverity::DEFAULT unless incident?
issuable_severity&.severity || IssuableSeverity::DEFAULT
end
private
def description_max_length_for_new_records_is_valid
......
# frozen_string_literal: true
class IssuableSeverity < ApplicationRecord
DEFAULT = 'unknown'
belongs_to :issue
validates :issue, presence: true, uniqueness: true
......
......@@ -60,6 +60,7 @@ class Issue < ApplicationRecord
end
end
has_one :issuable_severity
has_one :sentry_issue
has_one :alert_management_alert, class_name: 'AlertManagement::Alert'
has_and_belongs_to_many :self_managed_prometheus_alert_events, join_table: :issues_self_managed_prometheus_alert_events # rubocop: disable Rails/HasAndBelongsToMany
......
---
title: Exposes Incident's severity via GraphQL
merge_request: 40945
author:
type: added
......@@ -5564,6 +5564,11 @@ type EpicIssue implements Noteable {
"""
relativePosition: Int
"""
Severity level of the incident
"""
severity: IssuableSeverity
"""
State of the issue
"""
......@@ -7032,6 +7037,36 @@ type InstanceSecurityDashboard {
): VulnerabilityScannerConnection
}
"""
Incident severity
"""
enum IssuableSeverity {
"""
Critical severity
"""
CRITICAL
"""
High severity
"""
HIGH
"""
Low severity
"""
LOW
"""
Medium severity
"""
MEDIUM
"""
Unknown severity
"""
UNKNOWN
}
"""
State of a GitLab issue or merge request
"""
......@@ -7278,6 +7313,11 @@ type Issue implements Noteable {
"""
relativePosition: Int
"""
Severity level of the incident
"""
severity: IssuableSeverity
"""
State of the issue
"""
......
......@@ -15512,6 +15512,20 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "severity",
"description": "Severity level of the incident",
"args": [
],
"type": {
"kind": "ENUM",
"name": "IssuableSeverity",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "state",
"description": "State of the issue",
......@@ -19423,6 +19437,47 @@
"enumValues": null,
"possibleTypes": null
},
{
"kind": "ENUM",
"name": "IssuableSeverity",
"description": "Incident severity",
"fields": null,
"inputFields": null,
"interfaces": null,
"enumValues": [
{
"name": "UNKNOWN",
"description": "Unknown severity",
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "LOW",
"description": "Low severity",
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "MEDIUM",
"description": "Medium severity",
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "HIGH",
"description": "High severity",
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "CRITICAL",
"description": "Critical severity",
"isDeprecated": false,
"deprecationReason": null
}
],
"possibleTypes": null
},
{
"kind": "ENUM",
"name": "IssuableState",
......@@ -20075,6 +20130,20 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "severity",
"description": "Severity level of the incident",
"args": [
],
"type": {
"kind": "ENUM",
"name": "IssuableSeverity",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "state",
"description": "State of the issue",
......@@ -932,6 +932,7 @@ Relationship between an epic and an issue
| `reference` | String! | Internal reference of the issue. Returned in shortened format by default |
| `relationPath` | String | URI path of the epic-issue relation |
| `relativePosition` | Int | Relative position of the issue (used for positioning in epic tree and issue boards) |
| `severity` | IssuableSeverity | Severity level of the incident |
| `state` | IssueState! | State of the issue |
| `statusPagePublishedIncident` | Boolean | Indicates whether an issue is published to the status page |
| `subscribed` | Boolean! | Indicates the currently logged in user is subscribed to the issue |
......@@ -1103,6 +1104,7 @@ Represents a Group Membership
| `milestone` | Milestone | Milestone of the issue |
| `reference` | String! | Internal reference of the issue. Returned in shortened format by default |
| `relativePosition` | Int | Relative position of the issue (used for positioning in epic tree and issue boards) |
| `severity` | IssuableSeverity | Severity level of the incident |
| `state` | IssueState! | State of the issue |
| `statusPagePublishedIncident` | Boolean | Indicates whether an issue is published to the status page |
| `subscribed` | Boolean! | Indicates the currently logged in user is subscribed to the issue |
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Types::IssuableSeverityEnum do
specify { expect(described_class.graphql_name).to eq('IssuableSeverity') }
it 'exposes all the existing issuable severity values' do
expect(described_class.values.keys).to contain_exactly(
*%w[UNKNOWN LOW MEDIUM HIGH CRITICAL]
)
end
end
......@@ -15,7 +15,7 @@ RSpec.describe GitlabSchema.types['Issue'] do
fields = %i[id iid title description state reference author assignees participants labels milestone due_date
confidential discussion_locked upvotes downvotes user_notes_count web_path web_url relative_position
subscribed time_estimate total_time_spent closed_at created_at updated_at task_completion_status
designs design_collection alert_management_alert]
designs design_collection alert_management_alert severity]
fields.each do |field_name|
expect(described_class).to have_graphql_field(field_name)
......
......@@ -15,6 +15,7 @@ issues:
- resource_iteration_events
- sent_notifications
- sentry_issue
- issuable_severity
- label_links
- labels
- last_edited_by
......@@ -649,6 +650,8 @@ zoom_meetings:
- issue
sentry_issue:
- issue
issuable_severity:
- issue
design_versions: *version
epic:
- subscriptions
......
......@@ -860,4 +860,41 @@ RSpec.describe Issuable do
it { is_expected.to eq(incident) }
end
end
describe '#severity' do
subject { issuable.severity }
context 'when issuable is not an incident' do
using RSpec::Parameterized::TableSyntax
where(:issuable_type, :severity) do
:issue | 'unknown'
:merge_request | 'unknown'
end
with_them do
let(:issuable) { build_stubbed(issuable_type) }
it { is_expected.to eq(severity) }
end
end
context 'when issuable type is an incident' do
let!(:issuable) { build_stubbed(:incident) }
context 'when incident does not have issuable_severity' do
it 'returns default serverity' do
is_expected.to eq(IssuableSeverity::DEFAULT)
end
end
context 'when incident has issuable_severity' do
let!(:issuable_severity) { build_stubbed(:issuable_severity, issue: issuable, severity: 'critical') }
it 'returns issuable serverity' do
is_expected.to eq('critical')
end
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment