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
44e01684
Commit
44e01684
authored
Mar 09, 2020
by
Peter Leitzen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement publish incident service
parent
b0843ed9
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
138 additions
and
0 deletions
+138
-0
ee/app/services/status_page/publish_incident_service.rb
ee/app/services/status_page/publish_incident_service.rb
+62
-0
ee/spec/services/status_page/publish_incident_service_spec.rb
...pec/services/status_page/publish_incident_service_spec.rb
+76
-0
No files found.
ee/app/services/status_page/publish_incident_service.rb
0 → 100644
View file @
44e01684
# frozen_string_literal: true
module
StatusPage
# Delegate work to more specific publishing services.
#
# Use this service for publishing an incident to CDN which calls:
# * StatusPage::PublishDetailsService
# * StatusPage::PublishListService
class
PublishIncidentService
include
Gitlab
::
Utils
::
StrongMemoize
def
initialize
(
project
:,
issue_id
:)
@project
=
project
@issue_id
=
issue_id
end
def
execute
return
error_issue_not_found
unless
issue
response
=
publish_details
return
response
if
response
.
error?
publish_list
end
private
attr_reader
:project
,
:issue_id
def
publish_details
PublishDetailsService
.
new
(
project:
project
).
execute
(
issue
,
user_notes
)
end
def
publish_list
PublishListService
.
new
(
project:
project
).
execute
(
issues
)
end
def
issue
strong_memoize
(
:issue
)
{
issues_finder
.
find_by_id
(
issue_id
)
}
end
def
user_notes
strong_memoize
(
:user_notes
)
do
IncidentCommentsFinder
.
new
(
issue:
issue
).
all
end
end
def
issues
strong_memoize
(
:issues
)
{
issues_finder
.
all
}
end
def
issues_finder
strong_memoize
(
:issues_finder
)
do
IncidentsFinder
.
new
(
project_id:
project
.
id
)
end
end
def
error_issue_not_found
ServiceResponse
.
error
(
message:
'Issue not found'
)
end
end
end
ee/spec/services/status_page/publish_incident_service_spec.rb
0 → 100644
View file @
44e01684
# frozen_string_literal: true
require
'spec_helper'
describe
StatusPage
::
PublishIncidentService
do
let_it_be
(
:project
,
refind:
true
)
{
create
(
:project
)
}
let_it_be
(
:issue
)
{
create
(
:issue
,
project:
project
)
}
let_it_be
(
:settings
)
{
create
(
:status_page_setting
,
:enabled
,
project:
project
)
}
let
(
:service
)
{
described_class
.
new
(
project:
project
,
issue_id:
issue
.
id
)
}
subject
(
:result
)
{
service
.
execute
}
describe
'#execute'
do
before
do
stub_licensed_features
(
status_page:
true
)
end
context
'when publishing succeeds'
do
it
'returns uploads incidents details and list'
do
expect_to_upload_details
(
issue
)
expect_to_upload_list
expect
(
result
).
to
be_success
end
end
context
'when uploading details fails'
do
it
'returns error and skip list upload'
do
expect_to_upload_details
(
issue
,
status:
404
)
expect
(
result
).
to
be_error
path
=
StatusPage
::
Storage
.
details_path
(
issue
.
iid
)
expect
(
result
.
message
).
to
include
(
'NotFound'
)
expect
(
result
.
message
).
to
include
(
path
)
end
end
context
'when uploading list fails'
do
it
'returns error and skip list upload'
do
expect_to_upload_details
(
issue
)
expect_to_upload_list
(
status:
404
)
expect
(
result
).
to
be_error
path
=
StatusPage
::
Storage
.
list_path
expect
(
result
.
message
).
to
include
(
'NotFound'
)
expect
(
result
.
message
).
to
include
(
path
)
end
end
context
'with unrelated issue'
do
let
(
:issue
)
{
create
(
:issue
)
}
it
'returns error issue not found'
do
expect
(
result
).
to
be_error
expect
(
result
.
message
).
to
eq
(
'Issue not found'
)
end
end
end
private
def
expect_to_upload_details
(
issue
,
**
kwargs
)
stub_upload_request
(
StatusPage
::
Storage
.
details_path
(
issue
.
iid
),
**
kwargs
)
end
def
expect_to_upload_list
(
**
kwargs
)
stub_upload_request
(
StatusPage
::
Storage
.
list_path
,
**
kwargs
)
end
def
stub_upload_request
(
path
,
status:
200
)
stub_request
(
:put
,
%r{amazonaws.com/
#{
path
}
}
).
to_return
(
status:
status
)
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