Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import time
from datetime import datetime, timezone
from typing import Iterator, Optional
from urllib.parse import parse_qs, urlparse
from google.cloud import bigquery
from google.api_core.client_options import ClientOptions
from google.auth.credentials import AnonymousCredentials
Expand Down Expand Up @@ -105,8 +106,25 @@ def extract_pull_requests(
next_url = resp.links.get("next", {}).get("url")
if not next_url or len(batch) == 0:
break
# After first request, subsequent 'next' URLs already contain params
base_url, params = next_url, None
# Parse the next URL and extract the page parameter
parsed_url = urlparse(next_url)
query_params = parse_qs(parsed_url.query)
# Update only the page parameter, preserving other params
if "page" in query_params and query_params["page"]:
try:
page_num = int(query_params["page"][0])
if page_num > 0:
params["page"] = page_num
else:
logger.warning(f"Invalid page number {page_num} in next URL, stopping pagination")
break
except (ValueError, IndexError) as e:
logger.warning(f"Invalid page parameter in next URL: {e}, stopping pagination")
break
else:
# If no page parameter, this is unexpected - log and stop pagination
logger.warning("No page parameter in next URL, stopping pagination")
break

logger.info(f"Data extraction completed. Total PRs: {total}, Pages: {pages}")

Expand Down