diff --git a/src/main.rs b/src/main.rs --- a/src/main.rs +++ b/src/main.rs @@ -21,6 +21,7 @@ language::Language, collection::Collection, value::Data, + string::AtUri, }, }; use std::time::Duration; @@ -118,6 +119,31 @@ .ok_or("get_record response.value was not an object")? .clone(); Ok(record_map) +} + +async fn get_handle(client: &reqwest::Client, identifier: &str) -> Result> { + let mut url: Url = "https://slingshot.microcosm.blue".parse()?; + url.set_path("/xrpc/com.bad-example.identity.resolveMiniDoc"); + url.query_pairs_mut().append_pair("identifier", identifier); + let handle = client + .get(url) + .send() + .await? + .error_for_status()? + .json::() + .await? + .as_object() + .ok_or("minidoc response was not a json object")? + .get("handle") + .ok_or("minidoc response obj did not have 'handle' key")? + .as_str() + .ok_or("minidoc handle was not a string")? + .to_string(); + if handle == "handle.invalid" { + Ok(None) + } else { + Ok(Some(handle)) + } } #[tokio::main] @@ -238,6 +264,11 @@ continue; }; + let Ok(repo_uri) = AtUri::new(repo) else { + eprintln!("failed to parse repo to aturi for {subject}"); + continue; + }; + let repo_record = match get_record(&req_client, repo).await { Ok(m) => m, Err(e) => { @@ -249,6 +280,23 @@ eprintln!("failed to get name for repo for {subject}"); continue; }; + + let repo_handle = match get_handle(&req_client, repo_uri.authority().as_str()).await { + Ok(Some(h)) => h, + Ok(None) => { + eprintln!("invalid handle from identifier in {repo_uri} for {subject}"); + continue; + } + Err(e) => { + eprintln!("failed to get repo handle from identifier: {e} for {subject}"); + continue; + } + }; + + let issues_url = format!("https://tangled.org/@{repo_handle}/{name}/issues"); + println!("hi: {issues_url}"); + + // let message = format!(r#""#); eprintln!("got {subject} {title:?} for {name}"); }