✏️ Fix: [#95] 커밋 파일 목록 페이지네이션, 커밋 파일 확장자와 코드 언어 매핑
This commit is contained in:
@@ -26,6 +26,7 @@ from .services import *
|
||||
from .permissions import *
|
||||
|
||||
from common.utils.fileManager import file_delete
|
||||
from common.utils.mapManager import guess_language_from_path
|
||||
|
||||
from projects.serializers import *
|
||||
from portfolios.serializers import *
|
||||
@@ -212,9 +213,51 @@ class GithubAPIViewSet(viewsets.ViewSet):
|
||||
|
||||
if not (repo_full and sha):
|
||||
return Response({"is_query_param": False}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
try:
|
||||
page = int(request.query_params.get("page", 1))
|
||||
except ValueError:
|
||||
return Response({"is_page_int": False,"detail": "page and page_size must be integers"}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
commit = self.github.get_repo(repo_full).get_commit(sha)
|
||||
return Response([{"filename": f.filename, "status": f.status} for f in commit.files])
|
||||
if page < 1:
|
||||
return Response({"is_page_gte_1": False, "detail": "page and page_size must be >= 1"}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
try:
|
||||
repo = self.github.get_repo(repo_full)
|
||||
commit = repo.get_commit(sha)
|
||||
files = list(commit.files)
|
||||
total_count = len(files)
|
||||
|
||||
total_page = GithubTokenService.cal_github_total_page(total_count, PAGE_SIZE)
|
||||
|
||||
if total_page != 0 and page > total_page:
|
||||
return Response(
|
||||
{
|
||||
"is_page_le_total_page": False,
|
||||
"detail": "page is out of range",
|
||||
"page": page,
|
||||
"total_page": total_page,
|
||||
},
|
||||
status=status.HTTP_400_BAD_REQUEST,
|
||||
)
|
||||
|
||||
start = (page - 1) * PAGE_SIZE
|
||||
end = start + PAGE_SIZE
|
||||
paged_files = files[start:end]
|
||||
|
||||
except Exception as e:
|
||||
return Response({"error": str(e)}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
results = [{"filename": f.filename, "status": f.status} for f in paged_files]
|
||||
|
||||
return Response(
|
||||
{
|
||||
"page": page,
|
||||
"page_size": PAGE_SIZE,
|
||||
"total_page": total_page,
|
||||
"results": results
|
||||
}, status=status.HTTP_200_OK
|
||||
)
|
||||
|
||||
@action(detail=False, methods=["get"], url_path="file-content")
|
||||
def file_content(self, request):
|
||||
@@ -229,7 +272,15 @@ class GithubAPIViewSet(viewsets.ViewSet):
|
||||
content = file.decoded_content.decode("utf-8", errors="replace")
|
||||
else:
|
||||
content = file.content
|
||||
return Response({"path": file.path, "ref": sha, "content": content})
|
||||
|
||||
language = guess_language_from_path(file.path)
|
||||
|
||||
return Response({
|
||||
"path": file.path,
|
||||
"ref": sha,
|
||||
"language": language,
|
||||
"content": content,
|
||||
})
|
||||
except GithubException as e:
|
||||
return Response({"detail": str(e)}, status=e.status)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user