Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
0deaeb61
Commit
0deaeb61
authored
Sep 18, 2020
by
Vitali Tatarintev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add severity system note in background job
Move adding a severity system note into a background job
parent
d1d6903c
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
103 additions
and
4 deletions
+103
-4
app/services/incident_management/incidents/update_severity_service.rb
.../incident_management/incidents/update_severity_service.rb
+1
-1
app/workers/all_queues.yml
app/workers/all_queues.yml
+8
-0
app/workers/incident_management/add_severity_system_note_worker.rb
...rs/incident_management/add_severity_system_note_worker.rb
+22
-0
spec/services/incident_management/incidents/update_severity_service_spec.rb
...dent_management/incidents/update_severity_service_spec.rb
+12
-3
spec/workers/incident_management/add_severity_system_note_worker_spec.rb
...cident_management/add_severity_system_note_worker_spec.rb
+60
-0
No files found.
app/services/incident_management/incidents/update_severity_service.rb
View file @
0deaeb61
...
...
@@ -31,7 +31,7 @@ module IncidentManagement
end
def
add_system_note
SystemNoteService
.
change_incident_severity
(
issuable
,
current_user
)
::
IncidentManagement
::
AddSeveritySystemNoteWorker
.
perform_async
(
issuable
.
id
,
current_user
.
id
)
end
end
end
...
...
app/workers/all_queues.yml
View file @
0deaeb61
...
...
@@ -715,6 +715,14 @@
:weight:
2
:idempotent:
true
:tags: []
-
:name: incident_management:incident_management_add_severity_system_note
:feature_category: :incident_management
:has_external_dependencies:
:urgency: :low
:resource_boundary: :unknown
:weight:
2
:idempotent:
:tags: []
-
:name: incident_management:incident_management_pager_duty_process_incident
:feature_category: :incident_management
:has_external_dependencies:
...
...
app/workers/incident_management/add_severity_system_note_worker.rb
0 → 100644
View file @
0deaeb61
# frozen_string_literal: true
module
IncidentManagement
class
AddSeveritySystemNoteWorker
# rubocop:disable Scalability/IdempotentWorker
include
ApplicationWorker
queue_namespace
:incident_management
feature_category
:incident_management
def
perform
(
incident_id
,
user_id
)
return
if
incident_id
.
blank?
||
user_id
.
blank?
incident
=
Issue
.
with_issue_type
(
:incident
).
find_by_id
(
incident_id
)
return
unless
incident
user
=
User
.
find_by_id
(
user_id
)
return
unless
user
SystemNoteService
.
change_incident_severity
(
incident
,
user
)
end
end
end
spec/services/incident_management/incidents/update_severity_service_spec.rb
View file @
0deaeb61
...
...
@@ -7,12 +7,19 @@ RSpec.describe IncidentManagement::Incidents::UpdateSeverityService do
describe
'#execute'
do
let
(
:severity
)
{
'low'
}
let
(
:system_note_worker
)
{
::
IncidentManagement
::
AddSeveritySystemNoteWorker
}
subject
(
:update_severity
)
{
described_class
.
new
(
issuable
,
user
,
severity
).
execute
}
before
do
allow
(
system_note_worker
).
to
receive
(
:perform_async
)
end
shared_examples
'adds a system note'
do
it
do
expect
{
update_severity
}.
to
change
{
issuable
.
notes
.
where
(
author:
user
).
count
}.
by
(
1
)
it
'calls AddSeveritySystemNoteWorker'
do
update_severity
expect
(
system_note_worker
).
to
have_received
(
:perform_async
).
with
(
issuable
.
id
,
user
.
id
)
end
end
...
...
@@ -27,7 +34,9 @@ RSpec.describe IncidentManagement::Incidents::UpdateSeverityService do
end
it
'does not add a system note'
do
expect
{
update_severity
}.
not_to
change
{
issuable
.
notes
.
count
}
update_severity
expect
(
system_note_worker
).
not_to
have_received
(
:perform_async
)
end
end
end
...
...
spec/workers/incident_management/add_severity_system_note_worker_spec.rb
0 → 100644
View file @
0deaeb61
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
IncidentManagement
::
AddSeveritySystemNoteWorker
do
let_it_be
(
:project
)
{
create
(
:project
)
}
let_it_be
(
:user
)
{
create
(
:user
)
}
let_it_be
(
:incident
)
{
create
(
:incident
,
project:
project
)
}
let_it_be
(
:issuable_severity
)
{
create
(
:issuable_severity
,
issue:
incident
,
severity: :medium
)
}
describe
'#perform'
do
let
(
:incident_id
)
{
incident
.
id
}
let
(
:user_id
)
{
user
.
id
}
subject
(
:perform
)
{
described_class
.
new
.
perform
(
incident_id
,
user_id
)
}
shared_examples
'does not add a system note'
do
it
'does not change incident notes count'
do
expect
{
perform
}.
not_to
change
{
incident
.
notes
.
count
}
end
end
context
'when incident and user exist'
do
it
'creates a system note'
do
expect
{
perform
}.
to
change
{
incident
.
notes
.
where
(
author:
user
).
count
}.
by
(
1
)
end
end
context
'when incident does not exist'
do
let
(
:incident_id
)
{
-
1
}
it_behaves_like
'does not add a system note'
end
context
'when incident_id is nil'
do
let
(
:incident_id
)
{
nil
}
it_behaves_like
'does not add a system note'
end
context
'when issue is not an incident'
do
let_it_be
(
:issue
)
{
create
(
:issue
,
project:
project
)
}
let
(
:incident_id
)
{
issue
.
id
}
it_behaves_like
'does not add a system note'
end
context
'when user does not exist'
do
let
(
:user_id
)
{
-
1
}
it_behaves_like
'does not add a system note'
end
context
'when user_id is nil'
do
let
(
:user_id
)
{
nil
}
it_behaves_like
'does not add a system note'
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment