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
9d6b948c
Commit
9d6b948c
authored
Oct 29, 2020
by
Sean Arnold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create integration if not existing
- Update specs to match - Remove comment
parent
1a21f2c6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
12 deletions
+44
-12
app/services/alert_management/sync_alert_service_data_service.rb
...vices/alert_management/sync_alert_service_data_service.rb
+18
-2
db/migrate/20201027002551_migrate_services_to_http_integrations.rb
...e/20201027002551_migrate_services_to_http_integrations.rb
+1
-4
spec/services/alert_management/sync_alert_service_data_service_spec.rb
.../alert_management/sync_alert_service_data_service_spec.rb
+25
-6
No files found.
app/services/alert_management/sync_alert_service_data_service.rb
View file @
9d6b948c
...
...
@@ -10,9 +10,12 @@ module AlertManagement
def
execute
http_integration
=
find_http_integration
return
ServiceResponse
.
success
(
message:
'HTTP Integration not found'
)
unless
http_integration
result
=
if
http_integration
update_integration_data
(
http_integration
)
else
create_integration
end
result
=
update_integration_data
(
http_integration
)
result
?
ServiceResponse
.
success
:
ServiceResponse
.
error
(
message:
'Update failed'
)
end
...
...
@@ -29,6 +32,19 @@ module AlertManagement
.
first
end
def
create_integration
new_integration
=
AlertManagement
::
HttpIntegration
.
create
(
project_id:
alert_service
.
project_id
,
name:
'HTTP endpoint'
,
endpoint_identifier:
AlertManagement
::
HttpIntegration
::
LEGACY_IDENTIFIER
,
active:
alert_service
.
active
,
encrypted_token:
alert_service
.
data
.
encrypted_token
,
encrypted_token_iv:
alert_service
.
data
.
encrypted_token_iv
)
new_integration
.
persisted?
end
def
update_integration_data
(
http_integration
)
http_integration
.
update
(
active:
alert_service
.
active
,
...
...
db/migrate/20201027002551_migrate_services_to_http_integrations.rb
View file @
9d6b948c
# frozen_string_literal: true
# See https://docs.gitlab.com/ee/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class
MigrateServicesToHttpIntegrations
<
ActiveRecord
::
Migration
[
6.0
]
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
ALERT_SERVICE_TYPE
=
'AlertsService'
SERVICE_NAMES_IDENTIFIER
=
{
name:
'
Legacy E
ndpoint'
,
name:
'
HTTP e
ndpoint'
,
identifier:
'legacy'
}
...
...
spec/services/alert_management/sync_alert_service_data_service_spec.rb
View file @
9d6b948c
...
...
@@ -3,12 +3,23 @@
require
'spec_helper'
RSpec
.
describe
AlertManagement
::
SyncAlertServiceDataService
do
let_it_be
(
:alerts_service
)
{
create
(
:alerts_service
,
:active
)
}
let_it_be
(
:alerts_service
)
do
AlertsService
.
skip_callback
(
:save
,
:after
,
:update_http_integration
)
service
=
create
(
:alerts_service
,
:active
)
AlertsService
.
set_callback
(
:save
,
:after
,
:update_http_integration
)
service
end
describe
'#execute'
do
subject
{
described_class
.
new
(
alerts_service
).
execute
}
subject
(
:execute
)
{
described_class
.
new
(
alerts_service
).
execute
}
context
'without http integration'
do
it
'creates the integration'
do
expect
{
execute
}
.
to
change
{
AlertManagement
::
HttpIntegration
.
count
}.
by
(
1
)
end
it
'returns a success'
do
expect
(
subject
.
success?
).
to
eq
(
true
)
end
...
...
@@ -18,18 +29,26 @@ RSpec.describe AlertManagement::SyncAlertServiceDataService do
let_it_be
(
:integration
)
{
create
(
:alert_management_http_integration
,
:legacy
,
project:
alerts_service
.
project
)
}
it
'updates the integration'
do
expect
{
subject
}
expect
{
execute
}
.
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
it
'returns a success'
do
expect
(
subject
.
success?
).
to
eq
(
true
)
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
}
it
'creates the integration'
do
expect
{
execute
}
.
to
change
{
AlertManagement
::
HttpIntegration
.
count
}.
by
(
1
)
end
it
'returns a success'
do
expect
(
subject
.
success?
).
to
eq
(
true
)
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