From 473c32d3d4e3139e0216af14e29ffb46dfecf41b Mon Sep 17 00:00:00 2001 From: pablohashescobar <118773738+pablohashescobar@users.noreply.github.com> Date: Tue, 27 Jun 2023 22:56:06 +0530 Subject: [PATCH] fix: github importer issue (#1414) (#1415) --- apiserver/plane/api/views/importer.py | 24 +++++++++++++++++--- apiserver/plane/utils/integrations/github.py | 2 +- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/apiserver/plane/api/views/importer.py b/apiserver/plane/api/views/importer.py index 28d490740..63e2d38a1 100644 --- a/apiserver/plane/api/views/importer.py +++ b/apiserver/plane/api/views/importer.py @@ -42,16 +42,34 @@ from plane.utils.html_processor import strip_tags class ServiceIssueImportSummaryEndpoint(BaseAPIView): + def get(self, request, slug, service): try: if service == "github": + owner = request.GET.get("owner", False) + repo = request.GET.get("repo", False) + + if not owner or not repo: + return Response( + {"error": "Owner and repo are required"}, + status=status.HTTP_400_BAD_REQUEST, + ) + workspace_integration = WorkspaceIntegration.objects.get( integration__provider="github", workspace__slug=slug ) - access_tokens_url = workspace_integration.metadata["access_tokens_url"] - owner = request.GET.get("owner") - repo = request.GET.get("repo") + access_tokens_url = workspace_integration.metadata.get( + "access_tokens_url", False + ) + + if not access_tokens_url: + return Response( + { + "error": "There was an error during the installation of the GitHub app. To resolve this issue, we recommend reinstalling the GitHub app." + }, + status=status.HTTP_400_BAD_REQUEST, + ) issue_count, labels, collaborators = get_github_repo_details( access_tokens_url, owner, repo diff --git a/apiserver/plane/utils/integrations/github.py b/apiserver/plane/utils/integrations/github.py index d9aecece1..45cb5925a 100644 --- a/apiserver/plane/utils/integrations/github.py +++ b/apiserver/plane/utils/integrations/github.py @@ -113,7 +113,7 @@ def get_github_repo_details(access_tokens_url, owner, repo): last_url = labels_response.links.get("last").get("url") parsed_url = urlparse(last_url) last_page_value = parse_qs(parsed_url.query)["page"][0] - total_labels = total_labels + 100 * (last_page_value - 1) + total_labels = total_labels + 100 * (int(last_page_value) - 1) # Get labels in last page last_page_labels = requests.get(last_url, headers=headers).json()