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
20dd843d
Commit
20dd843d
authored
Jul 22, 2020
by
Vitali Tatarintev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Return ServiceResponse from CreateIssueService
parent
3e481b0a
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
17 deletions
+20
-17
app/services/incident_management/create_issue_service.rb
app/services/incident_management/create_issue_service.rb
+4
-4
app/workers/incident_management/process_alert_worker.rb
app/workers/incident_management/process_alert_worker.rb
+3
-3
spec/services/incident_management/create_issue_service_spec.rb
...services/incident_management/create_issue_service_spec.rb
+13
-10
No files found.
app/services/incident_management/create_issue_service.rb
View file @
20dd843d
...
...
@@ -14,9 +14,9 @@ module IncidentManagement
return
error_with
(
'invalid alert'
)
unless
alert
.
valid?
result
=
create_issue
return
error_with
(
result
.
message
)
unless
result
.
success?
return
error_with
(
result
.
message
,
result
.
payload
[
:issue
]
)
unless
result
.
success?
success
(
issue:
result
.
payload
[
:issue
])
result
end
private
...
...
@@ -62,10 +62,10 @@ module IncidentManagement
incident_management_setting
.
issue_template_content
end
def
error_with
(
message
)
def
error_with
(
message
,
issue
=
nil
)
log_error
(
%{Cannot create incident issue for "#{project.full_name}": #{message}}
)
error
(
message
)
ServiceResponse
.
error
(
payload:
{
issue:
issue
},
message:
message
)
end
end
end
app/workers/incident_management/process_alert_worker.rb
View file @
20dd843d
...
...
@@ -16,9 +16,10 @@ module IncidentManagement
alert
=
find_alert
(
alert_id
)
return
unless
alert
new_issue
=
create_issue_for
(
alert
)
return
unless
new_issue
&
.
persisted
?
result
=
create_issue_for
(
alert
)
return
unless
result
.
success
?
new_issue
=
result
.
payload
[
:issue
]
link_issue_with_alert
(
alert
,
new_issue
.
id
)
end
...
...
@@ -36,7 +37,6 @@ module IncidentManagement
IncidentManagement
::
CreateIssueService
.
new
(
alert
.
project
,
parsed_payload
(
alert
))
.
execute
.
dig
(
:issue
)
end
def
link_issue_with_alert
(
alert
,
issue_id
)
...
...
spec/services/incident_management/create_issue_service_spec.rb
View file @
20dd843d
...
...
@@ -25,10 +25,10 @@ RSpec.describe IncidentManagement::CreateIssueService do
create
(
:project_incident_management_setting
,
project:
project
)
end
subject
{
service
.
execute
}
subject
(
:execute
)
{
service
.
execute
}
context
'when create_issue enabled'
do
let
(
:issue
)
{
subject
[
:issue
]
}
let
(
:issue
)
{
execute
.
payload
[
:issue
]
}
before
do
setting
.
update!
(
create_issue:
true
)
...
...
@@ -36,7 +36,7 @@ RSpec.describe IncidentManagement::CreateIssueService do
context
'without issue_template_content'
do
it
'creates an issue with alert summary only'
do
expect
(
subject
).
to
include
(
status: :success
)
expect
(
execute
).
to
be_success
expect
(
issue
.
author
).
to
eq
(
user
)
expect
(
issue
.
title
).
to
eq
(
alert_title
)
...
...
@@ -61,7 +61,8 @@ RSpec.describe IncidentManagement::CreateIssueService do
.
to
receive
(
:log_error
)
.
with
(
error_message
(
issue_error
))
expect
(
subject
).
to
include
(
status: :error
,
message:
issue_error
)
expect
(
execute
).
to
be_error
expect
(
execute
.
message
).
to
eq
(
issue_error
)
end
end
...
...
@@ -70,7 +71,7 @@ RSpec.describe IncidentManagement::CreateIssueService do
let
(
:template_content
)
{
'some content'
}
it
'creates an issue appending issue template'
do
expect
(
subject
).
to
include
(
status: :success
)
expect
(
execute
).
to
be_success
expect
(
issue
.
description
).
to
include
(
alert_presenter
.
issue_summary_markdown
)
expect
(
separator_count
(
issue
.
description
)).
to
eq
(
1
)
...
...
@@ -95,7 +96,7 @@ RSpec.describe IncidentManagement::CreateIssueService do
end
it
'creates an issue interpreting quick actions'
do
expect
(
subject
).
to
include
(
status: :success
)
expect
(
execute
).
to
be_success
expect
(
issue
.
description
).
to
include
(
plain_text
)
expect
(
issue
.
due_date
).
to
be_present
...
...
@@ -128,7 +129,7 @@ RSpec.describe IncidentManagement::CreateIssueService do
end
it
'includes both templates'
do
expect
(
subject
).
to
include
(
status: :success
)
expect
(
execute
).
to
be_success
expect
(
issue
.
description
).
to
include
(
alert_presenter
.
issue_summary_markdown
)
expect
(
issue
.
description
).
to
include
(
template_content
)
...
...
@@ -162,7 +163,7 @@ RSpec.describe IncidentManagement::CreateIssueService do
it
'creates an issue'
do
query_title
=
"
#{
gitlab_alert
.
title
}
#{
gitlab_alert
.
computed_operator
}
#{
gitlab_alert
.
threshold
}
"
expect
(
subject
).
to
include
(
status: :success
)
expect
(
execute
).
to
be_success
expect
(
issue
.
author
).
to
eq
(
user
)
expect
(
issue
.
title
).
to
eq
(
alert_presenter
.
full_title
)
...
...
@@ -181,7 +182,8 @@ RSpec.describe IncidentManagement::CreateIssueService do
.
to
receive
(
:log_error
)
.
with
(
error_message
(
'invalid alert'
))
expect
(
subject
).
to
eq
(
status: :error
,
message:
'invalid alert'
)
expect
(
execute
).
to
be_error
expect
(
execute
.
message
).
to
eq
(
'invalid alert'
)
end
end
...
...
@@ -209,7 +211,8 @@ RSpec.describe IncidentManagement::CreateIssueService do
.
to
receive
(
:log_error
)
.
with
(
error_message
(
'setting disabled'
))
expect
(
subject
).
to
eq
(
status: :error
,
message:
'setting disabled'
)
expect
(
execute
).
to
be_error
expect
(
execute
.
message
).
to
eq
(
'setting disabled'
)
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