blob: 72eecc61c96078f1aa2efb4953054cbb0f8d8b0d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
module Projects
class UpdateService < BaseService
include UpdateVisibilityLevel
def execute
unless valid_visibility_level_change?(project, params[:visibility_level])
return error('New visibility level not allowed!')
end
if renaming_project_with_container_registry_tags?
return error('Cannot rename project because it contains container registry tags!')
end
if changing_default_branch?
return error("Could not set the default branch") unless project.change_head(params[:default_branch])
end
if project.update_attributes(update_params)
if project.previous_changes.include?('path')
project.rename_repo
else
system_hook_service.execute_hooks_for(project, :update)
end
success
else
model_errors = project.errors.full_messages.to_sentence
error_message = model_errors.presence || 'Project could not be updated!'
error(error_message)
end
end
def run_auto_devops_pipeline?
params.dig(:run_auto_devops_pipeline_explicit) == 'true' || params.dig(:run_auto_devops_pipeline_implicit) == 'true'
end
private
def update_params
params.except(:default_branch, :run_auto_devops_pipeline_explicit, :run_auto_devops_pipeline_implicit)
end
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
end
end
|