diff --git a/README.md b/README.md index 250fb32e..a037e2d0 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/tests/test_http.py b/tests/test_http.py index 68c6228e..4df7aba5 100644 --- a/tests/test_http.py +++ b/tests/test_http.py @@ -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"),