diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-11-27 17:08:25 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-11-27 17:08:25 +0000 |
| commit | 83448a99aaf18c7a045a081c5de0c22bc4a83de1 (patch) | |
| tree | 28076a33b40e63937d79a8fe8d54b58d42db092c /src/lib/git_events.rs | |
| parent | 5478aa74cc26452809e499a461067ca9744cb7ce (diff) | |
chore: bump rust-nosrt v0.37.0
use RelayUrl in repo_ref which I had resisted as it mutates relay
urls when printed to append a slash
Diffstat (limited to 'src/lib/git_events.rs')
| -rw-r--r-- | src/lib/git_events.rs | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/lib/git_events.rs b/src/lib/git_events.rs index bfe5b30..c4d6770 100644 --- a/src/lib/git_events.rs +++ b/src/lib/git_events.rs | |||
| @@ -4,7 +4,7 @@ use anyhow::{bail, Context, Result}; | |||
| 4 | use nostr::nips::{nip01::Coordinate, nip10::Marker, nip19::Nip19}; | 4 | use nostr::nips::{nip01::Coordinate, nip10::Marker, nip19::Nip19}; |
| 5 | use nostr_sdk::{ | 5 | use nostr_sdk::{ |
| 6 | hashes::sha1::Hash as Sha1Hash, Event, EventBuilder, EventId, FromBech32, Kind, NostrSigner, | 6 | hashes::sha1::Hash as Sha1Hash, Event, EventBuilder, EventId, FromBech32, Kind, NostrSigner, |
| 7 | PublicKey, Tag, TagKind, TagStandard, UncheckedUrl, | 7 | PublicKey, RelayUrl, Tag, TagKind, TagStandard, |
| 8 | }; | 8 | }; |
| 9 | 9 | ||
| 10 | use crate::{ | 10 | use crate::{ |
| @@ -96,7 +96,7 @@ pub async fn generate_patch_event( | |||
| 96 | let commit_parent = git_repo | 96 | let commit_parent = git_repo |
| 97 | .get_commit_parent(commit) | 97 | .get_commit_parent(commit) |
| 98 | .context("failed to get parent commit")?; | 98 | .context("failed to get parent commit")?; |
| 99 | let relay_hint = repo_ref.relays.first().map(nostr::UncheckedUrl::from); | 99 | let relay_hint = repo_ref.relays.first().cloned(); |
| 100 | 100 | ||
| 101 | sign_event( | 101 | sign_event( |
| 102 | EventBuilder::new( | 102 | EventBuilder::new( |
| @@ -104,6 +104,8 @@ pub async fn generate_patch_event( | |||
| 104 | git_repo | 104 | git_repo |
| 105 | .make_patch_from_commit(commit, &series_count) | 105 | .make_patch_from_commit(commit, &series_count) |
| 106 | .context(format!("failed to make patch for commit {commit}"))?, | 106 | .context(format!("failed to make patch for commit {commit}"))?, |
| 107 | ) | ||
| 108 | .tags( | ||
| 107 | [ | 109 | [ |
| 108 | repo_ref | 110 | repo_ref |
| 109 | .maintainers | 111 | .maintainers |
| @@ -141,6 +143,7 @@ pub async fn generate_patch_event( | |||
| 141 | relay_url: relay_hint.clone(), | 143 | relay_url: relay_hint.clone(), |
| 142 | marker: Some(Marker::Root), | 144 | marker: Some(Marker::Root), |
| 143 | public_key: None, | 145 | public_key: None, |
| 146 | uppercase: false, | ||
| 144 | })] | 147 | })] |
| 145 | } else if let Some(event_ref) = root_proposal_id.clone() { | 148 | } else if let Some(event_ref) = root_proposal_id.clone() { |
| 146 | vec![ | 149 | vec![ |
| @@ -165,6 +168,7 @@ pub async fn generate_patch_event( | |||
| 165 | relay_url: relay_hint.clone(), | 168 | relay_url: relay_hint.clone(), |
| 166 | marker: Some(Marker::Reply), | 169 | marker: Some(Marker::Reply), |
| 167 | public_key: None, | 170 | public_key: None, |
| 171 | uppercase: false, | ||
| 168 | })] | 172 | })] |
| 169 | } else { | 173 | } else { |
| 170 | vec![] | 174 | vec![] |
| @@ -256,9 +260,10 @@ pub fn event_tag_from_nip19_or_hex( | |||
| 256 | Nip19::Event(n) => { | 260 | Nip19::Event(n) => { |
| 257 | break Ok(Tag::from_standardized(nostr_sdk::TagStandard::Event { | 261 | break Ok(Tag::from_standardized(nostr_sdk::TagStandard::Event { |
| 258 | event_id: n.event_id, | 262 | event_id: n.event_id, |
| 259 | relay_url: n.relays.first().map(UncheckedUrl::new), | 263 | relay_url: n.relays.first().and_then(|url| RelayUrl::parse(url).ok()), |
| 260 | marker: Some(marker), | 264 | marker: Some(marker), |
| 261 | public_key: None, | 265 | public_key: None, |
| 266 | uppercase: false, | ||
| 262 | })); | 267 | })); |
| 263 | } | 268 | } |
| 264 | Nip19::EventId(id) => { | 269 | Nip19::EventId(id) => { |
| @@ -267,6 +272,7 @@ pub fn event_tag_from_nip19_or_hex( | |||
| 267 | relay_url: None, | 272 | relay_url: None, |
| 268 | marker: Some(marker), | 273 | marker: Some(marker), |
| 269 | public_key: None, | 274 | public_key: None, |
| 275 | uppercase: false, | ||
| 270 | })); | 276 | })); |
| 271 | } | 277 | } |
| 272 | Nip19::Coordinate(coordinate) => { | 278 | Nip19::Coordinate(coordinate) => { |
| @@ -291,6 +297,7 @@ pub fn event_tag_from_nip19_or_hex( | |||
| 291 | relay_url: None, | 297 | relay_url: None, |
| 292 | marker: Some(marker), | 298 | marker: Some(marker), |
| 293 | public_key: None, | 299 | public_key: None, |
| 300 | uppercase: false, | ||
| 294 | })); | 301 | })); |
| 295 | } | 302 | } |
| 296 | if prompt_for_correction { | 303 | if prompt_for_correction { |
| @@ -326,7 +333,8 @@ pub async fn generate_cover_letter_and_patch_events( | |||
| 326 | "From {} Mon Sep 17 00:00:00 2001\nSubject: [PATCH 0/{}] {title}\n\n{description}", | 333 | "From {} Mon Sep 17 00:00:00 2001\nSubject: [PATCH 0/{}] {title}\n\n{description}", |
| 327 | commits.last().unwrap(), | 334 | commits.last().unwrap(), |
| 328 | commits.len() | 335 | commits.len() |
| 329 | ), | 336 | )) |
| 337 | .tags( | ||
| 330 | [ | 338 | [ |
| 331 | repo_ref.maintainers.iter().map(|m| Tag::coordinate(Coordinate { | 339 | repo_ref.maintainers.iter().map(|m| Tag::coordinate(Coordinate { |
| 332 | kind: nostr::Kind::GitRepoAnnouncement, | 340 | kind: nostr::Kind::GitRepoAnnouncement, |
| @@ -618,7 +626,8 @@ mod tests { | |||
| 618 | Ok(nostr::event::EventBuilder::new( | 626 | Ok(nostr::event::EventBuilder::new( |
| 619 | nostr::event::Kind::GitPatch, | 627 | nostr::event::Kind::GitPatch, |
| 620 | format!("From ea897e987ea9a7a98e7a987e97987ea98e7a3334 Mon Sep 17 00:00:00 2001\nSubject: [PATCH 0/2] {title}\n\n{description}"), | 628 | format!("From ea897e987ea9a7a98e7a987e97987ea98e7a3334 Mon Sep 17 00:00:00 2001\nSubject: [PATCH 0/2] {title}\n\n{description}"), |
| 621 | [ | 629 | ) |
| 630 | .tags([ | ||
| 622 | Tag::hashtag("cover-letter"), | 631 | Tag::hashtag("cover-letter"), |
| 623 | Tag::hashtag("root"), | 632 | Tag::hashtag("root"), |
| 624 | ], | 633 | ], |