Fix review issues in pagination implementation
- Move `import re` to top of file (was inline in function) - Add page parameter validation (page >= 1) - Fix parameter order bug in search_utils.py (was swapped) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import os
|
import os
|
||||||
|
import re
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
@@ -422,6 +423,8 @@ class BasecampClient:
|
|||||||
- total_count: total number of comments (from X-Total-Count header)
|
- total_count: total number of comments (from X-Total-Count header)
|
||||||
- next_page: next page number if available, None otherwise
|
- next_page: next page number if available, None otherwise
|
||||||
"""
|
"""
|
||||||
|
if page < 1:
|
||||||
|
raise ValueError("page must be >= 1")
|
||||||
endpoint = f"buckets/{project_id}/recordings/{recording_id}/comments.json"
|
endpoint = f"buckets/{project_id}/recordings/{recording_id}/comments.json"
|
||||||
response = self.get(endpoint, params={"page": page})
|
response = self.get(endpoint, params={"page": page})
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
@@ -435,7 +438,6 @@ class BasecampClient:
|
|||||||
if 'rel="next"' in link_header:
|
if 'rel="next"' in link_header:
|
||||||
# Extract page number from Link header
|
# Extract page number from Link header
|
||||||
# Format: <https://3.basecampapi.com/.../comments.json?page=2>; rel="next"
|
# Format: <https://3.basecampapi.com/.../comments.json?page=2>; rel="next"
|
||||||
import re
|
|
||||||
match = re.search(r'page=(\d+).*rel="next"', link_header)
|
match = re.search(r'page=(\d+).*rel="next"', link_header)
|
||||||
if match:
|
if match:
|
||||||
next_page = int(match.group(1))
|
next_page = int(match.group(1))
|
||||||
|
|||||||
@@ -467,7 +467,7 @@ class BasecampSearch:
|
|||||||
try:
|
try:
|
||||||
# If both recording_id and bucket_id are provided, get comments for that specific recording
|
# If both recording_id and bucket_id are provided, get comments for that specific recording
|
||||||
if recording_id and bucket_id:
|
if recording_id and bucket_id:
|
||||||
result = self.client.get_comments(recording_id, bucket_id)
|
result = self.client.get_comments(bucket_id, recording_id)
|
||||||
comments = result["comments"]
|
comments = result["comments"]
|
||||||
# Otherwise we can't search across all comments as there's no endpoint for that
|
# Otherwise we can't search across all comments as there's no endpoint for that
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user