factory.py 873 B

12345678910111213141516171819202122
  1. """Factory for instantiating the correct Git provider backend."""
  2. from backend.app.services.git_providers.base import GitProviderBackend
  3. from backend.app.services.git_providers.forgejo import ForgejoBackend
  4. from backend.app.services.git_providers.gitea import GiteaBackend
  5. from backend.app.services.git_providers.github import GitHubBackend
  6. from backend.app.services.git_providers.gitlab import GitLabBackend
  7. _BACKENDS: dict[str, type[GitProviderBackend]] = {
  8. "github": GitHubBackend,
  9. "gitea": GiteaBackend,
  10. "forgejo": ForgejoBackend,
  11. "gitlab": GitLabBackend,
  12. }
  13. def get_provider_backend(provider: str) -> GitProviderBackend:
  14. """Return an instantiated backend for the given provider key."""
  15. backend_cls = _BACKENDS.get(provider)
  16. if backend_cls is None:
  17. raise ValueError(f"Unknown Git provider: {provider!r}")
  18. return backend_cls()