Skip to content

Commit

Permalink
initialie repo with url
Browse files Browse the repository at this point in the history
  • Loading branch information
DevilsAutumn committed Sep 27, 2024
1 parent 2ea9344 commit d0e1aa3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
1 change: 0 additions & 1 deletion backend/src/zango/api/platform/tenancy/v1/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 12 additions & 4 deletions backend/src/zango/api/platform/tenancy/v1/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 = {
Expand Down
1 change: 1 addition & 0 deletions backend/src/zango/cli/git_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit d0e1aa3

Please sign in to comment.