From 5802b36f467a89ad45762048037067ab4d0e7eb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=BB=BA=E5=B9=B3?= Date: Wed, 26 Feb 2025 17:28:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=88=97=E8=A1=A8=E5=88=86?= =?UTF-8?q?=E9=A1=B5=E5=92=8C=E5=88=86=E6=94=AF=E8=AE=B0=E5=BD=95=EF=BC=8C?= =?UTF-8?q?=E7=A1=AE=E4=BF=9D=E6=9B=B4=E5=A5=BD=E7=9A=84=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E3=80=82=E4=BC=98=E7=A7=80=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/pr/admin.py | 1 + apps/utils/git_config.py | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/apps/pr/admin.py b/apps/pr/admin.py index a68102d..b15569b 100644 --- a/apps/pr/admin.py +++ b/apps/pr/admin.py @@ -49,6 +49,7 @@ class ProjectHistoryAdmin(admin.ModelAdmin): list_display = ["project", "mr_url", "source_branch", "target_branch", "mr_title"] list_filter = ["project"] + list_per_page = 10 def save_model(self, request, obj, form, change): obj.create_by = request.user.username diff --git a/apps/utils/git_config.py b/apps/utils/git_config.py index fbf1774..72c4900 100644 --- a/apps/utils/git_config.py +++ b/apps/utils/git_config.py @@ -134,15 +134,16 @@ class GitLabProvider(GitProvider): :param project_id: :return: """ - models.ProjectHistory.objects.create( - project_id=project_id, - project_url=request_data.get("project", {}).get("web_url"), - mr_url=request_data.get('object_attributes', {}).get("url"), - source_branch=request_data.get('object_attributes', {}).get("source_branch"), - target_branch=request_data.get('object_attributes', {}).get("target_branch"), - mr_title=request_data.get('object_attributes', {}).get("title"), - source_data=request_data, - ) + if request_data.get('object_attributes', {}).get("source_branch") and request_data.get('object_attributes', {}).get("target_branch"): + models.ProjectHistory.objects.create( + project_id=project_id, + project_url=request_data.get("project", {}).get("web_url"), + mr_url=request_data.get('object_attributes', {}).get("url"), + source_branch=request_data.get('object_attributes', {}).get("source_branch"), + target_branch=request_data.get('object_attributes', {}).get("target_branch"), + mr_title=request_data.get('object_attributes', {}).get("title"), + source_data=request_data, + ) def run_command(self, mr_url, project_commands): """