upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/lib/git/nostr_url.rs
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2025-04-01 14:31:34 +0100
committerDanConwayDev <DanConwayDev@protonmail.com>2025-04-01 14:35:50 +0100
commit948fe972eb2bddf187b79f2673a091b6331cfd90 (patch)
treeec1c538d28108b104b5a00afd673631538f9aa00 /src/lib/git/nostr_url.rs
parent70966d571fce16f707725c6b0af0fd585bfce607 (diff)
chore: bump rust-nostr v0.37 ~> v0.40
and fix all of the breaking changes
Diffstat (limited to 'src/lib/git/nostr_url.rs')
-rw-r--r--src/lib/git/nostr_url.rs150
1 files changed, 84 insertions, 66 deletions
diff --git a/src/lib/git/nostr_url.rs b/src/lib/git/nostr_url.rs
index ae0ac5f..54be292 100644
--- a/src/lib/git/nostr_url.rs
+++ b/src/lib/git/nostr_url.rs
@@ -2,8 +2,8 @@ use core::fmt;
2use std::{collections::HashMap, str::FromStr}; 2use std::{collections::HashMap, str::FromStr};
3 3
4use anyhow::{Context, Error, Result, anyhow, bail}; 4use anyhow::{Context, Error, Result, anyhow, bail};
5use nostr::nips::{nip01::Coordinate, nip05}; 5use nostr::nips::{nip01::Coordinate, nip05, nip19::Nip19Coordinate};
6use nostr_sdk::{PublicKey, RelayUrl, ToBech32, Url}; 6use nostr_sdk::{FromBech32, PublicKey, RelayUrl, ToBech32, Url};
7 7
8use super::{Repo, get_git_config_item, save_git_config_item}; 8use super::{Repo, get_git_config_item, save_git_config_item};
9 9
@@ -58,7 +58,7 @@ impl FromStr for ServerProtocol {
58#[derive(Debug, PartialEq, Clone)] 58#[derive(Debug, PartialEq, Clone)]
59pub struct NostrUrlDecoded { 59pub struct NostrUrlDecoded {
60 pub original_string: String, 60 pub original_string: String,
61 pub coordinate: Coordinate, 61 pub coordinate: Nip19Coordinate,
62 pub protocol: Option<ServerProtocol>, 62 pub protocol: Option<ServerProtocol>,
63 pub user: Option<String>, 63 pub user: Option<String>,
64 pub nip05: Option<String>, 64 pub nip05: Option<String>,
@@ -166,7 +166,7 @@ impl NostrUrlDecoded {
166 // extract naddr npub/<optional-relays>/identifer 166 // extract naddr npub/<optional-relays>/identifer
167 let part = parts.first().context(INCORRECT_NOSTR_URL_FORMAT_ERROR)?; 167 let part = parts.first().context(INCORRECT_NOSTR_URL_FORMAT_ERROR)?;
168 // naddr used 168 // naddr used
169 let coordinate = if let Ok(coordinate) = Coordinate::parse(part) { 169 let coordinate = if let Ok(coordinate) = Nip19Coordinate::from_bech32(part) {
170 if coordinate.kind.eq(&nostr_sdk::Kind::GitRepoAnnouncement) { 170 if coordinate.kind.eq(&nostr_sdk::Kind::GitRepoAnnouncement) {
171 coordinate 171 coordinate
172 } else { 172 } else {
@@ -225,10 +225,12 @@ impl NostrUrlDecoded {
225 } 225 }
226 } 226 }
227 }; 227 };
228 Coordinate { 228 Nip19Coordinate {
229 identifier, 229 coordinate: Coordinate {
230 public_key, 230 identifier,
231 kind: nostr_sdk::Kind::GitRepoAnnouncement, 231 public_key,
232 kind: nostr_sdk::Kind::GitRepoAnnouncement,
233 },
232 relays, 234 relays,
233 } 235 }
234 }; 236 };
@@ -959,7 +961,7 @@ mod tests {
959 } 961 }
960 } 962 }
961 mod nostr_git_url_format { 963 mod nostr_git_url_format {
962 use nostr::nips::nip01::Coordinate; 964 use nostr::nips::nip19::Nip19Coordinate;
963 use nostr_sdk::PublicKey; 965 use nostr_sdk::PublicKey;
964 966
965 use super::*; 967 use super::*;
@@ -970,13 +972,15 @@ mod tests {
970 assert_eq!( 972 assert_eq!(
971 format!("{}", NostrUrlDecoded { 973 format!("{}", NostrUrlDecoded {
972 original_string: String::new(), 974 original_string: String::new(),
973 coordinate: Coordinate { 975 coordinate: Nip19Coordinate {
974 identifier: "ngit".to_string(), 976 coordinate: Coordinate {
975 public_key: PublicKey::parse( 977 identifier: "ngit".to_string(),
976 "npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr", 978 public_key: PublicKey::parse(
977 ) 979 "npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr",
978 .unwrap(), 980 )
979 kind: nostr_sdk::Kind::GitRepoAnnouncement, 981 .unwrap(),
982 kind: nostr_sdk::Kind::GitRepoAnnouncement,
983 },
980 relays: vec![RelayUrl::parse("wss://nos.lol").unwrap()], 984 relays: vec![RelayUrl::parse("wss://nos.lol").unwrap()],
981 }, 985 },
982 protocol: None, 986 protocol: None,
@@ -993,13 +997,15 @@ mod tests {
993 assert_eq!( 997 assert_eq!(
994 format!("{}", NostrUrlDecoded { 998 format!("{}", NostrUrlDecoded {
995 original_string: String::new(), 999 original_string: String::new(),
996 coordinate: Coordinate { 1000 coordinate: Nip19Coordinate {
997 identifier: "ngit".to_string(), 1001 coordinate: Coordinate {
998 public_key: PublicKey::parse( 1002 identifier: "ngit".to_string(),
999 "npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr", 1003 public_key: PublicKey::parse(
1000 ) 1004 "npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr",
1001 .unwrap(), 1005 )
1002 kind: nostr_sdk::Kind::GitRepoAnnouncement, 1006 .unwrap(),
1007 kind: nostr_sdk::Kind::GitRepoAnnouncement,
1008 },
1003 relays: vec![], 1009 relays: vec![],
1004 }, 1010 },
1005 protocol: None, 1011 protocol: None,
@@ -1016,13 +1022,15 @@ mod tests {
1016 assert_eq!( 1022 assert_eq!(
1017 format!("{}", NostrUrlDecoded { 1023 format!("{}", NostrUrlDecoded {
1018 original_string: String::new(), 1024 original_string: String::new(),
1019 coordinate: Coordinate { 1025 coordinate: Nip19Coordinate {
1020 identifier: "ngit".to_string(), 1026 coordinate: Coordinate {
1021 public_key: PublicKey::parse( 1027 identifier: "ngit".to_string(),
1022 "npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr", 1028 public_key: PublicKey::parse(
1023 ) 1029 "npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr",
1024 .unwrap(), 1030 )
1025 kind: nostr_sdk::Kind::GitRepoAnnouncement, 1031 .unwrap(),
1032 kind: nostr_sdk::Kind::GitRepoAnnouncement,
1033 },
1026 relays: vec![RelayUrl::parse("wss://nos.lol").unwrap()], 1034 relays: vec![RelayUrl::parse("wss://nos.lol").unwrap()],
1027 }, 1035 },
1028 protocol: Some(ServerProtocol::Ssh), 1036 protocol: Some(ServerProtocol::Ssh),
@@ -1039,13 +1047,15 @@ mod tests {
1039 assert_eq!( 1047 assert_eq!(
1040 format!("{}", NostrUrlDecoded { 1048 format!("{}", NostrUrlDecoded {
1041 original_string: String::new(), 1049 original_string: String::new(),
1042 coordinate: Coordinate { 1050 coordinate: Nip19Coordinate {
1043 identifier: "ngit".to_string(), 1051 coordinate: Coordinate {
1044 public_key: PublicKey::parse( 1052 identifier: "ngit".to_string(),
1045 "npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr", 1053 public_key: PublicKey::parse(
1046 ) 1054 "npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr",
1047 .unwrap(), 1055 )
1048 kind: nostr_sdk::Kind::GitRepoAnnouncement, 1056 .unwrap(),
1057 kind: nostr_sdk::Kind::GitRepoAnnouncement,
1058 },
1049 relays: vec![RelayUrl::parse("wss://nos.lol").unwrap()], 1059 relays: vec![RelayUrl::parse("wss://nos.lol").unwrap()],
1050 }, 1060 },
1051 protocol: Some(ServerProtocol::Ssh), 1061 protocol: Some(ServerProtocol::Ssh),
@@ -1061,14 +1071,16 @@ mod tests {
1061 mod nostr_url_decoded_paramemters_from_str { 1071 mod nostr_url_decoded_paramemters_from_str {
1062 use super::*; 1072 use super::*;
1063 1073
1064 fn get_model_coordinate(relays: bool) -> Coordinate { 1074 fn get_model_coordinate(relays: bool) -> Nip19Coordinate {
1065 Coordinate { 1075 Nip19Coordinate {
1066 identifier: "ngit".to_string(), 1076 coordinate: Coordinate {
1067 public_key: PublicKey::parse( 1077 identifier: "ngit".to_string(),
1068 "npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr", 1078 public_key: PublicKey::parse(
1069 ) 1079 "npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr",
1070 .unwrap(), 1080 )
1071 kind: nostr_sdk::Kind::GitRepoAnnouncement, 1081 .unwrap(),
1082 kind: nostr_sdk::Kind::GitRepoAnnouncement,
1083 },
1072 relays: if relays { 1084 relays: if relays {
1073 vec![RelayUrl::parse("wss://nos.lol").unwrap()] 1085 vec![RelayUrl::parse("wss://nos.lol").unwrap()]
1074 } else { 1086 } else {
@@ -1084,13 +1096,15 @@ mod tests {
1084 NostrUrlDecoded::parse_and_resolve(&url, &None).await?, 1096 NostrUrlDecoded::parse_and_resolve(&url, &None).await?,
1085 NostrUrlDecoded { 1097 NostrUrlDecoded {
1086 original_string: url.clone(), 1098 original_string: url.clone(),
1087 coordinate: Coordinate { 1099 coordinate: Nip19Coordinate {
1088 identifier: "ngit".to_string(), 1100 coordinate: Coordinate {
1089 public_key: PublicKey::parse( 1101 identifier: "ngit".to_string(),
1090 "npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr", 1102 public_key: PublicKey::parse(
1091 ) 1103 "npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr",
1092 .unwrap(), 1104 )
1093 kind: nostr_sdk::Kind::GitRepoAnnouncement, 1105 .unwrap(),
1106 kind: nostr_sdk::Kind::GitRepoAnnouncement,
1107 },
1094 relays: vec![RelayUrl::parse("wss://nos.lol").unwrap()], /* wont add the 1108 relays: vec![RelayUrl::parse("wss://nos.lol").unwrap()], /* wont add the
1095 * slash */ 1109 * slash */
1096 }, 1110 },
@@ -1172,13 +1186,15 @@ mod tests {
1172 NostrUrlDecoded::parse_and_resolve(&url, &None).await?, 1186 NostrUrlDecoded::parse_and_resolve(&url, &None).await?,
1173 NostrUrlDecoded { 1187 NostrUrlDecoded {
1174 original_string: url.clone(), 1188 original_string: url.clone(),
1175 coordinate: Coordinate { 1189 coordinate: Nip19Coordinate {
1176 identifier: "ngit".to_string(), 1190 coordinate: Coordinate {
1177 public_key: PublicKey::parse( 1191 identifier: "ngit".to_string(),
1178 "npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr", 1192 public_key: PublicKey::parse(
1179 ) 1193 "npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr",
1180 .unwrap(), 1194 )
1181 kind: nostr_sdk::Kind::GitRepoAnnouncement, 1195 .unwrap(),
1196 kind: nostr_sdk::Kind::GitRepoAnnouncement,
1197 },
1182 relays: vec![ 1198 relays: vec![
1183 RelayUrl::parse("wss://nos.lol/").unwrap(), 1199 RelayUrl::parse("wss://nos.lol/").unwrap(),
1184 RelayUrl::parse("wss://relay.damus.io/").unwrap(), 1200 RelayUrl::parse("wss://relay.damus.io/").unwrap(),
@@ -1274,13 +1290,15 @@ mod tests {
1274 NostrUrlDecoded::parse_and_resolve(&url, &None).await?, 1290 NostrUrlDecoded::parse_and_resolve(&url, &None).await?,
1275 NostrUrlDecoded { 1291 NostrUrlDecoded {
1276 original_string: url.clone(), 1292 original_string: url.clone(),
1277 coordinate: Coordinate { 1293 coordinate: Nip19Coordinate {
1278 identifier: "ngit".to_string(), 1294 coordinate: Coordinate {
1279 public_key: PublicKey::parse( 1295 identifier: "ngit".to_string(),
1280 "npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr", 1296 public_key: PublicKey::parse(
1281 ) 1297 "npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr",
1282 .unwrap(), 1298 )
1283 kind: nostr_sdk::Kind::GitRepoAnnouncement, 1299 .unwrap(),
1300 kind: nostr_sdk::Kind::GitRepoAnnouncement,
1301 },
1284 relays: vec![ 1302 relays: vec![
1285 RelayUrl::parse("wss://nos.lol/").unwrap(), 1303 RelayUrl::parse("wss://nos.lol/").unwrap(),
1286 RelayUrl::parse("wss://relay.damus.io/").unwrap(), 1304 RelayUrl::parse("wss://relay.damus.io/").unwrap(),