Project creation does not fail silently on DB related changes
This commit is contained in:
parent
c628f8f426
commit
bf4a3af06a
|
@ -90,9 +90,6 @@ module Projects
|
|||
unless @project.gitlab_project_import?
|
||||
@project.write_repository_config
|
||||
@project.create_wiki unless skip_wiki?
|
||||
create_services_from_active_templates(@project)
|
||||
|
||||
@project.create_labels
|
||||
end
|
||||
|
||||
event_service.create_project(@project, current_user)
|
||||
|
@ -121,21 +118,27 @@ module Projects
|
|||
Project.transaction do
|
||||
@project.create_or_update_import_data(data: import_data[:data], credentials: import_data[:credentials]) if import_data
|
||||
|
||||
if @project.save && !@project.import?
|
||||
raise 'Failed to create repository' unless @project.create_repository
|
||||
if @project.save
|
||||
unless @project.gitlab_project_import?
|
||||
create_services_from_active_templates(@project)
|
||||
@project.create_labels
|
||||
end
|
||||
|
||||
unless @project.import?
|
||||
raise 'Failed to create repository' unless @project.create_repository
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def fail(error:)
|
||||
message = "Unable to save project. Error: #{error}"
|
||||
message << "Project ID: #{@project.id}" if @project && @project.id
|
||||
|
||||
Rails.logger.error(message)
|
||||
|
||||
if @project && @project.import?
|
||||
if @project
|
||||
@project.errors.add(:base, message)
|
||||
@project.mark_import_as_failed(message)
|
||||
@project.mark_import_as_failed(message) if @project.import?
|
||||
end
|
||||
|
||||
@project
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
title: Project creation will now raise an error if a service template is invalid
|
||||
merge_request: 18013
|
||||
author:
|
||||
type: fixed
|
|
@ -70,6 +70,16 @@ describe Projects::CreateService, '#execute' do
|
|||
opts[:default_branch] = 'master'
|
||||
expect(create_project(user, opts)).to eq(nil)
|
||||
end
|
||||
|
||||
it 'handles invalid service' do
|
||||
create(:service, type: 'JiraService', project: nil, template: true, active: true)
|
||||
|
||||
project = create_project(user, opts)
|
||||
|
||||
expect(project).not_to be_persisted
|
||||
expect(project.errors.full_messages_for(:base).first).to match(/Unable to save project. Error: Unable to save JiraService/)
|
||||
expect(project.services.count).to eq 0
|
||||
end
|
||||
end
|
||||
|
||||
context 'wiki_enabled creates repository directory' do
|
||||
|
|
Loading…
Reference in New Issue