gitlab-org--gitlab-foss/app/services/projects/update_service.rb
Tommy Beadle 0de335eced Add a system hook for when a project is updated.
This sends a project_update hook when a repo is updated.  This does not include
renaming or transferring a project.  Those are covered by project_rename and
project_transfer.  This will get called, however, when the visibility is
changed.
2017-01-26 09:09:14 -05:00

35 lines
1 KiB
Ruby

module Projects
class UpdateService < BaseService
def execute
# check that user is allowed to set specified visibility_level
new_visibility = params[:visibility_level]
if new_visibility && new_visibility.to_i != project.visibility_level
unless can?(current_user, :change_visibility_level, project) &&
Gitlab::VisibilityLevel.allowed_for?(current_user, new_visibility)
deny_visibility_level(project, new_visibility)
return error('Visibility level unallowed')
end
end
new_branch = params[:default_branch]
if project.repository.exists? && new_branch && new_branch != project.default_branch
project.change_head(new_branch)
end
if project.update_attributes(params.except(:default_branch))
if project.previous_changes.include?('path')
project.rename_repo
else
system_hook_service.execute_hooks_for(project, :update)
end
success
else
error('Project could not be updated')
end
end
end
end