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
Hide 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
...
@@ -14,9 +14,9 @@ module IncidentManagement
return
error_with
(
'invalid alert'
)
unless
alert
.
valid?
return
error_with
(
'invalid alert'
)
unless
alert
.
valid?
result
=
create_issue
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
end
private
private
...
@@ -62,10 +62,10 @@ module IncidentManagement
...
@@ -62,10 +62,10 @@ module IncidentManagement
incident_management_setting
.
issue_template_content
incident_management_setting
.
issue_template_content
end
end
def
error_with
(
message
)
def
error_with
(
message
,
issue
=
nil
)
log_error
(
%{Cannot create incident issue for "#{project.full_name}": #{message}}
)
log_error
(
%{Cannot create incident issue for "#{project.full_name}": #{message}}
)
error
(
message
)
ServiceResponse
.
error
(
payload:
{
issue:
issue
},
message:
message
)
end
end
end
end
end
end
app/workers/incident_management/process_alert_worker.rb
View file @
20dd843d
...
@@ -16,9 +16,10 @@ module IncidentManagement
...
@@ -16,9 +16,10 @@ module IncidentManagement
alert
=
find_alert
(
alert_id
)
alert
=
find_alert
(
alert_id
)
return
unless
alert
return
unless
alert
new_issue
=
create_issue_for
(
alert
)
result
=
create_issue_for
(
alert
)
return
unless
new_issue
&
.
persisted
?
return
unless
result
.
success
?
new_issue
=
result
.
payload
[
:issue
]
link_issue_with_alert
(
alert
,
new_issue
.
id
)
link_issue_with_alert
(
alert
,
new_issue
.
id
)
end
end
...
@@ -36,7 +37,6 @@ module IncidentManagement
...
@@ -36,7 +37,6 @@ module IncidentManagement
IncidentManagement
::
CreateIssueService
IncidentManagement
::
CreateIssueService
.
new
(
alert
.
project
,
parsed_payload
(
alert
))
.
new
(
alert
.
project
,
parsed_payload
(
alert
))
.
execute
.
execute
.
dig
(
:issue
)
end
end
def
link_issue_with_alert
(
alert
,
issue_id
)
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
...
@@ -25,10 +25,10 @@ RSpec.describe IncidentManagement::CreateIssueService do
create
(
:project_incident_management_setting
,
project:
project
)
create
(
:project_incident_management_setting
,
project:
project
)
end
end
subject
{
service
.
execute
}
subject
(
:execute
)
{
service
.
execute
}
context
'when create_issue enabled'
do
context
'when create_issue enabled'
do
let
(
:issue
)
{
subject
[
:issue
]
}
let
(
:issue
)
{
execute
.
payload
[
:issue
]
}
before
do
before
do
setting
.
update!
(
create_issue:
true
)
setting
.
update!
(
create_issue:
true
)
...
@@ -36,7 +36,7 @@ RSpec.describe IncidentManagement::CreateIssueService do
...
@@ -36,7 +36,7 @@ RSpec.describe IncidentManagement::CreateIssueService do
context
'without issue_template_content'
do
context
'without issue_template_content'
do
it
'creates an issue with alert summary only'
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
.
author
).
to
eq
(
user
)
expect
(
issue
.
title
).
to
eq
(
alert_title
)
expect
(
issue
.
title
).
to
eq
(
alert_title
)
...
@@ -61,7 +61,8 @@ RSpec.describe IncidentManagement::CreateIssueService do
...
@@ -61,7 +61,8 @@ RSpec.describe IncidentManagement::CreateIssueService do
.
to
receive
(
:log_error
)
.
to
receive
(
:log_error
)
.
with
(
error_message
(
issue_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
end
end
...
@@ -70,7 +71,7 @@ RSpec.describe IncidentManagement::CreateIssueService do
...
@@ -70,7 +71,7 @@ RSpec.describe IncidentManagement::CreateIssueService do
let
(
:template_content
)
{
'some content'
}
let
(
:template_content
)
{
'some content'
}
it
'creates an issue appending issue template'
do
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
(
issue
.
description
).
to
include
(
alert_presenter
.
issue_summary_markdown
)
expect
(
separator_count
(
issue
.
description
)).
to
eq
(
1
)
expect
(
separator_count
(
issue
.
description
)).
to
eq
(
1
)
...
@@ -95,7 +96,7 @@ RSpec.describe IncidentManagement::CreateIssueService do
...
@@ -95,7 +96,7 @@ RSpec.describe IncidentManagement::CreateIssueService do
end
end
it
'creates an issue interpreting quick actions'
do
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
.
description
).
to
include
(
plain_text
)
expect
(
issue
.
due_date
).
to
be_present
expect
(
issue
.
due_date
).
to
be_present
...
@@ -128,7 +129,7 @@ RSpec.describe IncidentManagement::CreateIssueService do
...
@@ -128,7 +129,7 @@ RSpec.describe IncidentManagement::CreateIssueService do
end
end
it
'includes both templates'
do
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
(
alert_presenter
.
issue_summary_markdown
)
expect
(
issue
.
description
).
to
include
(
template_content
)
expect
(
issue
.
description
).
to
include
(
template_content
)
...
@@ -162,7 +163,7 @@ RSpec.describe IncidentManagement::CreateIssueService do
...
@@ -162,7 +163,7 @@ RSpec.describe IncidentManagement::CreateIssueService do
it
'creates an issue'
do
it
'creates an issue'
do
query_title
=
"
#{
gitlab_alert
.
title
}
#{
gitlab_alert
.
computed_operator
}
#{
gitlab_alert
.
threshold
}
"
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
.
author
).
to
eq
(
user
)
expect
(
issue
.
title
).
to
eq
(
alert_presenter
.
full_title
)
expect
(
issue
.
title
).
to
eq
(
alert_presenter
.
full_title
)
...
@@ -181,7 +182,8 @@ RSpec.describe IncidentManagement::CreateIssueService do
...
@@ -181,7 +182,8 @@ RSpec.describe IncidentManagement::CreateIssueService do
.
to
receive
(
:log_error
)
.
to
receive
(
:log_error
)
.
with
(
error_message
(
'invalid alert'
))
.
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
end
end
...
@@ -209,7 +211,8 @@ RSpec.describe IncidentManagement::CreateIssueService do
...
@@ -209,7 +211,8 @@ RSpec.describe IncidentManagement::CreateIssueService do
.
to
receive
(
:log_error
)
.
to
receive
(
:log_error
)
.
with
(
error_message
(
'setting disabled'
))
.
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
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