BigW Consortium Gitlab

Commit bf4a3af0 by Tiago Botelho

Project creation does not fail silently on DB related changes

parent c628f8f4
...@@ -90,9 +90,6 @@ module Projects ...@@ -90,9 +90,6 @@ module Projects
unless @project.gitlab_project_import? unless @project.gitlab_project_import?
@project.write_repository_config @project.write_repository_config
@project.create_wiki unless skip_wiki? @project.create_wiki unless skip_wiki?
create_services_from_active_templates(@project)
@project.create_labels
end end
event_service.create_project(@project, current_user) event_service.create_project(@project, current_user)
...@@ -121,21 +118,27 @@ module Projects ...@@ -121,21 +118,27 @@ module Projects
Project.transaction do Project.transaction do
@project.create_or_update_import_data(data: import_data[:data], credentials: import_data[:credentials]) if import_data @project.create_or_update_import_data(data: import_data[:data], credentials: import_data[:credentials]) if import_data
if @project.save && !@project.import? if @project.save
raise 'Failed to create repository' unless @project.create_repository 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 end
end end
def fail(error:) def fail(error:)
message = "Unable to save project. Error: #{error}" message = "Unable to save project. Error: #{error}"
message << "Project ID: #{@project.id}" if @project && @project.id
Rails.logger.error(message) Rails.logger.error(message)
if @project && @project.import? if @project
@project.errors.add(:base, message) @project.errors.add(:base, message)
@project.mark_import_as_failed(message) @project.mark_import_as_failed(message) if @project.import?
end end
@project @project
......
---
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 ...@@ -70,6 +70,16 @@ describe Projects::CreateService, '#execute' do
opts[:default_branch] = 'master' opts[:default_branch] = 'master'
expect(create_project(user, opts)).to eq(nil) expect(create_project(user, opts)).to eq(nil)
end 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 end
context 'wiki_enabled creates repository directory' do context 'wiki_enabled creates repository directory' do
......
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