fix: github importer issue (#1414) (#1415)

This commit is contained in:
pablohashescobar 2023-06-27 22:56:06 +05:30 committed by GitHub
parent 124d1c30aa
commit 473c32d3d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 4 deletions

View File

@ -42,16 +42,34 @@ from plane.utils.html_processor import strip_tags
class ServiceIssueImportSummaryEndpoint(BaseAPIView): class ServiceIssueImportSummaryEndpoint(BaseAPIView):
def get(self, request, slug, service): def get(self, request, slug, service):
try: try:
if service == "github": 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( workspace_integration = WorkspaceIntegration.objects.get(
integration__provider="github", workspace__slug=slug integration__provider="github", workspace__slug=slug
) )
access_tokens_url = workspace_integration.metadata["access_tokens_url"] access_tokens_url = workspace_integration.metadata.get(
owner = request.GET.get("owner") "access_tokens_url", False
repo = request.GET.get("repo") )
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( issue_count, labels, collaborators = get_github_repo_details(
access_tokens_url, owner, repo access_tokens_url, owner, repo

View File

@ -113,7 +113,7 @@ def get_github_repo_details(access_tokens_url, owner, repo):
last_url = labels_response.links.get("last").get("url") last_url = labels_response.links.get("last").get("url")
parsed_url = urlparse(last_url) parsed_url = urlparse(last_url)
last_page_value = parse_qs(parsed_url.query)["page"][0] 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 # Get labels in last page
last_page_labels = requests.get(last_url, headers=headers).json() last_page_labels = requests.get(last_url, headers=headers).json()