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:
authorLaszlo Megyer <lez@github.com>2024-12-16 11:38:06 +0100
committerDanConwayDev <DanConwayDev@protonmail.com>2024-12-16 16:50:39 +0000
commitcc87576cdfdd3aa18df6e94fbfa079d9e4f0241a (patch)
treea8c2bdb2333b75b7ead07dc6253635acf7a9c711 /src/lib/repo_ref.rs
parent4ee83e2fe5335a8afd78439c35f029c4a472e797 (diff)
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.
Diffstat (limited to 'src/lib/repo_ref.rs')
-rw-r--r--src/lib/repo_ref.rs10
1 files changed, 10 insertions, 0 deletions
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 {
38 pub maintainers: Vec<PublicKey>, 38 pub maintainers: Vec<PublicKey>,
39 pub trusted_maintainer: PublicKey, 39 pub trusted_maintainer: PublicKey,
40 pub events: HashMap<Coordinate, nostr::Event>, 40 pub events: HashMap<Coordinate, nostr::Event>,
41 pub nostr_git_url: Option<NostrUrlDecoded>,
41} 42}
42 43
43impl TryFrom<(nostr::Event, Option<PublicKey>)> for RepoRef { 44impl TryFrom<(nostr::Event, Option<PublicKey>)> for RepoRef {
@@ -60,6 +61,7 @@ impl TryFrom<(nostr::Event, Option<PublicKey>)> for RepoRef {
60 maintainers: Vec::new(), 61 maintainers: Vec::new(),
61 trusted_maintainer: trusted_maintainer.unwrap_or(event.pubkey), 62 trusted_maintainer: trusted_maintainer.unwrap_or(event.pubkey),
62 events: HashMap::new(), 63 events: HashMap::new(),
64 nostr_git_url: None,
63 }; 65 };
64 66
65 for tag in event.tags.iter() { 67 for tag in event.tags.iter() {
@@ -235,7 +237,14 @@ impl RepoRef {
235 .collect::<Vec<(Coordinate, Option<Timestamp>)>>() 237 .collect::<Vec<(Coordinate, Option<Timestamp>)>>()
236 } 238 }
237 239
240 pub fn set_nostr_git_url(&mut self, nostr_git_url: NostrUrlDecoded) {
241 self.nostr_git_url = Some(nostr_git_url)
242 }
243
238 pub fn to_nostr_git_url(&self, git_repo: &Option<&Repo>) -> String { 244 pub fn to_nostr_git_url(&self, git_repo: &Option<&Repo>) -> String {
245 if let Some(nostr_git_url) = &self.nostr_git_url {
246 return nostr_git_url.original_string.clone();
247 }
239 let c = self.coordinate_with_hint(); 248 let c = self.coordinate_with_hint();
240 format!("{}", NostrUrlDecoded { 249 format!("{}", NostrUrlDecoded {
241 original_string: String::new(), 250 original_string: String::new(),
@@ -550,6 +559,7 @@ mod tests {
550 trusted_maintainer: TEST_KEY_1_KEYS.public_key(), 559 trusted_maintainer: TEST_KEY_1_KEYS.public_key(),
551 maintainers: vec![TEST_KEY_1_KEYS.public_key(), TEST_KEY_2_KEYS.public_key()], 560 maintainers: vec![TEST_KEY_1_KEYS.public_key(), TEST_KEY_2_KEYS.public_key()],
552 events: HashMap::new(), 561 events: HashMap::new(),
562 nostr_git_url: None,
553 } 563 }
554 .to_event(&TEST_KEY_1_SIGNER) 564 .to_event(&TEST_KEY_1_SIGNER)
555 .await 565 .await