Commit 3693c7f1 authored by Raimund Hook's avatar Raimund Hook Committed by Jan Provaznik

Added severity to issues REST API

Previously this field was only available in GraphQL, this change adds it
to the REST API (display only)

Changelog: changed
MR: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/82696Signed-off-by: default avatarRaimund Hook <raimund.hook@exfo.com>
parent 3dbb300d
......@@ -135,7 +135,7 @@ class Issue < ApplicationRecord
scope :with_prometheus_alert_events, -> { joins(:issues_prometheus_alert_events) }
scope :with_self_managed_prometheus_alert_events, -> { joins(:issues_self_managed_prometheus_alert_events) }
scope :with_api_entity_associations, -> {
preload(:timelogs, :closed_by, :assignees, :author, :labels,
preload(:timelogs, :closed_by, :assignees, :author, :labels, :issuable_severity,
milestone: { project: [:route, { namespace: :route }] },
project: [:route, { namespace: :route }])
}
......
......@@ -165,6 +165,7 @@ Example response:
"confidential": false,
"discussion_locked": false,
"issue_type": "issue",
"severity": "UNKNOWN",
"_links":{
"self":"http://gitlab.example.com/api/v4/projects/1/issues/76",
"notes":"http://gitlab.example.com/api/v4/projects/1/issues/76/notes",
......@@ -390,6 +391,7 @@ Example response:
"confidential": false,
"discussion_locked": false,
"issue_type": "issue",
"severity": "UNKNOWN",
"_links":{
"self":"http://gitlab.example.com/api/v4/projects/4/issues/41",
"notes":"http://gitlab.example.com/api/v4/projects/4/issues/41/notes",
......@@ -598,6 +600,7 @@ Example response:
"confidential": false,
"discussion_locked": false,
"issue_type": "issue",
"severity": "UNKNOWN",
"_links":{
"self":"http://gitlab.example.com/api/v4/projects/4/issues/41",
"notes":"http://gitlab.example.com/api/v4/projects/4/issues/41/notes",
......@@ -755,6 +758,7 @@ Example response:
"confidential": false,
"discussion_locked": false,
"issue_type": "issue",
"severity": "UNKNOWN",
"task_completion_status": {
"count": 0,
"completed_count": 0
......@@ -917,6 +921,7 @@ Example response:
"confidential": false,
"discussion_locked": false,
"issue_type": "issue",
"severity": "UNKNOWN",
"_links": {
"self": "http://gitlab.example.com/api/v4/projects/1/issues/2",
"notes": "http://gitlab.example.com/api/v4/projects/1/issues/2/notes",
......@@ -1064,6 +1069,7 @@ Example response:
"confidential": false,
"discussion_locked": false,
"issue_type": "issue",
"severity": "UNKNOWN",
"_links": {
"self": "http://gitlab.example.com/api/v4/projects/1/issues/2",
"notes": "http://gitlab.example.com/api/v4/projects/1/issues/2/notes",
......@@ -1238,6 +1244,7 @@ Example response:
"confidential": false,
"discussion_locked": false,
"issue_type": "issue",
"severity": "UNKNOWN",
"_links": {
"self": "http://gitlab.example.com/api/v4/projects/1/issues/2",
"notes": "http://gitlab.example.com/api/v4/projects/1/issues/2/notes",
......@@ -1421,6 +1428,7 @@ Example response:
"confidential": false,
"discussion_locked": false,
"issue_type": "issue",
"severity": "UNKNOWN",
"_links": {
"self": "http://gitlab.example.com/api/v4/projects/1/issues/2",
"notes": "http://gitlab.example.com/api/v4/projects/1/issues/2/notes",
......@@ -1560,6 +1568,7 @@ Example response:
"confidential":false,
"discussion_locked":null,
"issue_type":"issue",
"severity": "UNKNOWN",
"web_url":"https://gitlab.example.com/namespace1/project2/-/issues/1",
"time_stats":{
"time_estimate":0,
......@@ -1669,6 +1678,7 @@ Example response:
"confidential": false,
"discussion_locked": false,
"issue_type": "issue",
"severity": "UNKNOWN",
"_links": {
"self": "http://gitlab.example.com/api/v4/projects/1/issues/2",
"notes": "http://gitlab.example.com/api/v4/projects/1/issues/2/notes",
......@@ -1797,6 +1807,7 @@ Example response:
"confidential": false,
"discussion_locked": false,
"issue_type": "issue",
"severity": "UNKNOWN",
"task_completion_status":{
"count":0,
"completed_count":0
......@@ -1906,6 +1917,7 @@ Example response:
"confidential": false,
"discussion_locked": false,
"issue_type": "issue",
"severity": "UNKNOWN",
"task_completion_status":{
"count":0,
"completed_count":0
......
......@@ -35,6 +35,10 @@ module API
issue
end
expose :severity,
format_with: :upcase,
documentation: { type: "String", desc: "One of #{::IssuableSeverity.severities.keys.map(&:upcase)}" }
# Calculating the value of subscribed field triggers Markdown
# processing. We can't do that for multiple issues / merge
# requests in a single API request.
......
......@@ -86,6 +86,7 @@
"due_date": { "type": ["string", "null"] },
"confidential": { "type": "boolean" },
"web_url": { "type": "uri" },
"severity": { "type": "string", "enum": ["UNKNOWN", "LOW", "MEDIUM", "HIGH", "CRITICAL"] },
"time_stats": {
"time_estimate": { "type": "integer" },
"total_time_spent": { "type": "integer" },
......
......@@ -554,6 +554,27 @@ RSpec.describe API::Issues do
end
end
context 'with incident issues' do
let_it_be(:incident) { create(:incident, project: project) }
it 'avoids N+1 queries' do
get api('/issues', user) # warm up
control = ActiveRecord::QueryRecorder.new do
get api('/issues', user)
end
create(:incident, project: project)
create(:incident, project: project)
expect do
get api('/issues', user)
end.not_to exceed_query_limit(control)
# 2 pre-existed issues + 3 incidents
expect(json_response.count).to eq(5)
end
end
context 'filter by labels or label_name param' do
context 'N+1' do
let(:label_b) { create(:label, title: 'foo', project: project) }
......
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