Commit 2973373c authored by Sean Arnold's avatar Sean Arnold Committed by Mayra Cabrera

Quickaction for changing an Issuable severity

parent 440e4556
...@@ -10,6 +10,14 @@ class IssuableSeverity < ApplicationRecord ...@@ -10,6 +10,14 @@ class IssuableSeverity < ApplicationRecord
critical: 'Critical - S1' critical: 'Critical - S1'
}.freeze }.freeze
SEVERITY_QUICK_ACTION_PARAMS = {
unknown: %w(Unknown 0),
low: %w(Low S4 4),
medium: %w(Medium S3 3),
high: %w(High S2 2),
critical: %w(Critical S1 1)
}.freeze
belongs_to :issue belongs_to :issue
validates :issue, presence: true, uniqueness: true validates :issue, presence: true, uniqueness: true
......
---
key_path: redis_hll_counters.quickactions.i_quickactions_severity_monthly
description: Count of MAU using the `/severity` quick action
product_section: ops
product_stage: monitor
product_group: group::monitor
product_category: incident_management
value_type: number
status: implemented
milestone: "14.2"
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/66422
time_frame: 28d
data_source: redis_hll
data_category: Optional
distribution:
- ce
- ee
tier:
- free
- premium
- ultimate
---
key_path: redis_hll_counters.quickactions.i_quickactions_severity_weekly
description: Count of WAU using the `/severity` quick action
product_section: ops
product_stage: monitor
product_group: group::monitor
product_category: incident_management
value_type: number
status: implemented
milestone: "14.2"
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/66422
time_frame: 7d
data_source: redis_hll
data_category: Optional
distribution:
- ce
- ee
tier:
- free
- premium
- ultimate
...@@ -16666,6 +16666,34 @@ Status: `data_available` ...@@ -16666,6 +16666,34 @@ Status: `data_available`
Tiers: `free`, `premium`, `ultimate` Tiers: `free`, `premium`, `ultimate`
### `redis_hll_counters.quickactions.i_quickactions_severity_monthly`
Count of MAU using the `/severity` quick action
[YAML definition](https://gitlab.com/gitlab-org/gitlab/-/blob/master/config/metrics/counts_28d/20210721042227_i_quickactions_severity_monthly.yml)
Group: `group::monitor`
Data Category: `Optional`
Status: `implemented`
Tiers: `free`, `premium`, `ultimate`
### `redis_hll_counters.quickactions.i_quickactions_severity_weekly`
Count of WAU using the `/severity` quick action
[YAML definition](https://gitlab.com/gitlab-org/gitlab/-/blob/master/config/metrics/counts_7d/20210721042223_i_quickactions_severity_weekly.yml)
Group: `group::monitor`
Data Category: `Optional`
Status: `implemented`
Tiers: `free`, `premium`, `ultimate`
### `redis_hll_counters.quickactions.i_quickactions_shrug_monthly` ### `redis_hll_counters.quickactions.i_quickactions_shrug_monthly`
Count of MAU using the `/shrug` quick action Count of MAU using the `/shrug` quick action
......
...@@ -94,6 +94,7 @@ threads. Some quick actions might not be available to all subscription tiers. ...@@ -94,6 +94,7 @@ threads. Some quick actions might not be available to all subscription tiers.
| `/remove_time_spent` | **{check-circle}** Yes | **{check-circle}** Yes | **{dotted-circle}** No | Remove time spent. | | `/remove_time_spent` | **{check-circle}** Yes | **{check-circle}** Yes | **{dotted-circle}** No | Remove time spent. |
| `/remove_zoom` | **{check-circle}** Yes | **{dotted-circle}** No | **{dotted-circle}** No | Remove Zoom meeting from this issue ([introduced in GitLab 12.4](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/16609)). | | `/remove_zoom` | **{check-circle}** Yes | **{dotted-circle}** No | **{dotted-circle}** No | Remove Zoom meeting from this issue ([introduced in GitLab 12.4](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/16609)). |
| `/reopen` | **{check-circle}** Yes | **{check-circle}** Yes | **{check-circle}** Yes | Reopen. | | `/reopen` | **{check-circle}** Yes | **{check-circle}** Yes | **{check-circle}** Yes | Reopen. |
| `/severity` | **{check-circle}** Yes | **{check-circle}** No | **{check-circle}** No | Set the severity. ([introduced in GitLab 14.2](https://gitlab.com/gitlab-org/gitlab/-/issues/334045)) |
| `/shrug <comment>` | **{check-circle}** Yes | **{check-circle}** Yes | **{check-circle}** Yes | Append the comment with `¯\_(ツ)_/¯`. | | `/shrug <comment>` | **{check-circle}** Yes | **{check-circle}** Yes | **{check-circle}** Yes | Append the comment with `¯\_(ツ)_/¯`. |
| `/spend <time> [<date>]` | **{check-circle}** Yes | **{check-circle}** Yes | **{dotted-circle}** No | Add or subtract spent time. Optionally, specify the date that time was spent on. For example, `/spend 1mo 2w 3d 4h 5m 2018-08-26` or `/spend -1h 30m`. Learn more about [time tracking](time_tracking.md). | | `/spend <time> [<date>]` | **{check-circle}** Yes | **{check-circle}** Yes | **{dotted-circle}** No | Add or subtract spent time. Optionally, specify the date that time was spent on. For example, `/spend 1mo 2w 3d 4h 5m 2018-08-26` or `/spend -1h 30m`. Learn more about [time tracking](time_tracking.md). |
| `/submit_review` | **{dotted-circle}** No | **{check-circle}** Yes | **{dotted-circle}** No | Submit a pending review ([introduced in GitLab 12.7](https://gitlab.com/gitlab-org/gitlab/-/issues/8041)). | | `/submit_review` | **{dotted-circle}** No | **{check-circle}** Yes | **{dotted-circle}** No | Submit a pending review ([introduced in GitLab 12.7](https://gitlab.com/gitlab-org/gitlab/-/issues/8041)). |
......
...@@ -241,8 +241,43 @@ module Gitlab ...@@ -241,8 +241,43 @@ module Gitlab
"#{comment} #{TABLEFLIP}" "#{comment} #{TABLEFLIP}"
end end
desc _('Set severity')
explanation _('Sets the severity')
params '1 / S1 / Critical'
types Issue
condition do
quick_action_target.supports_severity?
end
parse_params do |severity|
find_severity(severity)
end
command :severity do |severity|
if severity
::Issues::UpdateService.new(project: quick_action_target.project, current_user: current_user, params: { severity: severity }).execute(quick_action_target)
@execution_message[:severity] = _("Severity updated to %{severity}.") % { severity: severity.capitalize }
else
@execution_message[:severity] = _('No severity matches the provided parameter')
end
end
private private
def find_severity(severity_param)
return unless severity_param
severity_param = severity_param.downcase
severities = IssuableSeverity::SEVERITY_QUICK_ACTION_PARAMS.values.map { |vals| vals.map(&:downcase) }
matched_severity = severities.find do |severity_values|
severity_values.include?(severity_param)
end
return unless matched_severity
matched_severity[0]
end
def run_label_command(labels:, command:, updates_key:) def run_label_command(labels:, command:, updates_key:)
return if labels.empty? return if labels.empty?
......
...@@ -179,6 +179,10 @@ ...@@ -179,6 +179,10 @@
category: quickactions category: quickactions
redis_slot: quickactions redis_slot: quickactions
aggregation: weekly aggregation: weekly
- name: i_quickactions_severity
category: quickactions
redis_slot: quickactions
aggregation: weekly
- name: i_quickactions_shrug - name: i_quickactions_shrug
category: quickactions category: quickactions
redis_slot: quickactions redis_slot: quickactions
......
...@@ -22297,6 +22297,9 @@ msgstr "" ...@@ -22297,6 +22297,9 @@ msgstr ""
msgid "No schedules" msgid "No schedules"
msgstr "" msgstr ""
msgid "No severity matches the provided parameter"
msgstr ""
msgid "No source selected" msgid "No source selected"
msgstr "" msgstr ""
...@@ -29843,6 +29846,9 @@ msgstr "" ...@@ -29843,6 +29846,9 @@ msgstr ""
msgid "Set requirements for a user to sign-in. Enable mandatory two-factor authentication." msgid "Set requirements for a user to sign-in. Enable mandatory two-factor authentication."
msgstr "" msgstr ""
msgid "Set severity"
msgstr ""
msgid "Set size limits for displaying diffs in the browser." msgid "Set size limits for displaying diffs in the browser."
msgstr "" msgstr ""
...@@ -29987,6 +29993,9 @@ msgstr "" ...@@ -29987,6 +29993,9 @@ msgstr ""
msgid "Sets the milestone to %{milestone_reference}." msgid "Sets the milestone to %{milestone_reference}."
msgstr "" msgstr ""
msgid "Sets the severity"
msgstr ""
msgid "Sets time estimate to %{time_estimate}." msgid "Sets time estimate to %{time_estimate}."
msgstr "" msgstr ""
...@@ -30017,6 +30026,9 @@ msgstr "" ...@@ -30017,6 +30026,9 @@ msgstr ""
msgid "Severity" msgid "Severity"
msgstr "" msgstr ""
msgid "Severity updated to %{severity}."
msgstr ""
msgid "SeverityWidget|Severity" msgid "SeverityWidget|Severity"
msgstr "" msgstr ""
......
...@@ -2080,6 +2080,48 @@ RSpec.describe QuickActions::InterpretService do ...@@ -2080,6 +2080,48 @@ RSpec.describe QuickActions::InterpretService do
end end
end end
end end
context 'severity command' do
let_it_be_with_reload(:issuable) { create(:incident, project: project) }
subject(:set_severity) { service.execute(content, issuable) }
it_behaves_like 'failed command', 'No severity matches the provided parameter' do
let(:content) { '/severity something' }
end
shared_examples 'updates the severity' do |new_severity|
it do
expect { set_severity }.to change { issuable.severity }.from('unknown').to(new_severity)
end
end
context 'severity given with S format' do
let(:content) { '/severity s3' }
it_behaves_like 'updates the severity', 'medium'
end
context 'severity given with number format' do
let(:content) { '/severity 3' }
it_behaves_like 'updates the severity', 'medium'
end
context 'severity given with text format' do
let(:content) { '/severity medium' }
it_behaves_like 'updates the severity', 'medium'
end
context 'an issuable that does not support severity' do
let_it_be_with_reload(:issuable) { create(:issue, project: project) }
it_behaves_like 'failed command', 'Could not apply severity command.' do
let(:content) { '/severity s3' }
end
end
end
end end
describe '#explain' do describe '#explain' do
......
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