2014-09-02 18:07:02 +05:30
|
|
|
module Projects
|
|
|
|
class UpdateService < BaseService
|
2018-03-17 18:26:18 +05:30
|
|
|
include UpdateVisibilityLevel
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
def execute
|
2018-03-17 18:26:18 +05:30
|
|
|
unless valid_visibility_level_change?(project, params[:visibility_level])
|
2017-09-10 17:25:29 +05:30
|
|
|
return error('New visibility level not allowed!')
|
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
if renaming_project_with_container_registry_tags?
|
|
|
|
return error('Cannot rename project because it contains container registry tags!')
|
|
|
|
end
|
2016-08-24 12:49:21 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
if changing_default_branch?
|
2018-03-17 18:26:18 +05:30
|
|
|
return error("Could not set the default branch") unless project.change_head(params[:default_branch])
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
if project.update_attributes(params.except(:default_branch))
|
2014-09-02 18:07:02 +05:30
|
|
|
if project.previous_changes.include?('path')
|
|
|
|
project.rename_repo
|
2017-08-17 22:00:37 +05:30
|
|
|
else
|
|
|
|
system_hook_service.execute_hooks_for(project, :update)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
success
|
|
|
|
else
|
2018-03-17 18:26:18 +05:30
|
|
|
model_errors = project.errors.full_messages.to_sentence
|
|
|
|
error_message = model_errors.presence || 'Project could not be updated!'
|
|
|
|
|
|
|
|
error(error_message)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
def run_auto_devops_pipeline?
|
|
|
|
return false if project.repository.gitlab_ci_yml || !project.auto_devops.previous_changes.include?('enabled')
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
project.auto_devops.enabled? || (project.auto_devops.enabled.nil? && Gitlab::CurrentSettings.auto_devops_enabled?)
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
private
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
def renaming_project_with_container_registry_tags?
|
|
|
|
new_path = params[:path]
|
|
|
|
|
|
|
|
new_path && new_path != project.path &&
|
|
|
|
project.has_container_registry_tags?
|
|
|
|
end
|
|
|
|
|
|
|
|
def changing_default_branch?
|
|
|
|
new_branch = params[:default_branch]
|
|
|
|
|
|
|
|
project.repository.exists? &&
|
|
|
|
new_branch && new_branch != project.default_branch
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|