summaryrefslogtreecommitdiff
path: root/app/services/projects/after_rename_service.rb
diff options
context:
space:
mode:
authorGabriel Mazetto <brodock@gmail.com>2019-01-22 04:33:32 +0100
committerGabriel Mazetto <brodock@gmail.com>2019-01-22 13:55:18 +0100
commitd391dfb4acd1c75857b1578c449b0e508fc8a0ed (patch)
tree8899b80cb615dd518efe2b8a614c177ab0ca0b89 /app/services/projects/after_rename_service.rb
parent7a7948e64b2d5bd9f00f9f58862b0a0599e78c83 (diff)
downloadgitlab-ce-d391dfb4acd1c75857b1578c449b0e508fc8a0ed.tar.gz
Refactored AfterRenameService to reduce coupling
We still rely on the Dirty API for project rename (before/after) values, but we don't access the dirty api from the service class anymore. The previous value is now part of the initialization, which makes it easier to test and the behavior is clearer. The same was done with the `rename_repo` on the Storage classes, we now provide before and after values as part of the method signature.
Diffstat (limited to 'app/services/projects/after_rename_service.rb')
-rw-r--r--app/services/projects/after_rename_service.rb29
1 files changed, 17 insertions, 12 deletions
diff --git a/app/services/projects/after_rename_service.rb b/app/services/projects/after_rename_service.rb
index 9ace1f85336..c3cd9d1ea4a 100644
--- a/app/services/projects/after_rename_service.rb
+++ b/app/services/projects/after_rename_service.rb
@@ -12,22 +12,27 @@ module Projects
#
# Projects::AfterRenameService.new(project).execute
class AfterRenameService
- attr_reader :project, :full_path_before, :full_path_after, :path_before
+ # @return [String] The Project being renamed.
+ attr_reader :project
- RenameFailedError = Class.new(StandardError)
+ # @return [String] The path slug the project was using, before the rename took place.
+ attr_reader :path_before
- # @param [Project] project The Project of the repository to rename.
- def initialize(project)
- @project = project
+ # @return [String] The full path of the namespace + project, before the rename took place.
+ attr_reader :full_path_before
- # The full path of the namespace + project, before the rename took place.
- @full_path_before = project.full_path_was
+ # @return [String] The full path of the namespace + project, after the rename took place.
+ attr_reader :full_path_after
- # The full path of the namespace + project, after the rename took place.
- @full_path_after = project.build_full_path
+ RenameFailedError = Class.new(StandardError)
- # The path of just the project, before the rename took place.
- @path_before = project.previous_changes['path'].first
+ # @param [Project] project The Project being renamed.
+ # @param [String] path_before The path slug the project was using, before the rename took place.
+ def initialize(project, path_before:, full_path_before:)
+ @project = project
+ @path_before = path_before
+ @full_path_before = full_path_before
+ @full_path_after = project.full_path
end
def execute
@@ -61,7 +66,7 @@ module Projects
.new(project, full_path_before)
.execute
else
- project.storage.rename_repo
+ project.storage.rename_repo(old_full_path: full_path_before, new_full_path: full_path_after)
end
rename_failed! unless success