|
@@ -16,11 +16,13 @@ from models.gitModels import Repos
|
|
|
class RequestBody(BaseModel):
|
|
|
uuid: str
|
|
|
repo_url: str
|
|
|
+ repo_id: int
|
|
|
|
|
|
class CommitHash(BaseModel):
|
|
|
uuid: str
|
|
|
repo_url: str
|
|
|
commit_hash: str
|
|
|
+ repo_id: int
|
|
|
|
|
|
|
|
|
def generate_repo_path(uuid, repo_url):
|
|
@@ -51,17 +53,17 @@ def git_stats_to_json(text):
|
|
|
|
|
|
gitrouter = APIRouter()
|
|
|
|
|
|
-async def clone_task(repo_url, local_path,uuid,repo_name):
|
|
|
+async def clone_task(repo_url, local_path, uuid, repo_id):
|
|
|
current_time = int(time.time() * 1000)
|
|
|
print(f"开始克隆仓库: {repo_url}")
|
|
|
try:
|
|
|
loop = asyncio.get_event_loop()
|
|
|
await loop.run_in_executor(None, Repo.clone_from, repo_url, local_path)
|
|
|
- await Repos.filter(create_user=uuid,name=repo_name).update(path=local_path, state=1, update_time=current_time)
|
|
|
+ await Repos.filter(id = repo_id, create_user = uuid).update(path=local_path, state=1, update_time=current_time)
|
|
|
print(f"克隆仓库成功: {repo_url}")
|
|
|
except:
|
|
|
print(f"克隆仓库失败: {repo_url}")
|
|
|
- await Repos.filter(create_user=uuid,name=repo_name).update(path=local_path, state=0, update_time=current_time)
|
|
|
+ await Repos.filter(id = repo_id, create_user = uuid).update(path=local_path, state=2, update_time=current_time)
|
|
|
shutil.rmtree(local_path)
|
|
|
|
|
|
@gitrouter.post("/clone")
|
|
@@ -71,7 +73,7 @@ async def clone(request: RequestBody, background_tasks: BackgroundTasks):
|
|
|
return {"status": "400", "msg": "仓库已存在", "uuid": request.uuid, "repo_url": request.repo_url,
|
|
|
"path": local_path}
|
|
|
else:
|
|
|
- background_tasks.add_task(clone_task, request.repo_url, local_path, request.uuid, repo_name)
|
|
|
+ background_tasks.add_task(clone_task, request.repo_url, local_path, request.uuid, request.repo_id)
|
|
|
response = {"status": "200", "msg": "成功创建克隆任务", "uuid": request.uuid, "repo_name": repo_name,
|
|
|
"local_path": local_path}
|
|
|
return response
|