Commit acf7fd1b authored by James Lopez's avatar James Lopez

Merge branch 'self-monitoring-env' into 'master'

Create an environment for self monitoring project

See merge request gitlab-org/gitlab!24403
parents 6b0599ac 79ee324c
---
title: Create an environment for self monitoring project
merge_request: 24403
author:
type: added
...@@ -15,6 +15,7 @@ module Gitlab ...@@ -15,6 +15,7 @@ module Gitlab
:create_group, :create_group,
:create_project, :create_project,
:save_project_id, :save_project_id,
:create_environment,
:add_prometheus_manual_configuration, :add_prometheus_manual_configuration,
:track_event :track_event
...@@ -80,6 +81,17 @@ module Gitlab ...@@ -80,6 +81,17 @@ module Gitlab
end end
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) def add_prometheus_manual_configuration(result)
return success(result) unless prometheus_enabled? return success(result) unless prometheus_enabled?
return success(result) unless prometheus_listen_address.present? return success(result) unless prometheus_listen_address.present?
......
...@@ -5379,6 +5379,9 @@ msgstr "" ...@@ -5379,6 +5379,9 @@ msgstr ""
msgid "Could not create Wiki Repository at this time. Please try again later." msgid "Could not create Wiki Repository at this time. Please try again later."
msgstr "" msgstr ""
msgid "Could not create environment"
msgstr ""
msgid "Could not create group" msgid "Could not create group"
msgstr "" msgstr ""
......
...@@ -125,6 +125,25 @@ describe Gitlab::DatabaseImporters::SelfMonitoring::Project::CreateService do ...@@ -125,6 +125,25 @@ describe Gitlab::DatabaseImporters::SelfMonitoring::Project::CreateService do
expect(application_setting.self_monitoring_project_id).to eq(project.id) expect(application_setting.self_monitoring_project_id).to eq(project.id)
end 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 it 'returns error when saving project ID fails' do
allow(application_setting).to receive(:update).and_call_original allow(application_setting).to receive(:update).and_call_original
allow(application_setting).to receive(:update) 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