diff options
Diffstat (limited to 'src/lib/git/nostr_url.rs')
| -rw-r--r-- | src/lib/git/nostr_url.rs | 136 |
1 files changed, 62 insertions, 74 deletions
diff --git a/src/lib/git/nostr_url.rs b/src/lib/git/nostr_url.rs index 4fbc786..6b38a93 100644 --- a/src/lib/git/nostr_url.rs +++ b/src/lib/git/nostr_url.rs | |||
| @@ -1,11 +1,11 @@ | |||
| 1 | use core::fmt; | 1 | use core::fmt; |
| 2 | use std::{collections::HashMap, str::FromStr}; | 2 | use std::{collections::HashMap, str::FromStr}; |
| 3 | 3 | ||
| 4 | use anyhow::{anyhow, bail, Context, Error, Result}; | 4 | use anyhow::{Context, Error, Result, anyhow, bail}; |
| 5 | use nostr::nips::{nip01::Coordinate, nip05}; | 5 | use nostr::nips::{nip01::Coordinate, nip05}; |
| 6 | use nostr_sdk::{PublicKey, RelayUrl, ToBech32, Url}; | 6 | use nostr_sdk::{PublicKey, RelayUrl, ToBech32, Url}; |
| 7 | 7 | ||
| 8 | use super::{get_git_config_item, save_git_config_item, Repo}; | 8 | use super::{Repo, get_git_config_item, save_git_config_item}; |
| 9 | 9 | ||
| 10 | #[derive(Debug, PartialEq, Default, Clone)] | 10 | #[derive(Debug, PartialEq, Default, Clone)] |
| 11 | pub enum ServerProtocol { | 11 | pub enum ServerProtocol { |
| @@ -961,24 +961,21 @@ mod tests { | |||
| 961 | #[test] | 961 | #[test] |
| 962 | fn standard() -> Result<()> { | 962 | fn standard() -> Result<()> { |
| 963 | assert_eq!( | 963 | assert_eq!( |
| 964 | format!( | 964 | format!("{}", NostrUrlDecoded { |
| 965 | "{}", | 965 | original_string: String::new(), |
| 966 | NostrUrlDecoded { | 966 | coordinate: Coordinate { |
| 967 | original_string: String::new(), | 967 | identifier: "ngit".to_string(), |
| 968 | coordinate: Coordinate { | 968 | public_key: PublicKey::parse( |
| 969 | identifier: "ngit".to_string(), | 969 | "npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr", |
| 970 | public_key: PublicKey::parse( | 970 | ) |
| 971 | "npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr", | 971 | .unwrap(), |
| 972 | ) | 972 | kind: nostr_sdk::Kind::GitRepoAnnouncement, |
| 973 | .unwrap(), | 973 | relays: vec![RelayUrl::parse("wss://nos.lol").unwrap()], |
| 974 | kind: nostr_sdk::Kind::GitRepoAnnouncement, | 974 | }, |
| 975 | relays: vec![RelayUrl::parse("wss://nos.lol").unwrap()], | 975 | protocol: None, |
| 976 | }, | 976 | user: None, |
| 977 | protocol: None, | 977 | nip05: None, |
| 978 | user: None, | 978 | }), |
| 979 | nip05: None, | ||
| 980 | } | ||
| 981 | ), | ||
| 982 | "nostr://npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/nos.lol/ngit", | 979 | "nostr://npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/nos.lol/ngit", |
| 983 | ); | 980 | ); |
| 984 | Ok(()) | 981 | Ok(()) |
| @@ -987,24 +984,21 @@ mod tests { | |||
| 987 | #[test] | 984 | #[test] |
| 988 | fn no_relay() -> Result<()> { | 985 | fn no_relay() -> Result<()> { |
| 989 | assert_eq!( | 986 | assert_eq!( |
| 990 | format!( | 987 | format!("{}", NostrUrlDecoded { |
| 991 | "{}", | 988 | original_string: String::new(), |
| 992 | NostrUrlDecoded { | 989 | coordinate: Coordinate { |
| 993 | original_string: String::new(), | 990 | identifier: "ngit".to_string(), |
| 994 | coordinate: Coordinate { | 991 | public_key: PublicKey::parse( |
| 995 | identifier: "ngit".to_string(), | 992 | "npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr", |
| 996 | public_key: PublicKey::parse( | 993 | ) |
| 997 | "npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr", | 994 | .unwrap(), |
| 998 | ) | 995 | kind: nostr_sdk::Kind::GitRepoAnnouncement, |
| 999 | .unwrap(), | 996 | relays: vec![], |
| 1000 | kind: nostr_sdk::Kind::GitRepoAnnouncement, | 997 | }, |
| 1001 | relays: vec![], | 998 | protocol: None, |
| 1002 | }, | 999 | user: None, |
| 1003 | protocol: None, | 1000 | nip05: None, |
| 1004 | user: None, | 1001 | }), |
| 1005 | nip05: None, | ||
| 1006 | } | ||
| 1007 | ), | ||
| 1008 | "nostr://npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/ngit", | 1002 | "nostr://npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/ngit", |
| 1009 | ); | 1003 | ); |
| 1010 | Ok(()) | 1004 | Ok(()) |
| @@ -1013,24 +1007,21 @@ mod tests { | |||
| 1013 | #[test] | 1007 | #[test] |
| 1014 | fn with_protocol() -> Result<()> { | 1008 | fn with_protocol() -> Result<()> { |
| 1015 | assert_eq!( | 1009 | assert_eq!( |
| 1016 | format!( | 1010 | format!("{}", NostrUrlDecoded { |
| 1017 | "{}", | 1011 | original_string: String::new(), |
| 1018 | NostrUrlDecoded { | 1012 | coordinate: Coordinate { |
| 1019 | original_string: String::new(), | 1013 | identifier: "ngit".to_string(), |
| 1020 | coordinate: Coordinate { | 1014 | public_key: PublicKey::parse( |
| 1021 | identifier: "ngit".to_string(), | 1015 | "npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr", |
| 1022 | public_key: PublicKey::parse( | 1016 | ) |
| 1023 | "npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr", | 1017 | .unwrap(), |
| 1024 | ) | 1018 | kind: nostr_sdk::Kind::GitRepoAnnouncement, |
| 1025 | .unwrap(), | 1019 | relays: vec![RelayUrl::parse("wss://nos.lol").unwrap()], |
| 1026 | kind: nostr_sdk::Kind::GitRepoAnnouncement, | 1020 | }, |
| 1027 | relays: vec![RelayUrl::parse("wss://nos.lol").unwrap()], | 1021 | protocol: Some(ServerProtocol::Ssh), |
| 1028 | }, | 1022 | user: None, |
| 1029 | protocol: Some(ServerProtocol::Ssh), | 1023 | nip05: None, |
| 1030 | user: None, | 1024 | }), |
| 1031 | nip05: None, | ||
| 1032 | } | ||
| 1033 | ), | ||
| 1034 | "nostr://ssh/npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/nos.lol/ngit", | 1025 | "nostr://ssh/npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/nos.lol/ngit", |
| 1035 | ); | 1026 | ); |
| 1036 | Ok(()) | 1027 | Ok(()) |
| @@ -1039,24 +1030,21 @@ mod tests { | |||
| 1039 | #[test] | 1030 | #[test] |
| 1040 | fn with_protocol_and_user() -> Result<()> { | 1031 | fn with_protocol_and_user() -> Result<()> { |
| 1041 | assert_eq!( | 1032 | assert_eq!( |
| 1042 | format!( | 1033 | format!("{}", NostrUrlDecoded { |
| 1043 | "{}", | 1034 | original_string: String::new(), |
| 1044 | NostrUrlDecoded { | 1035 | coordinate: Coordinate { |
| 1045 | original_string: String::new(), | 1036 | identifier: "ngit".to_string(), |
| 1046 | coordinate: Coordinate { | 1037 | public_key: PublicKey::parse( |
| 1047 | identifier: "ngit".to_string(), | 1038 | "npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr", |
| 1048 | public_key: PublicKey::parse( | 1039 | ) |
| 1049 | "npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr", | 1040 | .unwrap(), |
| 1050 | ) | 1041 | kind: nostr_sdk::Kind::GitRepoAnnouncement, |
| 1051 | .unwrap(), | 1042 | relays: vec![RelayUrl::parse("wss://nos.lol").unwrap()], |
| 1052 | kind: nostr_sdk::Kind::GitRepoAnnouncement, | 1043 | }, |
| 1053 | relays: vec![RelayUrl::parse("wss://nos.lol").unwrap()], | 1044 | protocol: Some(ServerProtocol::Ssh), |
| 1054 | }, | 1045 | user: Some("bla".to_string()), |
| 1055 | protocol: Some(ServerProtocol::Ssh), | 1046 | nip05: None, |
| 1056 | user: Some("bla".to_string()), | 1047 | }), |
| 1057 | nip05: None, | ||
| 1058 | } | ||
| 1059 | ), | ||
| 1060 | "nostr://bla@ssh/npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/nos.lol/ngit", | 1048 | "nostr://bla@ssh/npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/nos.lol/ngit", |
| 1061 | ); | 1049 | ); |
| 1062 | Ok(()) | 1050 | Ok(()) |