forked from Dongjiaqi/reposync
解绑后数据清理 & 组织仓库同步
This commit is contained in:
parent
1fa2f45d7f
commit
2976a1acf7
|
@ -16,7 +16,7 @@ from src.router import SYNC_CONFIG as router
|
|||
from src.do.sync_config import SyncDirect
|
||||
from src.dto.sync_config import SyncRepoDTO, SyncBranchDTO, LogDTO, ModifyRepoDTO
|
||||
from src.service.sync_config import SyncService, LogService
|
||||
from src.service.cronjob import sync_repo_task, sync_branch_task, modify_repos
|
||||
from src.service.cronjob import sync_repo_task, sync_branch_task, modify_repos, delete_repo_dir
|
||||
from src.base.status_code import Status, SYNCResponse, SYNCException
|
||||
from src.service.cronjob import GITMSGException
|
||||
|
||||
|
@ -197,6 +197,15 @@ class SyncDirection(Controller):
|
|||
):
|
||||
api_log(LogType.INFO, f"用户 {user} 使用 DELETE 方法访问接口 {request.url.path} ", user)
|
||||
data = await self.service.delete_repo(repo_name=repo_name)
|
||||
try:
|
||||
if data.code_status == 0:
|
||||
delete_repo_dir(repo_name, user)
|
||||
await self.log_service.delete_logs(repo_name=repo_name)
|
||||
except GITMSGException as GITError:
|
||||
return SYNCResponse(
|
||||
code_status=GITError.status,
|
||||
msg=GITError.msg
|
||||
)
|
||||
return SYNCResponse(
|
||||
code_status=data.code_status,
|
||||
msg=data.status_msg
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import os
|
||||
import shutil
|
||||
import re
|
||||
import shlex
|
||||
import subprocess
|
||||
|
@ -34,14 +35,19 @@ def get_repo_address_with_token(address: str, token: str) -> str:
|
|||
|
||||
if address.startswith('https'):
|
||||
owner_name = address[8:].split("/")[1]
|
||||
return address[:8] + owner_name + ":" + token + '@' + address[8:]
|
||||
return address[:8] + "oauth2:" + token + '@' + address[8:]
|
||||
elif address.startswith('http'):
|
||||
owner_name = address[7:].split("/")[1]
|
||||
return address[:7] + owner_name + ":" + token + '@' + address[7:]
|
||||
return address[:7] + "oauth2:" + token + '@' + address[7:]
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
|
||||
def delete_repo_dir(repo_name, user: str):
|
||||
repo_dir = os.path.join(SYNC_DIR, repo_name)
|
||||
os.path.exists(repo_dir) and shutil.rmtree(repo_dir)
|
||||
|
||||
|
||||
def shell(cmd, dire: str, log_name: str, user: str):
|
||||
log = f'Execute cmd: ' + cmd
|
||||
if 'git clone' in log:
|
||||
|
|
|
@ -215,3 +215,11 @@ class LogService(Service):
|
|||
logs = await self.sync_log_dao.get_log(repo_name_list=repo_name_list, branch_id_list=branch_id_list,
|
||||
page_number=page_num, page_size=page_size, create_sort=create_sort)
|
||||
return logs
|
||||
|
||||
async def delete_logs(self, repo_name: str) -> SYNCException:
|
||||
logs = await self.sync_log_dao.filter(repo_name=repo_name)
|
||||
if logs:
|
||||
for log in logs:
|
||||
await self.sync_log_dao.delete(log)
|
||||
|
||||
return SYNCException(Status.SUCCESS)
|
||||
|
|
Loading…
Reference in New Issue