Skip to content
Open
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
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,25 @@ 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.

## Checking a review once

Use `get_review_outcome` when you manage polling yourself or need to check an existing
review ID. It fetches the review once and applies the same outcome and optional head
SHA checks as `wait_for_review`. With `AsyncProoflineClient`, await the call.

```python
outcome = client.get_review_outcome(
organization_id, review_id, head_commit_sha=expected_sha
)
if outcome is None:
print("Review is still pending")
else:
print(outcome.status, outcome.reason)
```

A pending or running review returns `None`. A review pinned to a different commit
returns `INCOMPLETE` with a `HEAD_COMMIT_MISMATCH` gap even while it is running.

## Review exports

`export_reviews` reads one CSV or NDJSON page over the bounded transport. Export tokens require `analytics:read`.
Expand Down
26 changes: 26 additions & 0 deletions proofline/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,19 @@ def iter_reviews(
params["cursor"] = cursor
raise _pagination_limit()

def get_review_outcome(
self,
organization_id: UUID,
review_id: UUID,
*,
head_commit_sha: str | None = None,
) -> ReviewOutcome | None:
"""Fetch and classify a review once, returning None if it is still pending."""
_head_commit(head_commit_sha)
url = _review_url(self._base_url, organization_id, review_id)
review = self.get_review(organization_id, review_id)
return outcome(review, url, review_id=review_id, head_commit_sha=head_commit_sha)

def wait_for_review(
self,
organization_id: UUID,
Expand Down Expand Up @@ -934,6 +947,19 @@ async def iter_reviews(
params["cursor"] = cursor
raise _pagination_limit()

async def get_review_outcome(
self,
organization_id: UUID,
review_id: UUID,
*,
head_commit_sha: str | None = None,
) -> ReviewOutcome | None:
"""Fetch and classify a review once, returning None if it is still pending."""
_head_commit(head_commit_sha)
url = _review_url(self._base_url, organization_id, review_id)
review = await self.get_review(organization_id, review_id)
return outcome(review, url, review_id=review_id, head_commit_sha=head_commit_sha)

async def wait_for_review(
self,
organization_id: UUID,
Expand Down
26 changes: 26 additions & 0 deletions tests/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -1256,6 +1256,32 @@ def gap_facts(result: Any) -> list[tuple[Any, str, tuple[str, ...]]]:
return [(gap.assessment_id, gap.status, gap.reason_codes) for gap in result.gaps]


@MODES
async def test_get_review_outcome_reads_once_and_checks_the_head(mode: str) -> None:
bodies = [review_at(HEAD, "PENDING"), review_at(HEAD), review_at(HEAD, "RUNNING")]
with Server(lambda request, index: Reply(body=bodies[index])) as server:
async with session(mode, server.url) as client:
with pytest.raises(ValueError, match="full 40 or 64 character"):
await call(client, "get_review_outcome", ORG, REVIEW, head_commit_sha="bad")
assert server.requests == []

result = await call(client, "get_review_outcome", ORG, REVIEW, head_commit_sha=HEAD)
assert result is None
assert len(server.requests) == 1

result = await call(client, "get_review_outcome", ORG, REVIEW, head_commit_sha=HEAD)
assert (result.status, result.gaps) == ("COMPLETED", ())
assert result.review_url == f"{server.url}/orgs/by-id/{ORG}/reviews/{REVIEW}"
assert len(server.requests) == 2

result = await call(
client, "get_review_outcome", ORG, REVIEW, head_commit_sha=OTHER_HEAD
)
assert result.status == "INCOMPLETE"
assert gap_facts(result)[-1] == PINNED_ELSEWHERE
assert len(server.requests) == 3


@MODES
async def test_wait_held_to_a_head_commit_never_completes_for_another(
mode: str, monkeypatch: pytest.MonkeyPatch
Expand Down