Commit 79ee324c authored by Kirstie Cook's avatar Kirstie Cook Committed by James Lopez

Create an environment for self monitoring project

parent 5f6d1b6f
---
title: Create an environment for self monitoring project
merge_request: 24403
author:
type: added
......@@ -15,6 +15,7 @@ module Gitlab
:create_group,
:create_project,
:save_project_id,
:create_environment,
:add_prometheus_manual_configuration,
:track_event
......@@ -80,6 +81,17 @@ module Gitlab
end
end
def create_environment(result)
environment = ::Environment.new(project_id: result[:project].id, name: 'production')
if environment.save
success(result)
else
log_error("Could not create environment for the Self monitoring project. Errors: %{errors}" % { errors: environment.errors.full_messages })
error(_('Could not create environment'))
end
end
def add_prometheus_manual_configuration(result)
return success(result) unless prometheus_enabled?
return success(result) unless prometheus_listen_address.present?
......
......@@ -5379,6 +5379,9 @@ msgstr ""
msgid "Could not create Wiki Repository at this time. Please try again later."
msgstr ""
msgid "Could not create environment"
msgstr ""
msgid "Could not create group"
msgstr ""
......
......@@ -125,6 +125,25 @@ describe Gitlab::DatabaseImporters::SelfMonitoring::Project::CreateService do
expect(application_setting.self_monitoring_project_id).to eq(project.id)
end
it 'creates an environment for the project' do
expect(project.default_environment.name).to eq('production')
end
context 'when the environment creation fails' do
let(:environment) { build(:environment, name: 'production') }
it 'returns error' do
allow(Environment).to receive(:new).and_return(environment)
allow(environment).to receive(:save).and_return(false)
expect(result).to eq(
status: :error,
message: 'Could not create environment',
last_step: :create_environment
)
end
end
it 'returns error when saving project ID fails' do
allow(application_setting).to receive(:update).and_call_original
allow(application_setting).to receive(:update)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment