upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/lib/repo_ref.rs
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2024-12-09 09:34:08 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2024-12-10 11:55:01 +0000
commit6d3a4eb870cd344b11ccda13e1339584ed4e4d17 (patch)
tree37cb5787bb62c519a235d5a8b0c5c0985d8b4977 /src/lib/repo_ref.rs
parentf0d0e1ba1cba11d3a98a5ab0c7f1dc72b6bc4e17 (diff)
feat(NostrUrlDecoded) add nip05 support
replace `NostrUrlDecoded::from_str` with `NostrUrlDecoded::parse_and_resolve` store nip05 pubkey mapping in git cache
Diffstat (limited to 'src/lib/repo_ref.rs')
-rw-r--r--src/lib/repo_ref.rs16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/lib/repo_ref.rs b/src/lib/repo_ref.rs
index 1b25ccf..089befc 100644
--- a/src/lib/repo_ref.rs
+++ b/src/lib/repo_ref.rs
@@ -41,6 +41,7 @@ impl TryFrom<(nostr::Event, Option<PublicKey>)> for RepoRef {
41 type Error = anyhow::Error; 41 type Error = anyhow::Error;
42 42
43 fn try_from((event, trusted_maintainer): (nostr::Event, Option<PublicKey>)) -> Result<Self> { 43 fn try_from((event, trusted_maintainer): (nostr::Event, Option<PublicKey>)) -> Result<Self> {
44 // TODO: turn trusted maintainer into NostrUrlDecoded
44 if !event.kind.eq(&Kind::GitRepoAnnouncement) { 45 if !event.kind.eq(&Kind::GitRepoAnnouncement) {
45 bail!("incorrect kind"); 46 bail!("incorrect kind");
46 } 47 }
@@ -239,6 +240,7 @@ impl RepoRef {
239 coordinate: self.coordinate_with_hint(), 240 coordinate: self.coordinate_with_hint(),
240 protocol: None, 241 protocol: None,
241 user: None, 242 user: None,
243 nip05: None, // TODO: if nip05 for pubkey saved in local git config use it.
242 } 244 }
243 ) 245 )
244 } 246 }
@@ -259,7 +261,7 @@ pub async fn get_repo_coordinates_when_remote_unknown(
259pub async fn try_and_get_repo_coordinates_when_remote_unknown( 261pub async fn try_and_get_repo_coordinates_when_remote_unknown(
260 git_repo: &Repo, 262 git_repo: &Repo,
261) -> Result<Coordinate> { 263) -> Result<Coordinate> {
262 let remote_coordinates = get_repo_coordinates_from_nostr_remotes(git_repo)?; 264 let remote_coordinates = get_repo_coordinates_from_nostr_remotes(git_repo).await?;
263 if remote_coordinates.is_empty() { 265 if remote_coordinates.is_empty() {
264 if let Ok(c) = get_repo_coordinates_from_git_config(git_repo) { 266 if let Ok(c) = get_repo_coordinates_from_git_config(git_repo) {
265 Ok(c) 267 Ok(c)
@@ -327,11 +329,15 @@ fn get_repo_coordinates_from_git_config(git_repo: &Repo) -> Result<Coordinate> {
327 .context("git config item \"nostr.repo\" is not an naddr") 329 .context("git config item \"nostr.repo\" is not an naddr")
328} 330}
329 331
330fn get_repo_coordinates_from_nostr_remotes(git_repo: &Repo) -> Result<HashMap<String, Coordinate>> { 332async fn get_repo_coordinates_from_nostr_remotes(
333 git_repo: &Repo,
334) -> Result<HashMap<String, Coordinate>> {
331 let mut repo_coordinates = HashMap::new(); 335 let mut repo_coordinates = HashMap::new();
332 for remote_name in git_repo.git_repo.remotes()?.iter().flatten() { 336 for remote_name in git_repo.git_repo.remotes()?.iter().flatten() {
333 if let Some(remote_url) = git_repo.git_repo.find_remote(remote_name)?.url() { 337 if let Some(remote_url) = git_repo.git_repo.find_remote(remote_name)?.url() {
334 if let Ok(nostr_url_decoded) = NostrUrlDecoded::from_str(remote_url) { 338 if let Ok(nostr_url_decoded) =
339 NostrUrlDecoded::parse_and_resolve(remote_url, &Some(git_repo)).await
340 {
335 repo_coordinates.insert(remote_name.to_string(), nostr_url_decoded.coordinate); 341 repo_coordinates.insert(remote_name.to_string(), nostr_url_decoded.coordinate);
336 } 342 }
337 } 343 }
@@ -383,7 +389,9 @@ async fn get_repo_coordinate_from_user_prompt(
383 .input(PromptInputParms::default().with_prompt("nostr repository"))?; 389 .input(PromptInputParms::default().with_prompt("nostr repository"))?;
384 let coordinate = if let Ok(c) = Coordinate::parse(&input) { 390 let coordinate = if let Ok(c) = Coordinate::parse(&input) {
385 c 391 c
386 } else if let Ok(nostr_url) = NostrUrlDecoded::from_str(&input) { 392 } else if let Ok(nostr_url) =
393 NostrUrlDecoded::parse_and_resolve(&input, &Some(git_repo)).await
394 {
387 nostr_url.coordinate 395 nostr_url.coordinate
388 } else { 396 } else {
389 eprintln!("not a valid naddr or git nostr remote URL starting nostr://"); 397 eprintln!("not a valid naddr or git nostr remote URL starting nostr://");