-
Notifications
You must be signed in to change notification settings - Fork 8
Description
Is your feature request related to a problem? Please describe.
The codebase has duplicated git repository preparation logic across multiple chain handlers (put_deploy_configs, put_gitlab_ci_config). Each handler independently retrieves GitServer resources, extracts SSH credentials, clones repositories, and checks out branches, leading to code duplication and increased maintenance burden.
Describe the solution you'd like
Extract the common git repository preparation workflow into a reusable function:
- Create a
GitRepositoryContextstruct to hold necessary git operation context (GitServer, Secret, SSH keys, URLs, working directory) - Implement a
PrepareGitRepositoryfunction that handles:- GitServer resource and Secret retrieval
- SSH credential extraction
- Repository cloning (if needed)
- Default branch checkout
- Refactor existing chain handlers to use this common function
- Add comprehensive unit tests for the new functionality
Describe alternatives you've considered
- Keep the current duplicated code - rejected due to maintainability concerns
- Use a builder pattern - overly complex for this straightforward use case
- Create a separate service struct - adds unnecessary abstraction
Additional context
This refactoring improves code maintainability by centralizing git operations setup logic and makes it easier to add new chain handlers that require similar git operations. The change affects put_deploy_configs.go and put_gitlab_ci_config.go, reducing ~50 lines of duplicated code per handler.