From d0e1aa3d63e12fbee449baa5f7356f0c3e895841 Mon Sep 17 00:00:00 2001 From: devilsautumn Date: Fri, 27 Sep 2024 15:29:11 +0530 Subject: [PATCH] initialie repo with url --- .../zango/api/platform/tenancy/v1/serializers.py | 1 - .../src/zango/api/platform/tenancy/v1/views.py | 16 ++++++++++++---- backend/src/zango/cli/git_setup.py | 1 + 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/backend/src/zango/api/platform/tenancy/v1/serializers.py b/backend/src/zango/api/platform/tenancy/v1/serializers.py index 7d8449d3..dcae71ee 100644 --- a/backend/src/zango/api/platform/tenancy/v1/serializers.py +++ b/backend/src/zango/api/platform/tenancy/v1/serializers.py @@ -41,7 +41,6 @@ def get_date_format_display(self, obj): def update(self, instance, validated_data): request = self.context["request"] extra_config_str = request.data.get("extra_config") - # Convert extra_config from string to JSON if it exists if extra_config_str: try: diff --git a/backend/src/zango/api/platform/tenancy/v1/views.py b/backend/src/zango/api/platform/tenancy/v1/views.py index e126ce54..4160c7cc 100644 --- a/backend/src/zango/api/platform/tenancy/v1/views.py +++ b/backend/src/zango/api/platform/tenancy/v1/views.py @@ -152,13 +152,14 @@ def get(self, request, *args, **kwargs): return get_api_response(success, response, status) - def get_branch(config, key, default): + def get_branch(self, config, key, default): branch = config.get('branch', {}).get(key, default) return branch if branch else default def put(self, request, *args, **kwargs): try: obj = self.get_obj(**kwargs) + old_git_config = obj.extra_config.get("git_config", {}) if obj.extra_config else {} serializer = TenantSerializerModel( instance=obj, data=request.data, @@ -172,19 +173,26 @@ def put(self, request, *args, **kwargs): if serializer.data.get("extra_config", None): app_directory = os.path.join(os.getcwd(), "workspaces", obj.name) new_git_config = serializer.data["extra_config"].get("git_config", {}) - old_git_config = obj.extra_config.get("git_config", {}) if obj.extra_config else {} new_repo_url = new_git_config.get("repo_url") old_repo_url = old_git_config.get("repo_url") + # if repo_url is null, clean the repository + if not new_repo_url: + os.system(f"rm -rf {app_directory}/.git") if new_repo_url and (not old_git_config or new_repo_url != old_repo_url): git_setup( - app_directory, + [app_directory, + "--git_repo_url", new_repo_url, + "--dev_branch", self.get_branch(new_git_config, "dev", "development"), + "--staging_branch", self.get_branch(new_git_config, "staging", "staging"), + "--prod_branch", self.get_branch(new_git_config, "prod", "main"), - True + "--initialize"], + standalone_mode=False ) result = { diff --git a/backend/src/zango/cli/git_setup.py b/backend/src/zango/cli/git_setup.py index 620785f1..c2a82a55 100644 --- a/backend/src/zango/cli/git_setup.py +++ b/backend/src/zango/cli/git_setup.py @@ -130,6 +130,7 @@ def git_setup( try: if initialize: + os.system(f"rm -rf {app_directory}/.git") # Initialize git repository repo = git.Repo.init(app_directory)