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
7e70ed4c
Commit
7e70ed4c
authored
Oct 27, 2020
by
Sean Arnold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add service to sync data to http integration
Add new specs + factories
parent
ada686ef
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
99 additions
and
0 deletions
+99
-0
app/models/project_services/alerts_service.rb
app/models/project_services/alerts_service.rb
+10
-0
app/services/alert_management/sync_alert_service_data_service.rb
...vices/alert_management/sync_alert_service_data_service.rb
+41
-0
spec/factories/alerts_service_data.rb
spec/factories/alerts_service_data.rb
+8
-0
spec/factories/services.rb
spec/factories/services.rb
+4
-0
spec/services/alert_management/sync_alert_service_data_service_spec.rb
.../alert_management/sync_alert_service_data_service_spec.rb
+36
-0
No files found.
app/models/project_services/alerts_service.rb
View file @
7e70ed4c
...
@@ -14,6 +14,8 @@ class AlertsService < Service
...
@@ -14,6 +14,8 @@ class AlertsService < Service
before_validation
:prevent_token_assignment
before_validation
:prevent_token_assignment
before_validation
:ensure_token
,
if: :activated?
before_validation
:ensure_token
,
if: :activated?
after_save
:update_http_integration
def
url
def
url
return
if
instance?
||
template?
return
if
instance?
||
template?
...
@@ -77,6 +79,14 @@ class AlertsService < Service
...
@@ -77,6 +79,14 @@ class AlertsService < Service
def
url_helpers
def
url_helpers
Gitlab
::
Routing
.
url_helpers
Gitlab
::
Routing
.
url_helpers
end
end
def
update_http_integration
return
unless
type
==
'AlertsService'
AlertManagement
::
SyncAlertServiceDataService
# rubocop: disable CodeReuse/ServiceClass
.
new
(
self
)
.
execute
end
end
end
AlertsService
.
prepend_if_ee
(
'EE::AlertsService'
)
AlertsService
.
prepend_if_ee
(
'EE::AlertsService'
)
app/services/alert_management/sync_alert_service_data_service.rb
0 → 100644
View file @
7e70ed4c
# frozen_string_literal: true
module
AlertManagement
class
SyncAlertServiceDataService
# @param alert_service [AlertsService]
def
initialize
(
alert_service
)
@alert_service
=
alert_service
end
def
execute
http_integration
=
find_http_integration
return
ServiceResponse
.
success
(
message:
'HTTP Integration not found'
)
unless
http_integration
result
=
update_integration_data
(
http_integration
)
result
?
ServiceResponse
.
success
:
ServiceResponse
.
error
(
message:
'Update failed'
)
end
private
attr_reader
:alert_service
def
find_http_integration
AlertManagement
::
HttpIntegrationsFinder
.
new
(
alert_service
.
project
,
endpoint_identifier:
::
AlertManagement
::
HttpIntegration
::
LEGACY_IDENTIFIER
)
.
execute
.
first
end
def
update_integration_data
(
http_integration
)
http_integration
.
update!
(
active:
alert_service
.
active
,
encrypted_token:
alert_service
.
data
.
encrypted_token
,
encrypted_token_iv:
alert_service
.
data
.
encrypted_token_iv
)
end
end
end
spec/factories/alerts_service_data.rb
0 → 100644
View file @
7e70ed4c
# frozen_string_literal: true
FactoryBot
.
define
do
factory
:alerts_service_data
do
service
{
association
(
:alerts_service
)
}
token
{
SecureRandom
.
hex
}
end
end
spec/factories/services.rb
View file @
7e70ed4c
...
@@ -56,6 +56,10 @@ FactoryBot.define do
...
@@ -56,6 +56,10 @@ FactoryBot.define do
trait
:inactive
do
trait
:inactive
do
active
{
false
}
active
{
false
}
end
end
before
(
:create
)
do
|
service
|
service
.
data
=
build
(
:alerts_service_data
,
service:
service
)
end
end
end
factory
:drone_ci_service
do
factory
:drone_ci_service
do
...
...
spec/services/alert_management/sync_alert_service_data_service_spec.rb
0 → 100644
View file @
7e70ed4c
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
AlertManagement
::
SyncAlertServiceDataService
do
let_it_be
(
:alerts_service
)
{
create
(
:alerts_service
,
:active
)
}
describe
'#execute'
do
subject
{
described_class
.
new
(
alerts_service
).
execute
}
context
'without http integration'
do
it
'returns a success'
do
expect
(
subject
.
success?
).
to
eq
(
true
)
end
end
context
'existing legacy http integration'
do
let_it_be
(
:integration
)
{
create
(
:alert_management_http_integration
,
:legacy
,
project:
alerts_service
.
project
)
}
it
'updates the integration'
do
expect
{
subject
}
.
to
change
{
integration
.
reload
.
encrypted_token
}.
to
(
alerts_service
.
data
.
encrypted_token
)
.
and
change
{
integration
.
encrypted_token_iv
}.
to
(
alerts_service
.
data
.
encrypted_token_iv
)
end
end
context
'existing other http integration'
do
let_it_be
(
:integration
)
{
create
(
:alert_management_http_integration
,
project:
alerts_service
.
project
)
}
it
'does not update the integration'
do
expect
{
subject
}
.
not_to
change
{
integration
}
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