Class: Projects::OverwriteProjectService

Inherits:
BaseService show all
Defined in:
app/services/projects/overwrite_project_service.rb

Instance Attribute Summary

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

Methods inherited from BaseService

#initialize

Methods included from BaseServiceUtility

#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level

Methods included from Gitlab::Allowable

#can?

Constructor Details

This class inherits a constructor from BaseService

Instance Method Details

#execute(source_project) ⇒ Object


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
# File 'app/services/projects/overwrite_project_service.rb', line 5

def execute(source_project)
  return unless source_project && source_project.namespace_id == @project.namespace_id

  start_time = ::Gitlab::Metrics::System.monotonic_time
  original_source_name = source_project.name
  original_source_path = source_project.path
  tmp_source_name, tmp_source_path = tmp_source_project_name(source_project)

  move_relationships_between(source_project, @project)

  source_project_rename = rename_project(source_project, tmp_source_name, tmp_source_path)

  if source_project_rename[:status] == :error
    raise 'Source project rename failed during project overwrite'
  end

  new_project_rename = rename_project(@project, original_source_name, original_source_path)

  if new_project_rename[:status] == :error
    rename_project(source_project, original_source_name, original_source_path)

    raise 'New project rename failed during project overwrite'
  end

  schedule_source_project_deletion(source_project)

  @project
rescue StandardError => e
  move_relationships_between(@project, source_project)
  remove_source_project_from_fork_network(source_project)

  raise e
ensure
  track_service(start_time, source_project, e)
end