From e57df2faa2f652c29bda8b6edd8acf0b43b82fa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20Sodr=C3=A9?= Date: Wed, 4 Nov 2026 13:58:06 +0100 Subject: [PATCH] Name pull-request runs by repository name, not owner/name `history` and `run` sent `--repo owner/name` as one encoded path segment (`owner%2Fname`). The server addresses pull-request runs by the repository's own name, so `history` reported no runs for a pull request that had them and `run` returned 404. This affected the documented form and the default taken from the git remote. The owner/name is now checked against the repositories with reviews, and only the name is sent. Another owner's repository of the same name is refused. A bare name is still sent as given. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01XSEfqvPGJbbk5j8rGSup7H --- src/lib.rs | 21 +++++++++++++-- tests/http.rs | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 6096711..5121301 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -431,7 +431,7 @@ pub async fn run(cli: Cli, token: Option) -> anyhow::Result { let api = connect(Http::new(origin)?, token, cli.org).await?; - let name = repository_name(&args.repository).await?; + let name = pull_request_repository(&api, &args.repository).await?; tools::json( &api.tool_get(&[ "reviews", @@ -482,7 +482,7 @@ pub async fn run(cli: Cli, token: Option) -> anyhow::Result { let api = connect(Http::new(origin)?, token, cli.org).await?; - let name = repository_name(&args.repository).await?; + let name = pull_request_repository(&api, &args.repository).await?; tools::json(&api.history(&name, args.pr).await?) } Command::Guidance(args) => { @@ -727,6 +727,23 @@ async fn reviewed_repository(api: &Api, args: &RepositoryArgs) -> anyhow::Result Ok((name, id)) } +/// The repository segment of a pull-request review address. The server names +/// the repository without its owner, so `owner/name` is first checked against +/// the repositories with reviews, and only `name` is sent. A bare name is sent +/// as given. +async fn pull_request_repository(api: &Api, args: &RepositoryArgs) -> anyhow::Result { + if let Some(name) = &args.repo + && !name.contains('/') + { + return Ok(name.clone()); + } + let (name, _) = reviewed_repository(api, args).await?; + Ok(name + .rsplit_once('/') + .map_or(name.as_str(), |(_, repository)| repository) + .to_owned()) +} + /// The newest review in `repository` that `matches`, searching with `search`. async fn latest( api: &Api, diff --git a/tests/http.rs b/tests/http.rs index b65ed37..1210fd1 100644 --- a/tests/http.rs +++ b/tests/http.rs @@ -1915,6 +1915,15 @@ async fn native_tools_keep_tenant_paths_and_reruns_make_one_attempt() { ) .into_response(); } + if path.ends_with("/reviews") { + return Json(json!({ + "items": [], + "truncated": false, + "next_cursor": null, + "filters": {"repositories": [{"id": REPOSITORY, "name": "owner/repo"}]} + })) + .into_response(); + } if path.ends_with("repository-names") { return Json( json!({"repositories": [{"id": REPOSITORY, "full_name":"owner/repo"}]}), @@ -1976,6 +1985,72 @@ async fn native_tools_keep_tenant_paths_and_reruns_make_one_attempt() { server.abort(); } +#[tokio::test] +async fn pull_request_runs_name_the_repository_without_its_owner() { + let requests = Arc::new(Mutex::new(Vec::new())); + let seen = Arc::clone(&requests); + let app = Router::new().fallback(move |request: axum::extract::Request| { + let seen = Arc::clone(&seen); + async move { + let path = request.uri().path().to_owned(); + seen.lock().unwrap().push(path.clone()); + if path.ends_with("/reviews") { + return Json(json!({ + "items": [], + "truncated": false, + "next_cursor": null, + "filters": {"repositories": [{"id": REPOSITORY, "name": "Acme/Web"}]} + })) + .into_response(); + } + Json(json!({"items": []})).into_response() + } + }); + let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap(); + let origin = format!("http://{}", listener.local_addr().unwrap()); + let server = tokio::spawn(async move { + axum::serve(listener, app).await.unwrap(); + }); + let prefix = format!("/api/v1/organizations/{ORG}/reviews/pr"); + for (args, expected) in [ + ( + vec!["history", "--repo", "acme/web", "--pr", "7"], + format!("{prefix}/web/7"), + ), + ( + vec!["run", "--repo", "acme/web", "--pr", "7", "--run", "2"], + format!("{prefix}/web/7/runs/2"), + ), + // A bare name is the address segment itself and needs no lookup. + ( + vec!["history", "--repo", "web", "--pr", "7"], + format!("{prefix}/web/7"), + ), + ] { + requests.lock().unwrap().clear(); + let output = cli(&origin, &args).await; + assert!( + output.status.success(), + "{args:?}: {}", + String::from_utf8_lossy(&output.stderr) + ); + assert_eq!(requests.lock().unwrap().last(), Some(&expected), "{args:?}"); + } + // Another owner's repository of the same name is refused, not read. + requests.lock().unwrap().clear(); + let output = cli(&origin, &["history", "--repo", "other/web", "--pr", "7"]).await; + assert_eq!(output.status.code(), Some(1)); + assert!(String::from_utf8_lossy(&output.stderr).contains("other/web has no reviews")); + assert!( + requests + .lock() + .unwrap() + .iter() + .all(|path| !path.starts_with(&prefix)) + ); + server.abort(); +} + #[tokio::test] async fn native_session_and_collection_keep_scope_cursor_and_single_start() { let starts = Arc::new(AtomicUsize::new(0));