fix: add pagination for github repositories endpoint (#345)

This commit is contained in:
pablohashescobar 2023-02-28 02:08:17 +05:30 committed by GitHub
parent 07295ac314
commit 90b8d66946
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -25,11 +25,15 @@ from plane.utils.integrations.github import get_github_repos
class GithubRepositoriesEndpoint(BaseAPIView): class GithubRepositoriesEndpoint(BaseAPIView):
def get(self, request, slug, workspace_integration_id): def get(self, request, slug, workspace_integration_id):
try: try:
page = request.GET.get("page", 1)
workspace_integration = WorkspaceIntegration.objects.get( workspace_integration = WorkspaceIntegration.objects.get(
workspace__slug=slug, pk=workspace_integration_id workspace__slug=slug, pk=workspace_integration_id
) )
access_tokens_url = workspace_integration.metadata["access_tokens_url"] access_tokens_url = workspace_integration.metadata["access_tokens_url"]
repositories_url = workspace_integration.metadata["repositories_url"] repositories_url = (
workspace_integration.metadata["repositories_url"]
+ f"?per_page=100&page={page}"
)
repositories = get_github_repos(access_tokens_url, repositories_url) repositories = get_github_repos(access_tokens_url, repositories_url)
return Response(repositories, status=status.HTTP_200_OK) return Response(repositories, status=status.HTTP_200_OK)
except WorkspaceIntegration.DoesNotExist: except WorkspaceIntegration.DoesNotExist: