diff options
| author | Laszlo Megyer <lez@github.com> | 2024-12-16 11:38:06 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-12-16 16:50:39 +0000 |
| commit | cc87576cdfdd3aa18df6e94fbfa079d9e4f0241a (patch) | |
| tree | a8c2bdb2333b75b7ead07dc6253635acf7a9c711 /src/lib/git | |
| parent | 4ee83e2fe5335a8afd78439c35f029c4a472e797 (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/git')
| -rw-r--r-- | src/lib/git/nostr_url.rs | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/lib/git/nostr_url.rs b/src/lib/git/nostr_url.rs index 6b38a93..de7953f 100644 --- a/src/lib/git/nostr_url.rs +++ b/src/lib/git/nostr_url.rs | |||
| @@ -55,7 +55,7 @@ impl FromStr for ServerProtocol { | |||
| 55 | } | 55 | } |
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | #[derive(Debug, PartialEq)] | 58 | #[derive(Debug, PartialEq, Clone)] |
| 59 | pub struct NostrUrlDecoded { | 59 | pub struct NostrUrlDecoded { |
| 60 | pub original_string: String, | 60 | pub original_string: String, |
| 61 | pub coordinate: Coordinate, | 61 | pub coordinate: Coordinate, |
| @@ -73,7 +73,11 @@ impl fmt::Display for NostrUrlDecoded { | |||
| 73 | if let Some(protocol) = &self.protocol { | 73 | if let Some(protocol) = &self.protocol { |
| 74 | write!(f, "{}/", protocol)?; | 74 | write!(f, "{}/", protocol)?; |
| 75 | } | 75 | } |
| 76 | write!(f, "{}/", self.coordinate.public_key.to_bech32().unwrap())?; | 76 | if let Some(nip05) = &self.nip05 { |
| 77 | write!(f, "{}/", nip05)?; | ||
| 78 | } else { | ||
| 79 | write!(f, "{}/", self.coordinate.public_key.to_bech32().unwrap())?; | ||
| 80 | } | ||
| 77 | if let Some(relay) = self.coordinate.relays.first() { | 81 | if let Some(relay) = self.coordinate.relays.first() { |
| 78 | write!( | 82 | write!( |
| 79 | f, | 83 | f, |
| @@ -97,6 +101,7 @@ impl NostrUrlDecoded { | |||
| 97 | let mut protocol = None; | 101 | let mut protocol = None; |
| 98 | let mut user = None; | 102 | let mut user = None; |
| 99 | let mut relays = vec![]; | 103 | let mut relays = vec![]; |
| 104 | let mut nip05 = None; | ||
| 100 | 105 | ||
| 101 | if !url.starts_with("nostr://") { | 106 | if !url.starts_with("nostr://") { |
| 102 | bail!("nostr git url must start with nostr://"); | 107 | bail!("nostr git url must start with nostr://"); |
| @@ -157,7 +162,6 @@ impl NostrUrlDecoded { | |||
| 157 | } | 162 | } |
| 158 | // extract naddr npub/<optional-relays>/identifer | 163 | // extract naddr npub/<optional-relays>/identifer |
| 159 | let part = parts.first().context(INCORRECT_NOSTR_URL_FORMAT_ERROR)?; | 164 | let part = parts.first().context(INCORRECT_NOSTR_URL_FORMAT_ERROR)?; |
| 160 | let mut nip05 = None; | ||
| 161 | // naddr used | 165 | // naddr used |
| 162 | let coordinate = if let Ok(coordinate) = Coordinate::parse(part) { | 166 | let coordinate = if let Ok(coordinate) = Coordinate::parse(part) { |
| 163 | if coordinate.kind.eq(&nostr_sdk::Kind::GitRepoAnnouncement) { | 167 | if coordinate.kind.eq(&nostr_sdk::Kind::GitRepoAnnouncement) { |
| @@ -254,7 +258,7 @@ pub fn use_nip05_git_config_cache_to_find_nip05_from_public_key( | |||
| 254 | .cloned()) | 258 | .cloned()) |
| 255 | } | 259 | } |
| 256 | 260 | ||
| 257 | fn save_nip05_to_git_config_cache( | 261 | pub fn save_nip05_to_git_config_cache( |
| 258 | nip05: &str, | 262 | nip05: &str, |
| 259 | public_key: &PublicKey, | 263 | public_key: &PublicKey, |
| 260 | git_repo: &Option<&Repo>, | 264 | git_repo: &Option<&Repo>, |