Skip to content

Commit

Permalink
app_name argument added
Browse files Browse the repository at this point in the history
  • Loading branch information
deepakdinesh1123 committed Oct 28, 2024
1 parent e335d38 commit 5b31311
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
4 changes: 1 addition & 3 deletions backend/src/zango/api/platform/tenancy/v1/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import json
import os
import traceback

from django_celery_results.models import TaskResult
Expand Down Expand Up @@ -192,7 +191,6 @@ def put(self, request, *args, **kwargs):
success = True
status_code = 200
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", {}
)
Expand All @@ -207,7 +205,7 @@ def put(self, request, *args, **kwargs):
):
git_setup(
[
app_directory,
obj.name,
"--git_repo_url",
new_repo_url,
"--dev_branch",
Expand Down
36 changes: 20 additions & 16 deletions backend/src/zango/cli/git_setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import json
import os
import sys

Expand All @@ -22,19 +21,21 @@ def is_valid_app_directory(directory):


def update_settings_with_git_repo_url(
app_directory, git_repo_url, dev_branch, staging_branch, prod_branch
app_name, git_repo_url, dev_branch, staging_branch, prod_branch
):
"""
Update the 'git_repo_url' in the TenantMode.extra_config field.
Args:
- app_directory (str): Full path of the app directory.
- app_name (str): Full path of the app directory.
- git_repo_url (str): URL of the remote git repository.
- dev_branch (str): Name of the development branch.
- staging_branch (str): Name of the staging branch.
- prod_branch (str): Name of the production branch.
Returns:
- bool: True if successful, False otherwise.
"""
settings_file_path = os.path.join(app_directory, "settings.json")

try:
project_name = find_project_name()
Expand All @@ -45,12 +46,7 @@ def update_settings_with_git_repo_url(

from zango.apps.shared.tenancy.models import TenantModel

# Load current settings from settings.json
with open(settings_file_path, "r") as settings_file:
settings = json.load(settings_file)

# Update git_repo_url in settings
app_name = settings["app_name"]
tenant_obj = TenantModel.objects.get(name=app_name)
git_config = {}
if tenant_obj.extra_config:
Expand All @@ -69,18 +65,14 @@ def update_settings_with_git_repo_url(
tenant_obj.save()

return True
except FileNotFoundError:
click.echo(f"Error: settings.json not found in {app_directory}.")
except json.JSONDecodeError:
click.echo(f"Error: settings.json is not valid JSON in {app_directory}.")
except Exception as e:
click.echo(f"Error occurred while updating tenant extra config: {e}")

return False


@click.command("git-setup")
@click.argument("app_directory", type=click.Path(exists=True, resolve_path=True))
@click.argument("app_name", type=str)
@click.option("--git_repo_url", prompt=True, required=True, help="Repo URL")
@click.option(
"--dev_branch",
Expand All @@ -107,20 +99,32 @@ def update_settings_with_git_repo_url(
"--initialize", is_flag=True, default=False, help="Initialize the repository"
)
def git_setup(
app_directory,
git_repo_url,
dev_branch,
staging_branch,
prod_branch,
initialize,
app_name,
):
"""
Initialize a git repository in the specified app directory and add the given remote repository URL.
APP_DIRECTORY: The directory of the app.
GIT_REPO_URL: The URL of the remote git repository.
"""

try:
from zango.apps.shared.tenancy.models import TenantModel

TenantModel.objects.get(name=app_name)
except TenantModel.DoesNotExist:
click.echo(
f"The app name '{app_name}' provided as an argument is invalid. Please ensure that you have entered the correct app name and try again."
)
return

# Check if the app directory exists
app_directory = os.path.join("workspaces", app_name)
if not os.path.exists(app_directory):
click.echo(f"The directory {app_directory} does not exist.")
return
Expand Down Expand Up @@ -174,7 +178,7 @@ def git_setup(
)

update_settings_with_git_repo_url(
app_directory,
app_name,
git_repo_url,
dev_branch,
staging_branch,
Expand Down

0 comments on commit 5b31311

Please sign in to comment.