diff --git a/crates/grove-providers/src/gitea.rs b/crates/grove-providers/src/gitea.rs index f143ae2..8a70bda 100644 --- a/crates/grove-providers/src/gitea.rs +++ b/crates/grove-providers/src/gitea.rs @@ -55,6 +55,17 @@ impl Provider for Gitea { .ok_or_else(|| Error::Other("response has no login".into())) } + fn get_repo(&self, owner: &str, name: &str) -> Result { + let v = self + .http + .ok("GET", &format!("/repos/{owner}/{name}"), None)?; + // `repo` defaults a missing flag to public; for a visibility check that must be an error. + if !v["private"].is_boolean() { + return Err(Error::Other("response has no `private` flag".into())); + } + Ok(repo(&v)) + } + fn list_repos(&self) -> Result> { let mut out = Vec::new(); for page in 1..=200 { diff --git a/crates/grove-providers/src/github.rs b/crates/grove-providers/src/github.rs index a1ac8c2..83612ca 100644 --- a/crates/grove-providers/src/github.rs +++ b/crates/grove-providers/src/github.rs @@ -54,6 +54,17 @@ impl Provider for GitHub { .ok_or_else(|| Error::Other("response has no login".into())) } + fn get_repo(&self, owner: &str, name: &str) -> Result { + let v = self + .http + .ok("GET", &format!("/repos/{owner}/{name}"), None)?; + // `repo` defaults a missing flag to public; for a visibility check that must be an error. + if !v["private"].is_boolean() { + return Err(Error::Other("response has no `private` flag".into())); + } + Ok(repo(&v)) + } + fn list_repos(&self) -> Result> { let mut out = Vec::new(); for page in 1..=200 { diff --git a/crates/grove-providers/src/lib.rs b/crates/grove-providers/src/lib.rs index 822a029..d5d1fe4 100644 --- a/crates/grove-providers/src/lib.rs +++ b/crates/grove-providers/src/lib.rs @@ -104,6 +104,8 @@ pub trait Provider { fn capabilities(&self) -> Capabilities; /// Verifies the token and returns the authenticated login. fn test_connection(&self) -> Result; + /// One repo's metadata (notably its visibility): `GET /repos/{owner}/{repo}`. + fn get_repo(&self, owner: &str, name: &str) -> Result; fn list_repos(&self) -> Result>; fn create_repo(&self, new: &NewRepo) -> Result; fn configure_mirror(&self, owner: &str, repo: &str, spec: &MirrorSpec) -> Result<()>; diff --git a/crates/grove-providers/tests/api.rs b/crates/grove-providers/tests/api.rs index 80e9b1a..eac4456 100644 --- a/crates/grove-providers/tests/api.rs +++ b/crates/grove-providers/tests/api.rs @@ -318,3 +318,34 @@ fn falls_back_to_tea_and_gh_logins() { assert!(token::resolve(&id, &github).is_err()); std::fs::remove_dir_all(&dir).unwrap(); } + +#[test] +fn get_repo_reports_visibility_on_both_forges() { + let (url, rx) = mock(vec![ + ( + 200, + r#"{"name":"r","private":true,"clone_url":"u","default_branch":"main","owner":{"login":"o"}}"#, + ), + (404, r#"{"message":"not found"}"#), + (200, r#"{"name":"r","owner":{"login":"o"}}"#), + ]); + let g = Gitea::new(ProviderKind::Gitea, &url, "t".into()); + let r = g.get_repo("o", "r").unwrap(); + assert!(r.private); + assert!(rx.recv().unwrap().starts_with("GET /api/v1/repos/o/r ")); + assert!(matches!( + g.get_repo("o", "gone").unwrap_err(), + Error::Api { status: 404, .. } + )); + rx.recv().unwrap(); + // A reply without the flag is an error, never "public by default". + assert!(g.get_repo("o", "r").is_err()); + + let (url, rx) = mock(vec![( + 200, + r#"{"name":"r","private":false,"clone_url":"u","default_branch":"main","owner":{"login":"o"}}"#, + )]); + let gh = GitHub::new(&url, "t".into()); + assert!(!gh.get_repo("o", "r").unwrap().private); + assert!(rx.recv().unwrap().starts_with("GET /repos/o/r ")); +}