✏️ Fix: [#72] commits 페이지네이션 수정
This commit is contained in:
@@ -129,7 +129,7 @@ class GithubAPIViewSet(viewsets.ViewSet):
|
|||||||
token = self.request.user.github_token.access_token
|
token = self.request.user.github_token.access_token
|
||||||
cache.set(cache_key, token, timeout=CACHE_TIMEOUT)
|
cache.set(cache_key, token, timeout=CACHE_TIMEOUT)
|
||||||
|
|
||||||
return Github(token)
|
return Github(token, per_page=COMMIT_PAGE_SIZE)
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def github(self):
|
def github(self):
|
||||||
@@ -149,10 +149,18 @@ class GithubAPIViewSet(viewsets.ViewSet):
|
|||||||
|
|
||||||
@action(detail=False, methods=["get"], url_path="personal-repos")
|
@action(detail=False, methods=["get"], url_path="personal-repos")
|
||||||
def personal_repos(self, request):
|
def personal_repos(self, 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)
|
||||||
|
|
||||||
|
if page < 1:
|
||||||
|
return Response({"is_page_gte_1": False, "detail": "page and page_size must be >= 1"}, status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
user = self.github.get_user()
|
user = self.github.get_user()
|
||||||
data = [
|
data = [
|
||||||
{'full_name': r.full_name}
|
{'full_name': r.full_name}
|
||||||
for r in user.get_repos()
|
for r in user.get_repos().get_page(page-1)
|
||||||
]
|
]
|
||||||
return Response(data, status=status.HTTP_200_OK)
|
return Response(data, status=status.HTTP_200_OK)
|
||||||
|
|
||||||
@@ -172,13 +180,13 @@ class GithubAPIViewSet(viewsets.ViewSet):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
repo = self.github.get_repo(repo_full_name)
|
repo = self.github.get_repo(repo_full_name)
|
||||||
commits = repo.get_commits(per_page=COMMIT_PAGE_SIZE).get_page(page - 1)
|
commits = repo.get_commits().get_page(page-1)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return Response({"error": str(e)}, status=status.HTTP_400_BAD_REQUEST)
|
return Response({"error": str(e)}, status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
data = [
|
data = [
|
||||||
{"sha": c.sha, "commit_message": c.commit.message}
|
{"sha": c.sha, "commit_message": c.commit.message}
|
||||||
for c in commits[:COMMIT_PAGE_SIZE]
|
for c in commits
|
||||||
]
|
]
|
||||||
|
|
||||||
return Response({
|
return Response({
|
||||||
@@ -190,6 +198,7 @@ class GithubAPIViewSet(viewsets.ViewSet):
|
|||||||
@action(detail=False, methods=["get"], url_path="commit-files")
|
@action(detail=False, methods=["get"], url_path="commit-files")
|
||||||
def commit_files(self, request):
|
def commit_files(self, request):
|
||||||
repo_full, sha = request.query_params.get("repo"), request.query_params.get("sha")
|
repo_full, sha = request.query_params.get("repo"), request.query_params.get("sha")
|
||||||
|
|
||||||
if not (repo_full and sha):
|
if not (repo_full and sha):
|
||||||
return Response({"is_query_param": False}, status=status.HTTP_400_BAD_REQUEST)
|
return Response({"is_query_param": False}, status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
@@ -215,15 +224,31 @@ class GithubAPIViewSet(viewsets.ViewSet):
|
|||||||
|
|
||||||
@action(detail=False, methods=["get"], url_path="organizations")
|
@action(detail=False, methods=["get"], url_path="organizations")
|
||||||
def organizations(self, request):
|
def organizations(self, 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)
|
||||||
|
|
||||||
|
if page < 1:
|
||||||
|
return Response({"is_page_gte_1": False, "detail": "page and page_size must be >= 1"}, status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
user = self.github.get_user()
|
user = self.github.get_user()
|
||||||
orgs = user.get_orgs()
|
orgs = user.get_orgs().get_page(page-1)
|
||||||
data = {"org_name": [org.name for org in orgs]}
|
data = {"org_name": [org.name for org in orgs]}
|
||||||
return Response(data, status=status.HTTP_200_OK)
|
return Response(data, status=status.HTTP_200_OK)
|
||||||
|
|
||||||
@action(detail=False, methods=["get"], url_path="organization-repos")
|
@action(detail=False, methods=["get"], url_path="organization-repos")
|
||||||
def organization_repos(self, request):
|
def organization_repos(self, 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)
|
||||||
|
|
||||||
|
if page < 1:
|
||||||
|
return Response({"is_page_gte_1": False, "detail": "page and page_size must be >= 1"}, status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
org_name = request.query_params.get("org")
|
org_name = request.query_params.get("org")
|
||||||
repos = self.github.get_organization(org_name).get_repos()
|
repos = self.github.get_organization(org_name).get_repos().get_page(page-1)
|
||||||
|
|
||||||
data = [
|
data = [
|
||||||
{'full_name': r.full_name}
|
{'full_name': r.full_name}
|
||||||
|
|||||||
Reference in New Issue
Block a user