From 8d3e274bc4f56d88296b059f42725a56569d6eef Mon Sep 17 00:00:00 2001 From: vapao Date: Sun, 8 Mar 2020 13:11:42 +0800 Subject: [PATCH] =?UTF-8?q?F=20=E4=BF=AE=E5=A4=8D=E5=B8=B8=E8=A7=84?= =?UTF-8?q?=E5=8F=91=E5=B8=83=E6=9B=B4=E6=94=B9Git=E4=BB=93=E5=BA=93?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E4=B8=8D=E7=94=9F=E6=95=88=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spug_api/apps/app/utils.py | 5 +++++ spug_api/apps/app/views.py | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/spug_api/apps/app/utils.py b/spug_api/apps/app/utils.py index 0a51f63..30150cc 100644 --- a/spug_api/apps/app/utils.py +++ b/spug_api/apps/app/utils.py @@ -4,6 +4,7 @@ from django.conf import settings from apps.app.models import Deploy from libs.gitlib import Git +import shutil import os @@ -22,3 +23,7 @@ def fetch_versions(deploy: Deploy): git_repo = deploy.extend_obj.git_repo repo_dir = os.path.join(settings.REPOS_DIR, str(deploy.id)) return Git(git_repo, repo_dir).fetch_branches_tags() + + +def remove_repo(deploy_id): + shutil.rmtree(os.path.join(settings.REPOS_DIR, str(deploy_id)), True) diff --git a/spug_api/apps/app/views.py b/spug_api/apps/app/views.py index 4807f5e..79bdd32 100644 --- a/spug_api/apps/app/views.py +++ b/spug_api/apps/app/views.py @@ -6,7 +6,7 @@ from django.db.models import F from libs import JsonParser, Argument, json_response from apps.app.models import App, Deploy, DeployExtend1, DeployExtend2 from apps.config.models import Config -from apps.app.utils import parse_envs, fetch_versions +from apps.app.utils import parse_envs, fetch_versions, remove_repo import json @@ -109,6 +109,9 @@ class DeployView(View): extend_form.filter_rule = json.dumps(extend_form.filter_rule) extend_form.custom_envs = json.dumps(parse_envs(extend_form.custom_envs)) if form.id: + extend = DeployExtend1.objects.filter(deploy_id=form.id).first() + if extend.git_repo != extend_form.git_repo: + remove_repo(form.id) Deploy.objects.filter(pk=form.id).update(**form) DeployExtend1.objects.filter(deploy_id=form.id).update(**extend_form) else: