From cc87576cdfdd3aa18df6e94fbfa079d9e4f0241a Mon Sep 17 00:00:00 2001 From: Laszlo Megyer Date: Mon, 16 Dec 2024 11:38:06 +0100 Subject: feat(init): default to nip05 git nostr url If the user has NIP-05 set up in profile, and it resolves at the time of running `ngit init`, NIP-05 will be used in the nostr remote url. --- src/lib/repo_ref.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/lib/repo_ref.rs') diff --git a/src/lib/repo_ref.rs b/src/lib/repo_ref.rs index a9d1186..8705597 100644 --- a/src/lib/repo_ref.rs +++ b/src/lib/repo_ref.rs @@ -38,6 +38,7 @@ pub struct RepoRef { pub maintainers: Vec, pub trusted_maintainer: PublicKey, pub events: HashMap, + pub nostr_git_url: Option, } impl TryFrom<(nostr::Event, Option)> for RepoRef { @@ -60,6 +61,7 @@ impl TryFrom<(nostr::Event, Option)> for RepoRef { maintainers: Vec::new(), trusted_maintainer: trusted_maintainer.unwrap_or(event.pubkey), events: HashMap::new(), + nostr_git_url: None, }; for tag in event.tags.iter() { @@ -235,7 +237,14 @@ impl RepoRef { .collect::)>>() } + pub fn set_nostr_git_url(&mut self, nostr_git_url: NostrUrlDecoded) { + self.nostr_git_url = Some(nostr_git_url) + } + pub fn to_nostr_git_url(&self, git_repo: &Option<&Repo>) -> String { + if let Some(nostr_git_url) = &self.nostr_git_url { + return nostr_git_url.original_string.clone(); + } let c = self.coordinate_with_hint(); format!("{}", NostrUrlDecoded { original_string: String::new(), @@ -550,6 +559,7 @@ mod tests { trusted_maintainer: TEST_KEY_1_KEYS.public_key(), maintainers: vec![TEST_KEY_1_KEYS.public_key(), TEST_KEY_2_KEYS.public_key()], events: HashMap::new(), + nostr_git_url: None, } .to_event(&TEST_KEY_1_SIGNER) .await -- cgit v1.2.3