Skip to content
Closed
Show file tree
Hide file tree
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
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,19 @@ if outcome.status != "COMPLETED":

`head_commit_sha` is a full SHA of 40 or 64 hexadecimal characters; any other value raises `ValueError` before a request. A review pinned to another head ends the wait on the read that names it. Its outcome is `INCOMPLETE` whatever the review's own status, its last gap has the reason code `HEAD_COMMIT_MISMATCH`, and `reason` says that the review is pinned to another head commit. A settled review that names no head has `HEAD_COMMIT_UNAVAILABLE` instead and is not `COMPLETED` either. `outcome.review.head_commit_sha` is the commit the review is pinned to. A patch review's head is a derived revision ID, so no commit matches it. In a GitHub Actions `pull_request` job, `GITHUB_SHA` is the merge commit; pass the pull request's head.

## Listing reviews

`iter_reviews` follows page cursors and yields each review summary. `ReviewFilters` carries the same filters as `list_reviews`; a `limit` filter sets the page size exactly as `page_size` does, bounded from 1 to 100. Pass one of the two, or an agreeing pair; a conflicting pair raises `ValueError` before any request. A `cursor` filter resumes an iteration. Iteration stops only when the server omits the continuation cursor, and exhausting `max_pages` (1 to 1000) or `max_items` (1 to 100000) raises `urn:proofline:sdk:pagination-limit`, so a partial collection cannot silently appear complete.

```python
with ProoflineClient() as client:
for review in client.iter_reviews(
organization_id,
filters={"status": "COMPLETED", "limit": 50},
):
print(review.id, review.status)
```

## Review exports

`export_reviews` reads one CSV or NDJSON page over the bounded transport. Export tokens require `analytics:read`.
Expand Down
14 changes: 12 additions & 2 deletions proofline/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,11 +511,16 @@ def iter_reviews(
self,
organization_id: UUID,
*,
page_size: int = 100,
page_size: int | None = None,
max_pages: int = 100,
max_items: int = 10_000,
filters: ReviewFilters | None = None,
) -> Iterator[ReviewSummary]:
requested = filters.get("limit") if filters else None
if page_size is None:
page_size = requested if requested is not None else 100
elif requested is not None and requested != page_size:
raise ValueError("Pass page_size or a limit filter, not both.")
_page_limits(page_size, max_pages, max_items)
params: ReviewFilters = {}
if filters:
Expand Down Expand Up @@ -906,11 +911,16 @@ async def iter_reviews(
self,
organization_id: UUID,
*,
page_size: int = 100,
page_size: int | None = None,
max_pages: int = 100,
max_items: int = 10_000,
filters: ReviewFilters | None = None,
) -> AsyncIterator[ReviewSummary]:
requested = filters.get("limit") if filters else None
if page_size is None:
page_size = requested if requested is not None else 100
elif requested is not None and requested != page_size:
raise ValueError("Pass page_size or a limit filter, not both.")
_page_limits(page_size, max_pages, max_items)
params: ReviewFilters = {}
if filters:
Expand Down
46 changes: 46 additions & 0 deletions tests/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -1770,6 +1770,52 @@ def respond(request: Request, index: int) -> Reply:
assert raised.value.type == "urn:proofline:sdk:pagination-limit"


@MODES
async def test_reviews_iterator_honors_the_limit_filter(mode: str) -> None:
def respond(request: Request, index: int) -> Reply:
query = parse_qs(urlsplit(request.path).query)
assert query["limit"] == ["2"]
return Reply(body=page())

with Server(respond) as server:
async with session(mode, server.url) as client:
items = await collect(client, filters={"limit": 2})
assert [item.id for item in items] == [REVIEW]
assert len(server.requests) == 1


@MODES
async def test_reviews_iterator_accepts_agreeing_page_size_and_limit_filter(mode: str) -> None:
def respond(request: Request, index: int) -> Reply:
query = parse_qs(urlsplit(request.path).query)
assert query["limit"] == ["2"]
return Reply(body=page())

with Server(respond) as server:
async with session(mode, server.url) as client:
items = await collect(client, page_size=2, filters={"limit": 2})
assert [item.id for item in items] == [REVIEW]
assert len(server.requests) == 1


@MODES
async def test_reviews_iterator_refuses_conflicting_page_size_and_limit_filter(mode: str) -> None:
with Server(lambda request, index: Reply(body=page())) as server:
async with session(mode, server.url) as client:
with pytest.raises(ValueError, match="not both"):
await collect(client, page_size=3, filters={"limit": 2})
assert not server.requests


@MODES
async def test_reviews_iterator_bounds_the_honored_limit_filter(mode: str) -> None:
with Server(lambda request, index: Reply(body=page())) as server:
async with session(mode, server.url) as client:
with pytest.raises(ValueError, match="Pagination requires"):
await collect(client, filters={"limit": 101})
assert not server.requests


def test_token_environment_and_https_origin_rejection(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setenv("PROOFLINE_TOKEN", TOKEN)
with ProoflineClient() as client:
Expand Down