Git配置更新,添加审阅者,支持多种git类型。
This commit is contained in:
parent
a2689bde56
commit
8ad4e4f188
@ -22,7 +22,7 @@ class AIConfigAdmin(AjaxAdmin):
|
||||
class GitConfigAdmin(AjaxAdmin):
|
||||
"""Admin配置"""
|
||||
|
||||
list_display = ["git_name", "git_type", "git_url", "access_token"]
|
||||
list_display = ["git_name", "git_type", "git_url", "access_token", "reviewer"]
|
||||
readonly_fields = ["create_by", "delete_at", "detail"]
|
||||
list_per_page = 10
|
||||
top_html = '<el-alert title="可配置多个Git服务上!" type="success"></el-alert>'
|
||||
|
||||
20
apps/pr/migrations/0004_gitconfig_reviewer.py
Normal file
20
apps/pr/migrations/0004_gitconfig_reviewer.py
Normal file
@ -0,0 +1,20 @@
|
||||
# Generated by Django 5.1.6 on 2025-03-03 15:00
|
||||
|
||||
import simplepro.components.fields
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("pr", "0003_projectconfig_project_url"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="gitconfig",
|
||||
name="reviewer",
|
||||
field=simplepro.components.fields.CharField(
|
||||
blank=True, max_length=16, null=True, verbose_name="项目管理员"
|
||||
),
|
||||
),
|
||||
]
|
||||
@ -52,13 +52,16 @@ class GitConfig(BaseModel):
|
||||
access_token = fields.CharField(
|
||||
null=True, blank=True, max_length=128, verbose_name="访问密钥"
|
||||
)
|
||||
reviewer = fields.CharField(
|
||||
null=True, blank=True, max_length=16, verbose_name="项目管理员"
|
||||
)
|
||||
|
||||
class Meta:
|
||||
verbose_name = "Git服务配置"
|
||||
verbose_name_plural = "Git服务配置"
|
||||
|
||||
def __str__(self):
|
||||
return self.git_name
|
||||
return f"{self.git_name}-{self.reviewer}"
|
||||
|
||||
|
||||
class ProjectConfig(BaseModel):
|
||||
|
||||
@ -1,12 +1,7 @@
|
||||
import json
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from pr import models
|
||||
from django.views import View
|
||||
from django.http import JsonResponse
|
||||
|
||||
from utils.pr_agent import cli
|
||||
from utils.pr_agent.config_loader import get_settings
|
||||
from utils.git_config import GitLabProvider
|
||||
from utils import constant
|
||||
|
||||
@ -68,16 +63,16 @@ class WebHookView(View):
|
||||
|
||||
# 获取对应处理类
|
||||
provider = self.select_git_provider(GIT_TYPE)
|
||||
project_id = provider.get_project_id(request_json=json_data)
|
||||
project_id = provider.get_project_id(request_json=json_data, git_type=GIT_TYPE)
|
||||
if not project_id:
|
||||
return JsonResponse(status=400, data={"error": "Missing project ID"})
|
||||
|
||||
# 获取项目配置
|
||||
project_config = provider.get_project_config(project_id=project_id)
|
||||
project_config = provider.get_project_config(project_id=project_id, git_type=GIT_TYPE)
|
||||
|
||||
# Token 校验
|
||||
provider.check_secret(
|
||||
request_headers=headers, project_secret=project_config.get("project_secret")
|
||||
request_headers=headers, project_secret=project_config.get("project_secret"), git_type=GIT_TYPE
|
||||
)
|
||||
|
||||
provider.get_merge_request(
|
||||
|
||||
@ -11,7 +11,7 @@ from utils import constant
|
||||
|
||||
class GitProvider(ABC):
|
||||
@abstractmethod
|
||||
def get_project_config(self, project_id):
|
||||
def get_project_config(self, project_id, git_type):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
@ -34,9 +34,10 @@ class GitProvider(ABC):
|
||||
|
||||
class GitLabProvider(GitProvider):
|
||||
@staticmethod
|
||||
def check_secret(request_headers, project_secret):
|
||||
def check_secret(request_headers, project_secret, git_type):
|
||||
"""
|
||||
检查密钥
|
||||
:param git_type:
|
||||
:param request_headers:
|
||||
:param project_secret:
|
||||
:return:
|
||||
@ -46,21 +47,23 @@ class GitLabProvider(GitProvider):
|
||||
return JsonResponse(status=403, data={"error": "Invalid token"})
|
||||
|
||||
@staticmethod
|
||||
def get_project_id(request_json):
|
||||
def get_project_id(request_json, git_type):
|
||||
"""
|
||||
获取项目ID
|
||||
:param git_type:
|
||||
:param request_json:
|
||||
:return:
|
||||
"""
|
||||
return request_json.get("project", {}).get("id")
|
||||
|
||||
def get_project_config(self, project_id):
|
||||
def get_project_config(self, project_id, git_type):
|
||||
"""
|
||||
实现GitLab项目配置获取逻辑
|
||||
:param git_type:
|
||||
:param project_id:
|
||||
:return:
|
||||
"""
|
||||
git_config = models.GitConfig.objects.filter(git_type=0).first()
|
||||
git_config = models.GitConfig.objects.filter(git_type=0).first() # Gitlab
|
||||
project_config = models.ProjectConfig.objects.filter(
|
||||
git_config=git_config, project_id=project_id
|
||||
).first()
|
||||
|
||||
@ -18,7 +18,7 @@ from pathlib import Path
|
||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
|
||||
CONFIG_NAME = BASE_DIR / "config.ini"
|
||||
CONFIG_NAME = BASE_DIR / "config.local.ini"
|
||||
|
||||
# 加载配置文件: 开发可加载config.local.ini
|
||||
_config = configparser.ConfigParser()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user