diff options
Diffstat (limited to 'src/sub_commands')
| -rw-r--r-- | src/sub_commands/init.rs | 17 | ||||
| -rw-r--r-- | src/sub_commands/push.rs | 9 | ||||
| -rw-r--r-- | src/sub_commands/send.rs | 32 |
3 files changed, 30 insertions, 28 deletions
diff --git a/src/sub_commands/init.rs b/src/sub_commands/init.rs index 4d1bdfb..4afe83c 100644 --- a/src/sub_commands/init.rs +++ b/src/sub_commands/init.rs | |||
| @@ -59,7 +59,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 59 | #[cfg(test)] | 59 | #[cfg(test)] |
| 60 | let mut client = <MockConnect as std::default::Default>::default(); | 60 | let mut client = <MockConnect as std::default::Default>::default(); |
| 61 | 61 | ||
| 62 | let (keys, user_ref) = login::launch( | 62 | let (signer, user_ref) = login::launch( |
| 63 | &git_repo, | 63 | &git_repo, |
| 64 | &cli_args.nsec, | 64 | &cli_args.nsec, |
| 65 | &cli_args.password, | 65 | &cli_args.password, |
| @@ -68,8 +68,6 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 68 | ) | 68 | ) |
| 69 | .await?; | 69 | .await?; |
| 70 | 70 | ||
| 71 | client.set_keys(&keys).await; | ||
| 72 | |||
| 73 | let repo_ref = if let Ok(rep_ref) = repo_ref::fetch( | 71 | let repo_ref = if let Ok(rep_ref) = repo_ref::fetch( |
| 74 | &git_repo, | 72 | &git_repo, |
| 75 | root_commit.to_string(), | 73 | root_commit.to_string(), |
| @@ -180,7 +178,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 180 | let mut maintainers_string = if !args.other_maintainers.is_empty() { | 178 | let mut maintainers_string = if !args.other_maintainers.is_empty() { |
| 181 | [args.other_maintainers.clone()].concat().join(" ") | 179 | [args.other_maintainers.clone()].concat().join(" ") |
| 182 | } else if repo_ref.is_none() && repo_config_result.is_err() { | 180 | } else if repo_ref.is_none() && repo_config_result.is_err() { |
| 183 | keys.public_key().to_bech32()? | 181 | signer.public_key().await?.to_bech32()? |
| 184 | } else { | 182 | } else { |
| 185 | let maintainers = if let Ok(config) = &repo_config_result { | 183 | let maintainers = if let Ok(config) = &repo_config_result { |
| 186 | config.maintainers.clone() | 184 | config.maintainers.clone() |
| @@ -193,7 +191,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 193 | .collect() | 191 | .collect() |
| 194 | } else { | 192 | } else { |
| 195 | //unreachable | 193 | //unreachable |
| 196 | vec![keys.public_key().to_bech32()?] | 194 | vec![signer.public_key().await?.to_bech32()?] |
| 197 | }; | 195 | }; |
| 198 | // add current user if not present | 196 | // add current user if not present |
| 199 | if maintainers.iter().any(|m| { | 197 | if maintainers.iter().any(|m| { |
| @@ -205,7 +203,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 205 | }) { | 203 | }) { |
| 206 | maintainers.join(" ") | 204 | maintainers.join(" ") |
| 207 | } else { | 205 | } else { |
| 208 | [maintainers, vec![keys.public_key().to_bech32()?]] | 206 | [maintainers, vec![signer.public_key().await?.to_bech32()?]] |
| 209 | .concat() | 207 | .concat() |
| 210 | .join(" ") | 208 | .join(" ") |
| 211 | } | 209 | } |
| @@ -231,7 +229,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 231 | } | 229 | } |
| 232 | // add current user incase removed | 230 | // add current user incase removed |
| 233 | if !maintainers.iter().any(|m| user_ref.public_key.eq(m)) { | 231 | if !maintainers.iter().any(|m| user_ref.public_key.eq(m)) { |
| 234 | maintainers.push(keys.public_key()); | 232 | maintainers.push(signer.public_key().await?); |
| 235 | } | 233 | } |
| 236 | break maintainers; | 234 | break maintainers; |
| 237 | } | 235 | } |
| @@ -300,7 +298,10 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 300 | relays: relays.clone(), | 298 | relays: relays.clone(), |
| 301 | maintainers: maintainers.clone(), | 299 | maintainers: maintainers.clone(), |
| 302 | } | 300 | } |
| 303 | .to_event(&keys)?; | 301 | .to_event(&signer) |
| 302 | .await?; | ||
| 303 | |||
| 304 | client.set_signer(signer).await; | ||
| 304 | 305 | ||
| 305 | send_events( | 306 | send_events( |
| 306 | &client, | 307 | &client, |
diff --git a/src/sub_commands/push.rs b/src/sub_commands/push.rs index ade2ff8..92c1c18 100644 --- a/src/sub_commands/push.rs +++ b/src/sub_commands/push.rs | |||
| @@ -148,7 +148,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 148 | ahead.len() | 148 | ahead.len() |
| 149 | ); | 149 | ); |
| 150 | 150 | ||
| 151 | let (keys, user_ref) = login::launch( | 151 | let (signer, user_ref) = login::launch( |
| 152 | &git_repo, | 152 | &git_repo, |
| 153 | &cli_args.nsec, | 153 | &cli_args.nsec, |
| 154 | &cli_args.password, | 154 | &cli_args.password, |
| @@ -157,8 +157,6 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 157 | ) | 157 | ) |
| 158 | .await?; | 158 | .await?; |
| 159 | 159 | ||
| 160 | client.set_keys(&keys).await; | ||
| 161 | |||
| 162 | let mut patch_events: Vec<nostr::Event> = vec![]; | 160 | let mut patch_events: Vec<nostr::Event> = vec![]; |
| 163 | for commit in &ahead { | 161 | for commit in &ahead { |
| 164 | patch_events.push( | 162 | patch_events.push( |
| @@ -167,7 +165,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 167 | &root_commit, | 165 | &root_commit, |
| 168 | commit, | 166 | commit, |
| 169 | Some(proposal_root_event.id), | 167 | Some(proposal_root_event.id), |
| 170 | &keys, | 168 | &signer, |
| 171 | &repo_ref, | 169 | &repo_ref, |
| 172 | patch_events.last().map(nostr::Event::id), | 170 | patch_events.last().map(nostr::Event::id), |
| 173 | None, | 171 | None, |
| @@ -175,11 +173,14 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 175 | &None, | 173 | &None, |
| 176 | &[], | 174 | &[], |
| 177 | ) | 175 | ) |
| 176 | .await | ||
| 178 | .context("cannot make patch event from commit")?, | 177 | .context("cannot make patch event from commit")?, |
| 179 | ); | 178 | ); |
| 180 | } | 179 | } |
| 181 | println!("pushing {} commits", ahead.len()); | 180 | println!("pushing {} commits", ahead.len()); |
| 182 | 181 | ||
| 182 | client.set_signer(signer).await; | ||
| 183 | |||
| 183 | send_events( | 184 | send_events( |
| 184 | &client, | 185 | &client, |
| 185 | patch_events, | 186 | patch_events, |
diff --git a/src/sub_commands/send.rs b/src/sub_commands/send.rs index 8971d8b..1d20e90 100644 --- a/src/sub_commands/send.rs +++ b/src/sub_commands/send.rs | |||
| @@ -8,7 +8,7 @@ use nostr::{ | |||
| 8 | nips::{nip01::Coordinate, nip10::Marker, nip19::Nip19}, | 8 | nips::{nip01::Coordinate, nip10::Marker, nip19::Nip19}, |
| 9 | EventBuilder, FromBech32, Tag, TagKind, ToBech32, UncheckedUrl, | 9 | EventBuilder, FromBech32, Tag, TagKind, ToBech32, UncheckedUrl, |
| 10 | }; | 10 | }; |
| 11 | use nostr_sdk::{hashes::sha1::Hash as Sha1Hash, TagStandard}; | 11 | use nostr_sdk::{hashes::sha1::Hash as Sha1Hash, NostrSigner, TagStandard}; |
| 12 | 12 | ||
| 13 | use super::list::tag_value; | 13 | use super::list::tag_value; |
| 14 | #[cfg(not(test))] | 14 | #[cfg(not(test))] |
| @@ -178,7 +178,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 178 | } else { | 178 | } else { |
| 179 | None | 179 | None |
| 180 | }; | 180 | }; |
| 181 | let (keys, user_ref) = login::launch( | 181 | let (signer, user_ref) = login::launch( |
| 182 | &git_repo, | 182 | &git_repo, |
| 183 | &cli_args.nsec, | 183 | &cli_args.nsec, |
| 184 | &cli_args.password, | 184 | &cli_args.password, |
| @@ -187,7 +187,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 187 | ) | 187 | ) |
| 188 | .await?; | 188 | .await?; |
| 189 | 189 | ||
| 190 | client.set_keys(&keys).await; | 190 | client.set_signer(signer.clone()).await; |
| 191 | 191 | ||
| 192 | let repo_ref = repo_ref::fetch( | 192 | let repo_ref = repo_ref::fetch( |
| 193 | &git_repo, | 193 | &git_repo, |
| @@ -208,11 +208,12 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 208 | cover_letter_title_description.clone(), | 208 | cover_letter_title_description.clone(), |
| 209 | &git_repo, | 209 | &git_repo, |
| 210 | &commits, | 210 | &commits, |
| 211 | &keys, | 211 | &signer, |
| 212 | &repo_ref, | 212 | &repo_ref, |
| 213 | &root_proposal_id, | 213 | &root_proposal_id, |
| 214 | &mention_tags, | 214 | &mention_tags, |
| 215 | )?; | 215 | ) |
| 216 | .await?; | ||
| 216 | 217 | ||
| 217 | println!( | 218 | println!( |
| 218 | "posting {} patch{} {} a covering letter...", | 219 | "posting {} patch{} {} a covering letter...", |
| @@ -576,11 +577,11 @@ async fn get_root_proposal_id_and_mentions_from_in_reply_to( | |||
| 576 | pub static PATCH_KIND: u16 = 1617; | 577 | pub static PATCH_KIND: u16 = 1617; |
| 577 | 578 | ||
| 578 | #[allow(clippy::too_many_lines)] | 579 | #[allow(clippy::too_many_lines)] |
| 579 | pub fn generate_cover_letter_and_patch_events( | 580 | pub async fn generate_cover_letter_and_patch_events( |
| 580 | cover_letter_title_description: Option<(String, String)>, | 581 | cover_letter_title_description: Option<(String, String)>, |
| 581 | git_repo: &Repo, | 582 | git_repo: &Repo, |
| 582 | commits: &[Sha1Hash], | 583 | commits: &[Sha1Hash], |
| 583 | keys: &nostr::Keys, | 584 | signer: &NostrSigner, |
| 584 | repo_ref: &RepoRef, | 585 | repo_ref: &RepoRef, |
| 585 | root_proposal_id: &Option<String>, | 586 | root_proposal_id: &Option<String>, |
| 586 | mentions: &[nostr::Tag], | 587 | mentions: &[nostr::Tag], |
| @@ -592,7 +593,7 @@ pub fn generate_cover_letter_and_patch_events( | |||
| 592 | let mut events = vec![]; | 593 | let mut events = vec![]; |
| 593 | 594 | ||
| 594 | if let Some((title, description)) = cover_letter_title_description { | 595 | if let Some((title, description)) = cover_letter_title_description { |
| 595 | events.push(EventBuilder::new( | 596 | events.push(signer.sign_event_builder(EventBuilder::new( |
| 596 | nostr::event::Kind::Custom(PATCH_KIND), | 597 | nostr::event::Kind::Custom(PATCH_KIND), |
| 597 | format!( | 598 | format!( |
| 598 | "From {} Mon Sep 17 00:00:00 2001\nSubject: [PATCH 0/{}] {title}\n\n{description}", | 599 | "From {} Mon Sep 17 00:00:00 2001\nSubject: [PATCH 0/{}] {title}\n\n{description}", |
| @@ -655,8 +656,7 @@ pub fn generate_cover_letter_and_patch_events( | |||
| 655 | .map(|pk| Tag::public_key(*pk)) | 656 | .map(|pk| Tag::public_key(*pk)) |
| 656 | .collect(), | 657 | .collect(), |
| 657 | ].concat(), | 658 | ].concat(), |
| 658 | ) | 659 | )).await |
| 659 | .to_event(keys) | ||
| 660 | .context("failed to create cover-letter event")?); | 660 | .context("failed to create cover-letter event")?); |
| 661 | } | 661 | } |
| 662 | 662 | ||
| @@ -667,7 +667,7 @@ pub fn generate_cover_letter_and_patch_events( | |||
| 667 | &root_commit, | 667 | &root_commit, |
| 668 | commit, | 668 | commit, |
| 669 | events.first().map(|event| event.id), | 669 | events.first().map(|event| event.id), |
| 670 | keys, | 670 | signer, |
| 671 | repo_ref, | 671 | repo_ref, |
| 672 | events.last().map(nostr::Event::id), | 672 | events.last().map(nostr::Event::id), |
| 673 | if events.is_empty() { | 673 | if events.is_empty() { |
| @@ -695,6 +695,7 @@ pub fn generate_cover_letter_and_patch_events( | |||
| 695 | root_proposal_id, | 695 | root_proposal_id, |
| 696 | if events.is_empty() { mentions } else { &[] }, | 696 | if events.is_empty() { mentions } else { &[] }, |
| 697 | ) | 697 | ) |
| 698 | .await | ||
| 698 | .context("failed to generate patch event")?, | 699 | .context("failed to generate patch event")?, |
| 699 | ); | 700 | ); |
| 700 | } | 701 | } |
| @@ -864,12 +865,12 @@ pub fn patch_supports_commit_ids(event: &nostr::Event) -> bool { | |||
| 864 | 865 | ||
| 865 | #[allow(clippy::too_many_arguments)] | 866 | #[allow(clippy::too_many_arguments)] |
| 866 | #[allow(clippy::too_many_lines)] | 867 | #[allow(clippy::too_many_lines)] |
| 867 | pub fn generate_patch_event( | 868 | pub async fn generate_patch_event( |
| 868 | git_repo: &Repo, | 869 | git_repo: &Repo, |
| 869 | root_commit: &Sha1Hash, | 870 | root_commit: &Sha1Hash, |
| 870 | commit: &Sha1Hash, | 871 | commit: &Sha1Hash, |
| 871 | thread_event_id: Option<nostr::EventId>, | 872 | thread_event_id: Option<nostr::EventId>, |
| 872 | keys: &nostr::Keys, | 873 | signer: &nostr_sdk::NostrSigner, |
| 873 | repo_ref: &RepoRef, | 874 | repo_ref: &RepoRef, |
| 874 | parent_patch_event_id: Option<nostr::EventId>, | 875 | parent_patch_event_id: Option<nostr::EventId>, |
| 875 | series_count: Option<(u64, u64)>, | 876 | series_count: Option<(u64, u64)>, |
| @@ -882,7 +883,7 @@ pub fn generate_patch_event( | |||
| 882 | .context("failed to get parent commit")?; | 883 | .context("failed to get parent commit")?; |
| 883 | let relay_hint = repo_ref.relays.first().map(nostr::UncheckedUrl::from); | 884 | let relay_hint = repo_ref.relays.first().map(nostr::UncheckedUrl::from); |
| 884 | 885 | ||
| 885 | EventBuilder::new( | 886 | signer.sign_event_builder(EventBuilder::new( |
| 886 | nostr::event::Kind::Custom(PATCH_KIND), | 887 | nostr::event::Kind::Custom(PATCH_KIND), |
| 887 | git_repo | 888 | git_repo |
| 888 | .make_patch_from_commit(commit,&series_count) | 889 | .make_patch_from_commit(commit,&series_count) |
| @@ -999,8 +1000,7 @@ pub fn generate_patch_event( | |||
| 999 | ], | 1000 | ], |
| 1000 | ] | 1001 | ] |
| 1001 | .concat(), | 1002 | .concat(), |
| 1002 | ) | 1003 | )).await |
| 1003 | .to_event(keys) | ||
| 1004 | .context("failed to sign event") | 1004 | .context("failed to sign event") |
| 1005 | } | 1005 | } |
| 1006 | // TODO | 1006 | // TODO |