Class: Makit::Services::RepositoryManager
- Inherits:
-
Object
- Object
- Makit::Services::RepositoryManager
- Defined in:
- lib/makit/services/repository_manager.rb
Overview
Service class responsible for git repository management operations Handles cloning, pulling, logging, and working directory setup
This class now acts as a Ruby wrapper around the gRPC service implementation, maintaining backward compatibility while providing the benefits of the new architecture.
Class Method Summary collapse
-
.clone_or_pull_repository(git_repository) ⇒ Array<Makit::V1::Command>
Clone repository if it doesn’t exist, otherwise pull latest changes.
-
.clone_repository(git_repository) ⇒ Array<Makit::V1::Command>
Clone a git repository to a local directory.
-
.get_latest_commit(clone_dir, commands) ⇒ String
Get the latest commit hash from a repository.
-
.get_repository_log(git_repository, limit, skip) ⇒ Array<Makit::V1::GitLogEntry>
Get git log information for a repository.
-
.initialize_repository(directory) ⇒ Makit::V1::Command
Initialize a new git repository in the specified directory.
-
.pull_repository(git_repository) ⇒ Makit::V1::Command
Pull the latest changes from the remote repository.
-
.setup_work_directory(repository) ⇒ nil
Set up a work directory for a repository.
-
.validate_clone_directory(url) ⇒ String
Validate that a clone directory exists for the given repository.
Class Method Details
.clone_or_pull_repository(git_repository) ⇒ Array<Makit::V1::Command>
Clone repository if it doesn’t exist, otherwise pull latest changes
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/makit/services/repository_manager.rb', line 96 def clone_or_pull_repository(git_repository) # Create a new repository model directly model = create_empty_repository_model # Call the gRPC service request = Makit::V1::Services::CloneOrPullRepositoryRequest.new( model: convert_to_proto_model(model), git_repository: git_repository ) result_model = Makit::V1::Services::RepositoryManagerServiceImpl.new.clone_or_pull_repository(request, nil) # Convert back to Ruby model and extract command results ruby_model = convert_from_proto_model(result_model) # Convert command results to Makit::V1::Command objects ruby_model.command_results.map { |result| create_command_from_result(result) } end |
.clone_repository(git_repository) ⇒ Array<Makit::V1::Command>
Clone a git repository to a local directory
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/makit/services/repository_manager.rb', line 47 def clone_repository(git_repository) # Create a new repository model directly model = create_empty_repository_model # Call the gRPC service request = Makit::V1::Services::CloneRepositoryRequest.new( model: convert_to_proto_model(model), git_repository: git_repository ) result_model = Makit::V1::Services::RepositoryManagerServiceImpl.new.clone_repository(request, nil) # Convert back to Ruby model and extract command results ruby_model = convert_from_proto_model(result_model) # Convert command results to Makit::V1::Command objects ruby_model.command_results.map { |result| create_command_from_result(result) } end |
.get_latest_commit(clone_dir, commands) ⇒ String
Get the latest commit hash from a repository
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/makit/services/repository_manager.rb', line 167 def get_latest_commit(clone_dir, commands) # Create a new repository model directly model = create_empty_repository_model # Call the gRPC service request = Makit::V1::Services::GetLatestCommitRequest.new( model: convert_to_proto_model(model), clone_dir: clone_dir ) result_model = Makit::V1::Services::RepositoryManagerServiceImpl.new.get_latest_commit(request, nil) # Convert back to Ruby model ruby_model = convert_from_proto_model(result_model) # Append command results to the provided commands array ruby_model.command_results.each { |result| commands << create_command_from_result(result) } # Return the latest commit hash ruby_model.latest_commit_hash || "" end |
.get_repository_log(git_repository, limit, skip) ⇒ Array<Makit::V1::GitLogEntry>
Get git log information for a repository
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/makit/services/repository_manager.rb', line 121 def get_repository_log(git_repository, limit, skip) # Create a new repository model directly model = create_empty_repository_model # Call the gRPC service request = Makit::V1::Services::GetRepositoryLogRequest.new( model: convert_to_proto_model(model), git_repository: git_repository, limit: limit, skip: skip ) result_model = Makit::V1::Services::RepositoryManagerServiceImpl.new.get_repository_log(request, nil) # Convert back to Ruby model and extract git log entries ruby_model = convert_from_proto_model(result_model) # Convert to Makit::V1::GitLogEntry objects ruby_model.git_log_entries.map { |entry| create_git_log_entry_from_model(entry) } end |
.initialize_repository(directory) ⇒ Makit::V1::Command
Initialize a new git repository in the specified directory
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/makit/services/repository_manager.rb', line 21 def initialize_repository(directory) # Create a new repository model directly model = create_empty_repository_model # Call the gRPC service request = Makit::V1::Services::InitializeRepositoryRequest.new( model: convert_to_proto_model(model), directory: directory ) result_model = Makit::V1::Services::RepositoryManagerServiceImpl.new.initialize_repository(request, nil) # Convert back to Ruby model and extract the command result ruby_model = convert_from_proto_model(result_model) # Return the last command result as a Makit::V1::Command return create_command_from_result(ruby_model.command_results.last) if ruby_model.command_results.any? # Fallback: create a mock command if no results create_mock_command(0, "Repository initialized", "") end |
.pull_repository(git_repository) ⇒ Makit::V1::Command
Pull the latest changes from the remote repository
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/makit/services/repository_manager.rb', line 70 def pull_repository(git_repository) # Create a new repository model directly model = create_empty_repository_model # Call the gRPC service request = Makit::V1::Services::PullRepositoryRequest.new( model: convert_to_proto_model(model), git_repository: git_repository ) result_model = Makit::V1::Services::RepositoryManagerServiceImpl.new.pull_repository(request, nil) # Convert back to Ruby model and extract the command result ruby_model = convert_from_proto_model(result_model) # Return the last command result as a Makit::V1::Command return create_command_from_result(ruby_model.command_results.last) if ruby_model.command_results.any? # Fallback: create a mock command if no results create_mock_command(0, "Repository pulled", "") end |
.setup_work_directory(repository) ⇒ nil
Set up a work directory for a repository
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/makit/services/repository_manager.rb', line 146 def setup_work_directory(repository) # Create a new repository model directly model = create_empty_repository_model # Call the gRPC service request = Makit::V1::Services::SetupWorkDirectoryRequest.new( model: convert_to_proto_model(model), repository: repository ) Makit::V1::Services::RepositoryManagerServiceImpl.new.setup_work_directory(request, nil) # Always return nil as per original API nil end |
.validate_clone_directory(url) ⇒ String
Validate that a clone directory exists for the given repository
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/makit/services/repository_manager.rb', line 193 def validate_clone_directory(url) # Create a new repository model directly model = create_empty_repository_model # Call the gRPC service request = Makit::V1::Services::ValidateCloneDirectoryRequest.new( model: convert_to_proto_model(model), url: url ) result_model = Makit::V1::Services::RepositoryManagerServiceImpl.new.validate_clone_directory(request, nil) # Convert back to Ruby model and return clone directory ruby_model = convert_from_proto_model(result_model) ruby_model.clone_directory || "" end |