diff options
Diffstat (limited to 'src/bin/ngit/sub_commands/label.rs')
| -rw-r--r-- | src/bin/ngit/sub_commands/label.rs | 22 |
1 files changed, 6 insertions, 16 deletions
diff --git a/src/bin/ngit/sub_commands/label.rs b/src/bin/ngit/sub_commands/label.rs index 634e0b5..f6714ae 100644 --- a/src/bin/ngit/sub_commands/label.rs +++ b/src/bin/ngit/sub_commands/label.rs | |||
| @@ -3,14 +3,13 @@ use ngit::{ | |||
| 3 | client::{Params, get_issues_from_cache, get_proposals_and_revisions_from_cache, send_events}, | 3 | client::{Params, get_issues_from_cache, get_proposals_and_revisions_from_cache, send_events}, |
| 4 | git_events::{KIND_LABEL, get_labels}, | 4 | git_events::{KIND_LABEL, get_labels}, |
| 5 | }; | 5 | }; |
| 6 | use nostr::{EventBuilder, Tag, TagStandard}; | 6 | use nostr::{EventBuilder, Tag, TagStandard, nips::nip19::Nip19}; |
| 7 | use nostr_sdk::{EventId, FromBech32}; | 7 | use nostr_sdk::{EventId, FromBech32}; |
| 8 | use nostr::nips::nip19::Nip19; | ||
| 9 | 8 | ||
| 10 | use crate::{ | 9 | use crate::{ |
| 11 | client::{ | 10 | client::{ |
| 12 | Client, Connect, fetching_with_report, get_events_from_local_cache, get_repo_ref_from_cache, | 11 | Client, Connect, fetching_with_report, get_events_from_local_cache, |
| 13 | save_event_in_local_cache, | 12 | get_repo_ref_from_cache, save_event_in_local_cache, |
| 14 | }, | 13 | }, |
| 15 | git::{Repo, RepoActions}, | 14 | git::{Repo, RepoActions}, |
| 16 | login, | 15 | login, |
| @@ -90,19 +89,13 @@ async fn publish_label_event( | |||
| 90 | 89 | ||
| 91 | // Permission check: only the author or a maintainer may label. | 90 | // Permission check: only the author or a maintainer may label. |
| 92 | if target.pubkey != user_pubkey && !repo_ref.maintainers.contains(&user_pubkey) { | 91 | if target.pubkey != user_pubkey && !repo_ref.maintainers.contains(&user_pubkey) { |
| 93 | bail!( | 92 | bail!("only the {target_kind} author or a repository maintainer can label a {target_kind}"); |
| 94 | "only the {target_kind} author or a repository maintainer can label a {target_kind}" | ||
| 95 | ); | ||
| 96 | } | 93 | } |
| 97 | 94 | ||
| 98 | // Fetch existing label events so we can warn about duplicates. | 95 | // Fetch existing label events so we can warn about duplicates. |
| 99 | let existing_label_events = get_events_from_local_cache( | 96 | let existing_label_events = get_events_from_local_cache( |
| 100 | git_repo_path, | 97 | git_repo_path, |
| 101 | vec![ | 98 | vec![nostr::Filter::default().event(event_id).kind(KIND_LABEL)], |
| 102 | nostr::Filter::default() | ||
| 103 | .event(event_id) | ||
| 104 | .kind(KIND_LABEL), | ||
| 105 | ], | ||
| 106 | ) | 99 | ) |
| 107 | .await?; | 100 | .await?; |
| 108 | 101 | ||
| @@ -117,10 +110,7 @@ async fn publish_label_event( | |||
| 117 | .collect(); | 110 | .collect(); |
| 118 | 111 | ||
| 119 | if new_labels.is_empty() { | 112 | if new_labels.is_empty() { |
| 120 | let already: Vec<String> = labels | 113 | let already: Vec<String> = labels.iter().map(|l| format!("#{}", l.trim())).collect(); |
| 121 | .iter() | ||
| 122 | .map(|l| format!("#{}", l.trim())) | ||
| 123 | .collect(); | ||
| 124 | println!( | 114 | println!( |
| 125 | "{target_kind} already has label{}: {}", | 115 | "{target_kind} already has label{}: {}", |
| 126 | if already.len() == 1 { "" } else { "s" }, | 116 | if already.len() == 1 { "" } else { "s" }, |