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
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,26 @@ with ProoflineClient() as client:

A provider object ID can replace `full_name` on the same host. For later requests, use the returned Proofline `repository_id`, which also resolves on its own within the organization.

## Look up a pull request's reviews

`list_pull_request_reviews` and `get_pull_request_review` take the repository name without its owner: for a GitHub repository, the part after `owner/`. `client.fixes.list_open_findings` takes the full `owner/name`. The server refuses an `owner/name` value in the two pull request lookups with a 400 `ProoflineError`, whose `detail` carries the server's reason.

In GitHub Actions, `GITHUB_REPOSITORY` holds `owner/name`, so split it to get both forms:

```python
import os
from uuid import UUID

from proofline import ProoflineClient

owner, name = os.environ["GITHUB_REPOSITORY"].split("/", 1)
organization_id = UUID(os.environ["PROOFLINE_ORGANIZATION_ID"])

with ProoflineClient() as client:
page = client.list_pull_request_reviews(organization_id, name, 12)
findings = client.fixes.list_open_findings(f"{owner}/{name}", 12)
```

## Errors and refusals

A refused request raises `ProoflineError` with the server problem's `status`, `type`, `title` and `detail`. When a review request creates nothing, the error also carries `refusal`, whose `reason` names the setting to change, such as `NO_LINKED_ENVIRONMENT` or `ENVIRONMENT_NOT_READY`, and `repository_name`. `RunNowRefusal` names the type of `refusal`. A refusal that does not match the public contract keeps its status, `title` and `detail` with the type `urn:proofline:sdk:invalid-response` and no `refusal`. Any other status, such as the 402 a review request answers when credits cannot pay, is a plain problem with no `refusal`. The token is redacted from every text field, and `repr` and `str` show only the status.
Expand Down
19 changes: 19 additions & 0 deletions tests/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,25 @@ def respond_run_now(request: Request, index: int) -> Reply:
assert len({request.peer_port for request in server.requests}) == 1


@MODES
async def test_pull_request_lookups_send_the_repository_name_unencoded(mode: str) -> None:
name = "web"
prefix = f"/api/v1/organizations/{ORG}/reviews/pr/{name}/42"
paths = [(prefix, page()), (f"{prefix}/runs/3", review())]

def respond(request: Request, index: int) -> Reply:
assert request.method == "GET"
return Reply(body=paths[index][1])

with Server(respond) as server:
async with session(mode, server.url) as client:
reviews = await call(client, "list_pull_request_reviews", ORG, name, 42)
run = await call(client, "get_pull_request_review", ORG, name, 42, 3)
assert isinstance(reviews, ReviewPage)
assert isinstance(run, CustomerReviewDetail)
assert [request.path for request in server.requests] == [path for path, _ in paths]


@MODES
@pytest.mark.parametrize(
("operation", "route", "sent", "request_model", "response_model", "extra"),
Expand Down