|
@@ -12,7 +12,8 @@ from models.aiModels import Scan_Tasks, Commit_Summary_Tasks, File_Summary_Tasks
|
|
|
from models.gitModels import Repos
|
|
|
|
|
|
airouter = APIRouter()
|
|
|
-class RequestBody(BaseModel):
|
|
|
+class RequestCommit(BaseModel):
|
|
|
+ task_id: str
|
|
|
uuid: str
|
|
|
repo_url: str
|
|
|
|
|
@@ -22,6 +23,7 @@ class RequestScan(BaseModel):
|
|
|
repo_url: str
|
|
|
|
|
|
class RequestFile(BaseModel):
|
|
|
+ task_id: str
|
|
|
uuid: str
|
|
|
repo_url: str
|
|
|
file_path: str
|
|
@@ -167,7 +169,7 @@ async def process_batch2(local_path,path):
|
|
|
return {"summary":None}
|
|
|
|
|
|
|
|
|
-async def analysis(local_path, repo_id, task_id):
|
|
|
+async def analysis(local_path, task_id):
|
|
|
file_list = await get_code_files(local_path)
|
|
|
print(file_list)
|
|
|
results = []
|
|
@@ -177,23 +179,23 @@ async def analysis(local_path, repo_id, task_id):
|
|
|
for result in batch_results:
|
|
|
if isinstance(result, Exception):
|
|
|
print(f"处理出错: {result}")
|
|
|
- await Scan_Tasks.filter(id=task_id).update(state=2, repo_id=repo_id, result={"results": results},
|
|
|
+ await Scan_Tasks.filter(id=task_id).update(state=3, result={"results": results},
|
|
|
scan_end_time=int(time.time()))
|
|
|
else:
|
|
|
results.append(result)
|
|
|
- await Scan_Tasks.filter(id=task_id).update(state=2, repo_id=repo_id, result={"results": results},
|
|
|
+ await Scan_Tasks.filter(id=task_id).update(state=2, result={"results": results},
|
|
|
scan_end_time=int(time.time()))
|
|
|
print("扫描完成")
|
|
|
|
|
|
-async def commit_task(content,repo_id):
|
|
|
+async def commit_task(content,task_id):
|
|
|
commit_result=await asyncio.gather(commit_summary(content), return_exceptions=True)
|
|
|
if isinstance(commit_result, Exception):
|
|
|
print(f"提交出错: {commit_result}")
|
|
|
else:
|
|
|
print("提交成功")
|
|
|
- await Commit_Summary_Tasks.filter(repo_id=repo_id).update(result=commit_result[0],end_time=int(time.time()))
|
|
|
+ await Commit_Summary_Tasks.filter(id=task_id).update(result=commit_result[0],end_time=int(time.time()))
|
|
|
|
|
|
-async def file_task(file_path,repo_id):
|
|
|
+async def file_task(file_path,task_id):
|
|
|
with open(file_path, 'r', encoding="utf8") as f:
|
|
|
content = f.read()
|
|
|
file_result = await asyncio.gather(file_summary(content), return_exceptions=True)
|
|
@@ -201,7 +203,7 @@ async def file_task(file_path,repo_id):
|
|
|
print(f"提交出错: {file_result}")
|
|
|
else:
|
|
|
print("提交成功")
|
|
|
- await File_Summary_Tasks.filter(repo_id=repo_id).update(result=file_result[0], end_time=int(time.time()))
|
|
|
+ await File_Summary_Tasks.filter(id=task_id).update(result=file_result[0], end_time=int(time.time()))
|
|
|
|
|
|
|
|
|
|
|
@@ -212,22 +214,22 @@ async def scan(request: RequestScan, background_tasks: BackgroundTasks):
|
|
|
repo = await Repos.get(name=repo_name)
|
|
|
repo_id = repo.id
|
|
|
print(f"开始扫描仓库: {repo_name}")
|
|
|
- await Scan_Tasks.filter(repo_id=repo_id).update(state=1, scan_start_time=int(time.time()))
|
|
|
- background_tasks.add_task(analysis, local_path, repo_id, request.task_id)
|
|
|
+ await Scan_Tasks.filter(id=request.task_id).update(state=1, scan_start_time=int(time.time()))
|
|
|
+ background_tasks.add_task(analysis, local_path, request.task_id)
|
|
|
return {"code": 200, "msg": "添加扫描任务成功"}
|
|
|
|
|
|
@airouter.post("/summaryCommit")
|
|
|
-async def summaryCommit(request: RequestBody, background_tasks: BackgroundTasks):
|
|
|
+async def summaryCommit(request: RequestCommit, background_tasks: BackgroundTasks):
|
|
|
local_path, repo_name = generate_repo_path(request.uuid, request.repo_url)
|
|
|
repo=await Repos.get(name=repo_name)
|
|
|
repo_id=repo.id
|
|
|
- repo_commit=await Commit_Summary_Tasks.get(repo_id=repo_id)
|
|
|
+ repo_commit=await Commit_Summary_Tasks.get(id=request.task_id)
|
|
|
repo_commit_hash=repo_commit.repo_hash
|
|
|
print(f"开始提交仓库: {repo_name}")
|
|
|
- await Commit_Summary_Tasks.filter(repo_id=repo_id).update(start_time=int(time.time()))
|
|
|
+ await Commit_Summary_Tasks.filter(id=request.task_id).update(start_time=int(time.time()))
|
|
|
# commit_content = Repo(local_path).git.log('-1', '-p', '--pretty=format:%h %s')
|
|
|
commit_content = Repo(local_path).git.diff(f"{repo_commit_hash}^", repo_commit_hash)
|
|
|
- background_tasks.add_task(commit_task,commit_content,repo_id)
|
|
|
+ background_tasks.add_task(commit_task,commit_content, request.task_id)
|
|
|
return {"code": 200, "msg": "添加提交任务成功"}
|
|
|
|
|
|
@airouter.post("/summaryFile")
|
|
@@ -235,8 +237,8 @@ async def summaryFile(request: RequestFile,background_tasks: BackgroundTasks):
|
|
|
local_path, repo_name = generate_repo_path(request.uuid, request.repo_url)
|
|
|
repo=await Repos.get(name=repo_name)
|
|
|
repo_id = repo.id
|
|
|
- await File_Summary_Tasks.filter(repo_id=repo_id).update(start_time=int(time.time()))
|
|
|
- background_tasks.add_task(file_task, request.file_path, repo_id)
|
|
|
+ await File_Summary_Tasks.filter(id=request.task_id).update(start_time=int(time.time()))
|
|
|
+ background_tasks.add_task(file_task, request.file_path, request.task_id)
|
|
|
return {"code": 200, "msg": "添加提交任务成功"}
|
|
|
|
|
|
|