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
152dcfbd
Commit
152dcfbd
authored
Oct 08, 2020
by
Sean Arnold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add label system note (resource event)
Add specs for services Fix cop error
parent
fd262a4f
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
131 additions
and
66 deletions
+131
-66
ee/app/services/incident_management/apply_incident_sla_exceeded_label_service.rb
...t_management/apply_incident_sla_exceeded_label_service.rb
+10
-1
ee/app/services/incident_management/create_incident_sla_exceeded_label_service.rb
..._management/create_incident_sla_exceeded_label_service.rb
+3
-3
ee/app/workers/incident_management/incident_sla_exceeded_check_worker.rb
...incident_management/incident_sla_exceeded_check_worker.rb
+1
-1
ee/spec/services/incident_management/apply_incident_sla_ecxeeded_label_service_spec.rb
...agement/apply_incident_sla_ecxeeded_label_service_spec.rb
+38
-0
ee/spec/services/incident_management/create_incident_sla_exceeded_label_service_spec.rb
...gement/create_incident_sla_exceeded_label_service_spec.rb
+7
-0
spec/services/incident_management/create_incident_label_service_spec.rb
...incident_management/create_incident_label_service_spec.rb
+1
-61
spec/support/shared_examples/services/incident_shared_examples.rb
...port/shared_examples/services/incident_shared_examples.rb
+71
-0
No files found.
ee/app/services/incident_management/apply_incident_sla_exceeded_label_service.rb
View file @
152dcfbd
...
...
@@ -13,15 +13,24 @@ module IncidentManagement
return
if
incident
.
label_ids
.
include?
(
label
.
id
)
incident
.
labels
<<
label
add_resource_event
label
end
private
attr_reader
:incident
,
:label
def
add_resource_event
ResourceEvents
::
ChangeLabelsService
.
new
(
incident
,
User
.
alert_bot
)
.
execute
(
added_labels:
[
label
])
end
def
incident_exceeded_label
::
IncidentManagement
::
CreateIncidentSlaExceededLabelService
.
new
(
project
,
current_user
)
.
new
(
project
)
.
execute
.
payload
[
:label
]
end
...
...
ee/app/services/incident_management/create_incident_sla_exceeded_label_service.rb
View file @
152dcfbd
...
...
@@ -3,10 +3,10 @@
module
IncidentManagement
class
CreateIncidentSlaExceededLabelService
<
BaseService
LABEL_PROPERTIES
=
{
title:
'
SLA exceeded
'
,
color:
'#
7E6AB0
'
,
title:
'
missed::SLA
'
,
color:
'#
D9534F
'
,
description:
<<~
DESCRIPTION
.
chomp
This incident was not closed before the SLA (Service Level Agreement) time exceeded
Incidents that have missed the targeted SLA (Service Level Agreement).
DESCRIPTION
}.
freeze
...
...
ee/app/workers/incident_management/incident_sla_exceeded_check_worker.rb
View file @
152dcfbd
# frozen_string_literal: true
module
IncidentManagement
class
IncidentSlaExceededCheckWorker
class
IncidentSlaExceededCheckWorker
# rubocop:disable Scalability/IdempotentWorker
include
ApplicationWorker
include
CronjobQueue
# rubocop:disable Scalability/CronWorkerContext
...
...
ee/spec/services/incident_management/apply_incident_sla_ecxeeded_label_service_spec.rb
0 → 100644
View file @
152dcfbd
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
IncidentManagement
::
ApplyIncidentSlaExceededLabelService
do
let_it_be_with_refind
(
:incident
)
{
create
(
:incident
)
}
let_it_be
(
:project
)
{
incident
.
project
}
let_it_be
(
:label
)
do
::
IncidentManagement
::
CreateIncidentSlaExceededLabelService
.
new
(
project
)
.
execute
.
payload
[
:label
]
end
subject
{
described_class
.
new
(
incident
).
execute
}
context
'label exists already'
do
before
do
incident
.
labels
<<
label
end
it
'does not add a label'
do
expect
{
subject
}.
not_to
change
{
incident
.
labels
.
reload
.
count
}
end
end
it
'adds a label to the incident'
do
expect
{
subject
}.
to
change
{
incident
.
labels
.
reload
.
count
}
end
it
'adds a note that the label was added'
do
expect
{
subject
}.
to
change
{
incident
.
resource_label_events
.
reload
.
count
}
event
=
incident
.
resource_label_events
.
first
expect
(
event
.
action
).
to
eq
(
'add'
)
expect
(
event
.
label
).
to
eq
(
label
)
end
end
ee/spec/services/incident_management/create_incident_sla_exceeded_label_service_spec.rb
0 → 100644
View file @
152dcfbd
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
IncidentManagement
::
CreateIncidentLabelService
do
it_behaves_like
'incident management label service'
end
spec/services/incident_management/create_incident_label_service_spec.rb
View file @
152dcfbd
...
...
@@ -3,65 +3,5 @@
require
'spec_helper'
RSpec
.
describe
IncidentManagement
::
CreateIncidentLabelService
do
let_it_be
(
:project
)
{
create
(
:project
,
:private
)
}
let_it_be
(
:user
)
{
User
.
alert_bot
}
let
(
:service
)
{
described_class
.
new
(
project
,
user
)
}
subject
(
:execute
)
{
service
.
execute
}
describe
'execute'
do
let
(
:incident_label_attributes
)
{
attributes_for
(
:label
,
:incident
)
}
let
(
:title
)
{
incident_label_attributes
[
:title
]
}
let
(
:color
)
{
incident_label_attributes
[
:color
]
}
let
(
:description
)
{
incident_label_attributes
[
:description
]
}
shared_examples
'existing label'
do
it
'returns the existing label'
do
expect
{
execute
}.
not_to
change
(
Label
,
:count
)
expect
(
execute
).
to
be_success
expect
(
execute
.
payload
).
to
eq
(
label:
label
)
end
end
shared_examples
'new label'
do
it
'creates a new label'
do
expect
{
execute
}.
to
change
(
Label
,
:count
).
by
(
1
)
label
=
project
.
reload
.
labels
.
last
expect
(
execute
).
to
be_success
expect
(
execute
.
payload
).
to
eq
(
label:
label
)
expect
(
label
.
title
).
to
eq
(
title
)
expect
(
label
.
color
).
to
eq
(
color
)
expect
(
label
.
description
).
to
eq
(
description
)
end
end
context
'with predefined project label'
do
it_behaves_like
'existing label'
do
let!
(
:label
)
{
create
(
:label
,
project:
project
,
title:
title
)
}
end
end
context
'with predefined group label'
do
let
(
:project
)
{
create
(
:project
,
group:
group
)
}
let
(
:group
)
{
create
(
:group
)
}
it_behaves_like
'existing label'
do
let!
(
:label
)
{
create
(
:group_label
,
group:
group
,
title:
title
)
}
end
end
context
'without label'
do
context
'when user has permissions to create labels'
do
it_behaves_like
'new label'
end
context
'when user has no permissions to create labels'
do
let_it_be
(
:user
)
{
create
(
:user
)
}
it_behaves_like
'new label'
end
end
end
it_behaves_like
'incident management label service'
end
spec/support/shared_examples/services/incident_shared_examples.rb
View file @
152dcfbd
...
...
@@ -45,3 +45,74 @@ RSpec.shared_examples 'not an incident issue' do
expect
(
issue
.
labels
).
not_to
include
(
have_attributes
(
label_properties
))
end
end
# This shared example is to test the execution of incident management label services
# For example:
# - IncidentManagement::CreateIncidentSlaExceededLabelService
# - IncidentManagement::CreateIncidentLabelService
# It doesn't require any defined variables
RSpec
.
shared_examples
'incident management label service'
do
let_it_be
(
:project
)
{
create
(
:project
,
:private
)
}
let_it_be
(
:user
)
{
User
.
alert_bot
}
let
(
:service
)
{
described_class
.
new
(
project
,
user
)
}
subject
(
:execute
)
{
service
.
execute
}
describe
'execute'
do
let
(
:incident_label_attributes
)
{
described_class
::
LABEL_PROPERTIES
}
let
(
:title
)
{
incident_label_attributes
[
:title
]
}
let
(
:color
)
{
incident_label_attributes
[
:color
]
}
let
(
:description
)
{
incident_label_attributes
[
:description
]
}
shared_examples
'existing label'
do
it
'returns the existing label'
do
expect
{
execute
}.
not_to
change
(
Label
,
:count
)
expect
(
execute
).
to
be_success
expect
(
execute
.
payload
).
to
eq
(
label:
label
)
end
end
shared_examples
'new label'
do
it
'creates a new label'
do
expect
{
execute
}.
to
change
(
Label
,
:count
).
by
(
1
)
label
=
project
.
reload
.
labels
.
last
expect
(
execute
).
to
be_success
expect
(
execute
.
payload
).
to
eq
(
label:
label
)
expect
(
label
.
title
).
to
eq
(
title
)
expect
(
label
.
color
).
to
eq
(
color
)
expect
(
label
.
description
).
to
eq
(
description
)
end
end
context
'with predefined project label'
do
it_behaves_like
'existing label'
do
let!
(
:label
)
{
create
(
:label
,
project:
project
,
title:
title
)
}
end
end
context
'with predefined group label'
do
let
(
:project
)
{
create
(
:project
,
group:
group
)
}
let
(
:group
)
{
create
(
:group
)
}
it_behaves_like
'existing label'
do
let!
(
:label
)
{
create
(
:group_label
,
group:
group
,
title:
title
)
}
end
end
context
'without label'
do
context
'when user has permissions to create labels'
do
it_behaves_like
'new label'
end
context
'when user has no permissions to create labels'
do
let_it_be
(
:user
)
{
create
(
:user
)
}
it_behaves_like
'new label'
end
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