diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/client.rs | 26 | ||||
| -rw-r--r-- | src/repo_ref.rs | 16 | ||||
| -rw-r--r-- | src/sub_commands/init.rs | 4 | ||||
| -rw-r--r-- | src/sub_commands/list.rs | 69 | ||||
| -rw-r--r-- | src/sub_commands/send.rs | 30 |
5 files changed, 67 insertions, 78 deletions
diff --git a/src/client.rs b/src/client.rs index 29d390f..5603014 100644 --- a/src/client.rs +++ b/src/client.rs | |||
| @@ -36,10 +36,10 @@ use nostr_sqlite::SQLiteDatabase; | |||
| 36 | use crate::{ | 36 | use crate::{ |
| 37 | config::get_dirs, | 37 | config::get_dirs, |
| 38 | login::{get_logged_in_user, get_user_ref_from_cache}, | 38 | login::{get_logged_in_user, get_user_ref_from_cache}, |
| 39 | repo_ref::{RepoRef, REPO_REF_KIND}, | 39 | repo_ref::RepoRef, |
| 40 | sub_commands::{ | 40 | sub_commands::{ |
| 41 | list::status_kinds, | 41 | list::status_kinds, |
| 42 | send::{event_is_patch_set_root, event_is_revision_root, PATCH_KIND}, | 42 | send::{event_is_patch_set_root, event_is_revision_root}, |
| 43 | }, | 43 | }, |
| 44 | }; | 44 | }; |
| 45 | 45 | ||
| @@ -212,7 +212,7 @@ impl Connect for Client { | |||
| 212 | }); | 212 | }); |
| 213 | } | 213 | } |
| 214 | save_event_in_cache(git_repo_path, &event).await?; | 214 | save_event_in_cache(git_repo_path, &event).await?; |
| 215 | if event.kind().eq(&Kind::Custom(REPO_REF_KIND)) { | 215 | if event.kind().eq(&Kind::GitRepoAnnouncement) { |
| 216 | save_event_in_global_cache(git_repo_path, &event).await?; | 216 | save_event_in_global_cache(git_repo_path, &event).await?; |
| 217 | } | 217 | } |
| 218 | Ok(event.id()) | 218 | Ok(event.id()) |
| @@ -895,7 +895,7 @@ async fn create_relays_request( | |||
| 895 | git_repo_path, | 895 | git_repo_path, |
| 896 | vec![ | 896 | vec![ |
| 897 | nostr::Filter::default() | 897 | nostr::Filter::default() |
| 898 | .kinds(vec![Kind::Custom(PATCH_KIND)]) | 898 | .kinds(vec![Kind::GitPatch]) |
| 899 | .custom_tag( | 899 | .custom_tag( |
| 900 | SingleLetterTag::lowercase(nostr_sdk::Alphabet::A), | 900 | SingleLetterTag::lowercase(nostr_sdk::Alphabet::A), |
| 901 | repo_coordinates_without_relays | 901 | repo_coordinates_without_relays |
| @@ -1070,7 +1070,7 @@ async fn process_fetched_events( | |||
| 1070 | for event in &events { | 1070 | for event in &events { |
| 1071 | if !request.existing_events.contains(&event.id) { | 1071 | if !request.existing_events.contains(&event.id) { |
| 1072 | save_event_in_cache(git_repo_path, event).await?; | 1072 | save_event_in_cache(git_repo_path, event).await?; |
| 1073 | if event.kind().as_u16().eq(&REPO_REF_KIND) { | 1073 | if event.kind().eq(&Kind::GitRepoAnnouncement) { |
| 1074 | save_event_in_global_cache(git_repo_path, event).await?; | 1074 | save_event_in_global_cache(git_repo_path, event).await?; |
| 1075 | let new_coordinate = !request | 1075 | let new_coordinate = !request |
| 1076 | .repo_coordinates_without_relays | 1076 | .repo_coordinates_without_relays |
| @@ -1172,7 +1172,7 @@ async fn process_fetched_events( | |||
| 1172 | if !request.existing_events.contains(&event.id) | 1172 | if !request.existing_events.contains(&event.id) |
| 1173 | && !event.event_ids().any(|id| report.proposals.contains(id)) | 1173 | && !event.event_ids().any(|id| report.proposals.contains(id)) |
| 1174 | { | 1174 | { |
| 1175 | if event.kind().as_u16() == PATCH_KIND && !event_is_patch_set_root(event) { | 1175 | if event.kind().eq(&Kind::GitPatch) && !event_is_patch_set_root(event) { |
| 1176 | report.commits.insert(event.id); | 1176 | report.commits.insert(event.id); |
| 1177 | } else if status_kinds().contains(&event.kind()) { | 1177 | } else if status_kinds().contains(&event.kind()) { |
| 1178 | report.statuses.insert(event.id); | 1178 | report.statuses.insert(event.id); |
| @@ -1238,7 +1238,7 @@ pub fn get_fetch_filters( | |||
| 1238 | vec![ | 1238 | vec![ |
| 1239 | get_filter_repo_events(repo_coordinates), | 1239 | get_filter_repo_events(repo_coordinates), |
| 1240 | nostr::Filter::default() | 1240 | nostr::Filter::default() |
| 1241 | .kinds(vec![Kind::Custom(PATCH_KIND), Kind::EventDeletion]) | 1241 | .kinds(vec![Kind::GitPatch, Kind::EventDeletion]) |
| 1242 | .custom_tag( | 1242 | .custom_tag( |
| 1243 | SingleLetterTag::lowercase(nostr_sdk::Alphabet::A), | 1243 | SingleLetterTag::lowercase(nostr_sdk::Alphabet::A), |
| 1244 | repo_coordinates | 1244 | repo_coordinates |
| @@ -1252,13 +1252,9 @@ pub fn get_fetch_filters( | |||
| 1252 | vec![] | 1252 | vec![] |
| 1253 | } else { | 1253 | } else { |
| 1254 | vec![ | 1254 | vec![ |
| 1255 | nostr::Filter::default().events(proposal_ids.clone()).kinds( | 1255 | nostr::Filter::default() |
| 1256 | [ | 1256 | .events(proposal_ids.clone()) |
| 1257 | vec![Kind::Custom(PATCH_KIND), Kind::EventDeletion], | 1257 | .kinds([vec![Kind::GitPatch, Kind::EventDeletion], status_kinds()].concat()), |
| 1258 | status_kinds(), | ||
| 1259 | ] | ||
| 1260 | .concat(), | ||
| 1261 | ), | ||
| 1262 | ] | 1258 | ] |
| 1263 | }, | 1259 | }, |
| 1264 | if required_profiles.is_empty() { | 1260 | if required_profiles.is_empty() { |
| @@ -1272,7 +1268,7 @@ pub fn get_fetch_filters( | |||
| 1272 | 1268 | ||
| 1273 | pub fn get_filter_repo_events(repo_coordinates: &HashSet<Coordinate>) -> nostr::Filter { | 1269 | pub fn get_filter_repo_events(repo_coordinates: &HashSet<Coordinate>) -> nostr::Filter { |
| 1274 | nostr::Filter::default() | 1270 | nostr::Filter::default() |
| 1275 | .kind(Kind::Custom(REPO_REF_KIND)) | 1271 | .kind(Kind::GitRepoAnnouncement) |
| 1276 | .identifiers( | 1272 | .identifiers( |
| 1277 | repo_coordinates | 1273 | repo_coordinates |
| 1278 | .iter() | 1274 | .iter() |
diff --git a/src/repo_ref.rs b/src/repo_ref.rs index 0409502..ca196d9 100644 --- a/src/repo_ref.rs +++ b/src/repo_ref.rs | |||
| @@ -37,7 +37,7 @@ impl TryFrom<nostr::Event> for RepoRef { | |||
| 37 | type Error = anyhow::Error; | 37 | type Error = anyhow::Error; |
| 38 | 38 | ||
| 39 | fn try_from(event: nostr::Event) -> Result<Self> { | 39 | fn try_from(event: nostr::Event) -> Result<Self> { |
| 40 | if !event.kind.as_u16().eq(&REPO_REF_KIND) { | 40 | if !event.kind.eq(&Kind::GitRepoAnnouncement) { |
| 41 | bail!("incorrect kind"); | 41 | bail!("incorrect kind"); |
| 42 | } | 42 | } |
| 43 | let mut r = Self::default(); | 43 | let mut r = Self::default(); |
| @@ -107,13 +107,11 @@ impl TryFrom<nostr::Event> for RepoRef { | |||
| 107 | } | 107 | } |
| 108 | } | 108 | } |
| 109 | 109 | ||
| 110 | pub static REPO_REF_KIND: u16 = 30_617; | ||
| 111 | |||
| 112 | impl RepoRef { | 110 | impl RepoRef { |
| 113 | pub async fn to_event(&self, signer: &NostrSigner) -> Result<nostr::Event> { | 111 | pub async fn to_event(&self, signer: &NostrSigner) -> Result<nostr::Event> { |
| 114 | sign_event( | 112 | sign_event( |
| 115 | nostr_sdk::EventBuilder::new( | 113 | nostr_sdk::EventBuilder::new( |
| 116 | nostr::event::Kind::Custom(REPO_REF_KIND), | 114 | nostr::event::Kind::GitRepoAnnouncement, |
| 117 | "", | 115 | "", |
| 118 | [ | 116 | [ |
| 119 | vec![ | 117 | vec![ |
| @@ -179,7 +177,7 @@ impl RepoRef { | |||
| 179 | let mut res = HashSet::new(); | 177 | let mut res = HashSet::new(); |
| 180 | for m in &self.maintainers { | 178 | for m in &self.maintainers { |
| 181 | res.insert(Coordinate { | 179 | res.insert(Coordinate { |
| 182 | kind: Kind::Custom(REPO_REF_KIND), | 180 | kind: Kind::GitRepoAnnouncement, |
| 183 | public_key: *m, | 181 | public_key: *m, |
| 184 | identifier: self.identifier.clone(), | 182 | identifier: self.identifier.clone(), |
| 185 | relays: vec![], | 183 | relays: vec![], |
| @@ -191,7 +189,7 @@ impl RepoRef { | |||
| 191 | /// coordinates without relay hints | 189 | /// coordinates without relay hints |
| 192 | pub fn coordinate_with_hint(&self) -> Coordinate { | 190 | pub fn coordinate_with_hint(&self) -> Coordinate { |
| 193 | Coordinate { | 191 | Coordinate { |
| 194 | kind: Kind::Custom(REPO_REF_KIND), | 192 | kind: Kind::GitRepoAnnouncement, |
| 195 | public_key: *self | 193 | public_key: *self |
| 196 | .maintainers | 194 | .maintainers |
| 197 | .first() | 195 | .first() |
| @@ -256,7 +254,7 @@ pub async fn try_and_get_repo_coordinates( | |||
| 256 | if let Some(identifier) = repo_config.identifier { | 254 | if let Some(identifier) = repo_config.identifier { |
| 257 | for public_key in maintainers { | 255 | for public_key in maintainers { |
| 258 | repo_coordinates.insert(Coordinate { | 256 | repo_coordinates.insert(Coordinate { |
| 259 | kind: Kind::Custom(REPO_REF_KIND), | 257 | kind: Kind::GitRepoAnnouncement, |
| 260 | public_key, | 258 | public_key, |
| 261 | identifier: identifier.clone(), | 259 | identifier: identifier.clone(), |
| 262 | relays: vec![], | 260 | relays: vec![], |
| @@ -283,7 +281,7 @@ pub async fn try_and_get_repo_coordinates( | |||
| 283 | } | 281 | } |
| 284 | // look find all repo refs with root_commit. for identifier | 282 | // look find all repo refs with root_commit. for identifier |
| 285 | let filter = nostr::Filter::default() | 283 | let filter = nostr::Filter::default() |
| 286 | .kind(nostr::Kind::Custom(REPO_REF_KIND)) | 284 | .kind(nostr::Kind::GitRepoAnnouncement) |
| 287 | .reference(git_repo.get_root_commit()?.to_string()) | 285 | .reference(git_repo.get_root_commit()?.to_string()) |
| 288 | .authors(maintainers.clone()); | 286 | .authors(maintainers.clone()); |
| 289 | let mut events = | 287 | let mut events = |
| @@ -306,7 +304,7 @@ pub async fn try_and_get_repo_coordinates( | |||
| 306 | for m in &repo_config.maintainers { | 304 | for m in &repo_config.maintainers { |
| 307 | if let Ok(maintainer) = PublicKey::parse(m) { | 305 | if let Ok(maintainer) = PublicKey::parse(m) { |
| 308 | repo_coordinates.insert(Coordinate { | 306 | repo_coordinates.insert(Coordinate { |
| 309 | kind: Kind::Custom(REPO_REF_KIND), | 307 | kind: Kind::GitRepoAnnouncement, |
| 310 | public_key: maintainer, | 308 | public_key: maintainer, |
| 311 | identifier: identifier.to_string(), | 309 | identifier: identifier.to_string(), |
| 312 | relays: vec![], | 310 | relays: vec![], |
diff --git a/src/sub_commands/init.rs b/src/sub_commands/init.rs index 2a97779..1c51375 100644 --- a/src/sub_commands/init.rs +++ b/src/sub_commands/init.rs | |||
| @@ -16,7 +16,7 @@ use crate::{ | |||
| 16 | login, | 16 | login, |
| 17 | repo_ref::{ | 17 | repo_ref::{ |
| 18 | extract_pks, get_repo_config_from_yaml, save_repo_config_to_yaml, | 18 | extract_pks, get_repo_config_from_yaml, save_repo_config_to_yaml, |
| 19 | try_and_get_repo_coordinates, RepoRef, REPO_REF_KIND, | 19 | try_and_get_repo_coordinates, RepoRef, |
| 20 | }, | 20 | }, |
| 21 | Cli, | 21 | Cli, |
| 22 | }; | 22 | }; |
| @@ -336,7 +336,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 336 | git_repo.save_git_config_item( | 336 | git_repo.save_git_config_item( |
| 337 | "nostr.repo", | 337 | "nostr.repo", |
| 338 | &Coordinate { | 338 | &Coordinate { |
| 339 | kind: Kind::Custom(REPO_REF_KIND), | 339 | kind: Kind::GitRepoAnnouncement, |
| 340 | public_key: user_ref.public_key, | 340 | public_key: user_ref.public_key, |
| 341 | identifier: identifier.clone(), | 341 | identifier: identifier.clone(), |
| 342 | relays: vec![], | 342 | relays: vec![], |
diff --git a/src/sub_commands/list.rs b/src/sub_commands/list.rs index cc7ac6f..73ef107 100644 --- a/src/sub_commands/list.rs +++ b/src/sub_commands/list.rs | |||
| @@ -2,7 +2,7 @@ use std::{collections::HashSet, io::Write, ops::Add, path::Path}; | |||
| 2 | 2 | ||
| 3 | use anyhow::{bail, Context, Result}; | 3 | use anyhow::{bail, Context, Result}; |
| 4 | use nostr::nips::nip01::Coordinate; | 4 | use nostr::nips::nip01::Coordinate; |
| 5 | use nostr_sdk::PublicKey; | 5 | use nostr_sdk::{Kind, PublicKey}; |
| 6 | 6 | ||
| 7 | use super::send::event_is_patch_set_root; | 7 | use super::send::event_is_patch_set_root; |
| 8 | #[cfg(test)] | 8 | #[cfg(test)] |
| @@ -16,7 +16,7 @@ use crate::{ | |||
| 16 | repo_ref::{get_repo_coordinates, RepoRef}, | 16 | repo_ref::{get_repo_coordinates, RepoRef}, |
| 17 | sub_commands::send::{ | 17 | sub_commands::send::{ |
| 18 | commit_msg_from_patch_oneliner, event_is_cover_letter, event_is_revision_root, | 18 | commit_msg_from_patch_oneliner, event_is_cover_letter, event_is_revision_root, |
| 19 | event_to_cover_letter, patch_supports_commit_ids, PATCH_KIND, | 19 | event_to_cover_letter, patch_supports_commit_ids, |
| 20 | }, | 20 | }, |
| 21 | }; | 21 | }; |
| 22 | 22 | ||
| @@ -84,31 +84,31 @@ pub async fn launch() -> Result<()> { | |||
| 84 | .collect::<Vec<&nostr::Event>>() | 84 | .collect::<Vec<&nostr::Event>>() |
| 85 | .first() | 85 | .first() |
| 86 | { | 86 | { |
| 87 | e.kind().as_u16() | 87 | e.kind() |
| 88 | } else { | 88 | } else { |
| 89 | STATUS_KIND_OPEN | 89 | Kind::GitStatusOpen |
| 90 | }; | 90 | }; |
| 91 | if status.eq(&STATUS_KIND_OPEN) { | 91 | if status.eq(&Kind::GitStatusOpen) { |
| 92 | open_proposals.push(proposal); | 92 | open_proposals.push(proposal); |
| 93 | } else if status.eq(&STATUS_KIND_CLOSED) { | 93 | } else if status.eq(&Kind::GitStatusClosed) { |
| 94 | closed_proposals.push(proposal); | 94 | closed_proposals.push(proposal); |
| 95 | } else if status.eq(&STATUS_KIND_DRAFT) { | 95 | } else if status.eq(&Kind::GitStatusDraft) { |
| 96 | draft_proposals.push(proposal); | 96 | draft_proposals.push(proposal); |
| 97 | } else if status.eq(&STATUS_KIND_APPLIED) { | 97 | } else if status.eq(&Kind::GitStatusApplied) { |
| 98 | applied_proposals.push(proposal); | 98 | applied_proposals.push(proposal); |
| 99 | } | 99 | } |
| 100 | } | 100 | } |
| 101 | 101 | ||
| 102 | let mut selected_status = STATUS_KIND_OPEN; | 102 | let mut selected_status = Kind::GitStatusOpen; |
| 103 | 103 | ||
| 104 | loop { | 104 | loop { |
| 105 | let proposals_for_status = if selected_status == STATUS_KIND_OPEN { | 105 | let proposals_for_status = if selected_status == Kind::GitStatusOpen { |
| 106 | &open_proposals | 106 | &open_proposals |
| 107 | } else if selected_status == STATUS_KIND_DRAFT { | 107 | } else if selected_status == Kind::GitStatusDraft { |
| 108 | &draft_proposals | 108 | &draft_proposals |
| 109 | } else if selected_status == STATUS_KIND_CLOSED { | 109 | } else if selected_status == Kind::GitStatusClosed { |
| 110 | &closed_proposals | 110 | &closed_proposals |
| 111 | } else if selected_status == STATUS_KIND_APPLIED { | 111 | } else if selected_status == Kind::GitStatusApplied { |
| 112 | &applied_proposals | 112 | &applied_proposals |
| 113 | } else { | 113 | } else { |
| 114 | &open_proposals | 114 | &open_proposals |
| @@ -116,15 +116,15 @@ pub async fn launch() -> Result<()> { | |||
| 116 | 116 | ||
| 117 | let prompt = if proposals.len().eq(&open_proposals.len()) { | 117 | let prompt = if proposals.len().eq(&open_proposals.len()) { |
| 118 | "all proposals" | 118 | "all proposals" |
| 119 | } else if selected_status == STATUS_KIND_OPEN { | 119 | } else if selected_status == Kind::GitStatusOpen { |
| 120 | if open_proposals.is_empty() { | 120 | if open_proposals.is_empty() { |
| 121 | "proposals menu" | 121 | "proposals menu" |
| 122 | } else { | 122 | } else { |
| 123 | "open proposals" | 123 | "open proposals" |
| 124 | } | 124 | } |
| 125 | } else if selected_status == STATUS_KIND_DRAFT { | 125 | } else if selected_status == Kind::GitStatusDraft { |
| 126 | "draft proposals" | 126 | "draft proposals" |
| 127 | } else if selected_status == STATUS_KIND_CLOSED { | 127 | } else if selected_status == Kind::GitStatusClosed { |
| 128 | "closed proposals" | 128 | "closed proposals" |
| 129 | } else { | 129 | } else { |
| 130 | "applied proposals" | 130 | "applied proposals" |
| @@ -143,16 +143,16 @@ pub async fn launch() -> Result<()> { | |||
| 143 | }) | 143 | }) |
| 144 | .collect(); | 144 | .collect(); |
| 145 | 145 | ||
| 146 | if !selected_status.eq(&STATUS_KIND_OPEN) && open_proposals.len().gt(&0) { | 146 | if !selected_status.eq(&Kind::GitStatusOpen) && open_proposals.len().gt(&0) { |
| 147 | choices.push(format!("({}) Open proposals...", open_proposals.len())); | 147 | choices.push(format!("({}) Open proposals...", open_proposals.len())); |
| 148 | } | 148 | } |
| 149 | if !selected_status.eq(&STATUS_KIND_DRAFT) && draft_proposals.len().gt(&0) { | 149 | if !selected_status.eq(&Kind::GitStatusDraft) && draft_proposals.len().gt(&0) { |
| 150 | choices.push(format!("({}) Draft proposals...", draft_proposals.len())); | 150 | choices.push(format!("({}) Draft proposals...", draft_proposals.len())); |
| 151 | } | 151 | } |
| 152 | if !selected_status.eq(&STATUS_KIND_CLOSED) && closed_proposals.len().gt(&0) { | 152 | if !selected_status.eq(&Kind::GitStatusClosed) && closed_proposals.len().gt(&0) { |
| 153 | choices.push(format!("({}) Closed proposals...", closed_proposals.len())); | 153 | choices.push(format!("({}) Closed proposals...", closed_proposals.len())); |
| 154 | } | 154 | } |
| 155 | if !selected_status.eq(&STATUS_KIND_APPLIED) && applied_proposals.len().gt(&0) { | 155 | if !selected_status.eq(&Kind::GitStatusApplied) && applied_proposals.len().gt(&0) { |
| 156 | choices.push(format!( | 156 | choices.push(format!( |
| 157 | "({}) Applied proposals...", | 157 | "({}) Applied proposals...", |
| 158 | applied_proposals.len() | 158 | applied_proposals.len() |
| @@ -167,13 +167,13 @@ pub async fn launch() -> Result<()> { | |||
| 167 | 167 | ||
| 168 | if (selected_index + 1).gt(&proposals_for_status.len()) { | 168 | if (selected_index + 1).gt(&proposals_for_status.len()) { |
| 169 | if choices[selected_index].contains("Open") { | 169 | if choices[selected_index].contains("Open") { |
| 170 | selected_status = STATUS_KIND_OPEN; | 170 | selected_status = Kind::GitStatusOpen; |
| 171 | } else if choices[selected_index].contains("Draft") { | 171 | } else if choices[selected_index].contains("Draft") { |
| 172 | selected_status = STATUS_KIND_DRAFT; | 172 | selected_status = Kind::GitStatusDraft; |
| 173 | } else if choices[selected_index].contains("Closed") { | 173 | } else if choices[selected_index].contains("Closed") { |
| 174 | selected_status = STATUS_KIND_CLOSED; | 174 | selected_status = Kind::GitStatusClosed; |
| 175 | } else if choices[selected_index].contains("Applied") { | 175 | } else if choices[selected_index].contains("Applied") { |
| 176 | selected_status = STATUS_KIND_APPLIED; | 176 | selected_status = Kind::GitStatusApplied; |
| 177 | } | 177 | } |
| 178 | continue; | 178 | continue; |
| 179 | } | 179 | } |
| @@ -804,17 +804,12 @@ pub fn get_most_recent_patch_with_ancestors( | |||
| 804 | Ok(res) | 804 | Ok(res) |
| 805 | } | 805 | } |
| 806 | 806 | ||
| 807 | pub static STATUS_KIND_OPEN: u16 = 1630; | ||
| 808 | pub static STATUS_KIND_APPLIED: u16 = 1631; | ||
| 809 | pub static STATUS_KIND_CLOSED: u16 = 1632; | ||
| 810 | pub static STATUS_KIND_DRAFT: u16 = 1633; | ||
| 811 | |||
| 812 | pub fn status_kinds() -> Vec<nostr::Kind> { | 807 | pub fn status_kinds() -> Vec<nostr::Kind> { |
| 813 | vec![ | 808 | vec![ |
| 814 | nostr::Kind::Custom(STATUS_KIND_OPEN), | 809 | nostr::Kind::GitStatusOpen, |
| 815 | nostr::Kind::Custom(STATUS_KIND_APPLIED), | 810 | nostr::Kind::GitStatusApplied, |
| 816 | nostr::Kind::Custom(STATUS_KIND_CLOSED), | 811 | nostr::Kind::GitStatusClosed, |
| 817 | nostr::Kind::Custom(STATUS_KIND_DRAFT), | 812 | nostr::Kind::GitStatusDraft, |
| 818 | ] | 813 | ] |
| 819 | } | 814 | } |
| 820 | 815 | ||
| @@ -826,7 +821,7 @@ pub async fn get_proposals_and_revisions_from_cache( | |||
| 826 | git_repo_path, | 821 | git_repo_path, |
| 827 | vec![ | 822 | vec![ |
| 828 | nostr::Filter::default() | 823 | nostr::Filter::default() |
| 829 | .kind(nostr::Kind::Custom(PATCH_KIND)) | 824 | .kind(nostr::Kind::GitPatch) |
| 830 | .custom_tag( | 825 | .custom_tag( |
| 831 | nostr::SingleLetterTag::lowercase(nostr_sdk::Alphabet::A), | 826 | nostr::SingleLetterTag::lowercase(nostr_sdk::Alphabet::A), |
| 832 | repo_coordinates | 827 | repo_coordinates |
| @@ -855,10 +850,10 @@ pub async fn get_all_proposal_patch_events_from_cache( | |||
| 855 | git_repo_path, | 850 | git_repo_path, |
| 856 | vec![ | 851 | vec![ |
| 857 | nostr::Filter::default() | 852 | nostr::Filter::default() |
| 858 | .kind(nostr::Kind::Custom(PATCH_KIND)) | 853 | .kind(nostr::Kind::GitPatch) |
| 859 | .event(*proposal_id), | 854 | .event(*proposal_id), |
| 860 | nostr::Filter::default() | 855 | nostr::Filter::default() |
| 861 | .kind(nostr::Kind::Custom(PATCH_KIND)) | 856 | .kind(nostr::Kind::GitPatch) |
| 862 | .id(*proposal_id), | 857 | .id(*proposal_id), |
| 863 | ], | 858 | ], |
| 864 | ) | 859 | ) |
| @@ -891,7 +886,7 @@ pub async fn get_all_proposal_patch_events_from_cache( | |||
| 891 | git_repo_path, | 886 | git_repo_path, |
| 892 | vec![ | 887 | vec![ |
| 893 | nostr::Filter::default() | 888 | nostr::Filter::default() |
| 894 | .kind(nostr::Kind::Custom(PATCH_KIND)) | 889 | .kind(nostr::Kind::GitPatch) |
| 895 | .events(revision_roots) | 890 | .events(revision_roots) |
| 896 | .authors(permissioned_users.clone()), | 891 | .authors(permissioned_users.clone()), |
| 897 | ], | 892 | ], |
diff --git a/src/sub_commands/send.rs b/src/sub_commands/send.rs index 9733cfe..73c980b 100644 --- a/src/sub_commands/send.rs +++ b/src/sub_commands/send.rs | |||
| @@ -12,7 +12,7 @@ use nostr::{ | |||
| 12 | }, | 12 | }, |
| 13 | EventBuilder, FromBech32, Tag, TagKind, ToBech32, UncheckedUrl, | 13 | EventBuilder, FromBech32, Tag, TagKind, ToBech32, UncheckedUrl, |
| 14 | }; | 14 | }; |
| 15 | use nostr_sdk::{hashes::sha1::Hash as Sha1Hash, NostrSigner, TagStandard}; | 15 | use nostr_sdk::{hashes::sha1::Hash as Sha1Hash, Kind, NostrSigner, TagStandard}; |
| 16 | 16 | ||
| 17 | use super::list::tag_value; | 17 | use super::list::tag_value; |
| 18 | #[cfg(not(test))] | 18 | #[cfg(not(test))] |
| @@ -28,7 +28,7 @@ use crate::{ | |||
| 28 | }, | 28 | }, |
| 29 | git::{Repo, RepoActions}, | 29 | git::{Repo, RepoActions}, |
| 30 | login, | 30 | login, |
| 31 | repo_ref::{get_repo_coordinates, RepoRef, REPO_REF_KIND}, | 31 | repo_ref::{get_repo_coordinates, RepoRef}, |
| 32 | Cli, | 32 | Cli, |
| 33 | }; | 33 | }; |
| 34 | 34 | ||
| @@ -288,7 +288,10 @@ pub async fn send_events( | |||
| 288 | ) -> Result<()> { | 288 | ) -> Result<()> { |
| 289 | let fallback = [ | 289 | let fallback = [ |
| 290 | client.get_fallback_relays().clone(), | 290 | client.get_fallback_relays().clone(), |
| 291 | if events.iter().any(|e| e.kind().as_u16().eq(&REPO_REF_KIND)) { | 291 | if events |
| 292 | .iter() | ||
| 293 | .any(|e| e.kind().eq(&Kind::GitRepoAnnouncement)) | ||
| 294 | { | ||
| 292 | client.get_blaster_relays().clone() | 295 | client.get_blaster_relays().clone() |
| 293 | } else { | 296 | } else { |
| 294 | vec![] | 297 | vec![] |
| @@ -573,8 +576,6 @@ async fn get_root_proposal_id_and_mentions_from_in_reply_to( | |||
| 573 | Ok((root_proposal_id, mention_tags)) | 576 | Ok((root_proposal_id, mention_tags)) |
| 574 | } | 577 | } |
| 575 | 578 | ||
| 576 | pub static PATCH_KIND: u16 = 1617; | ||
| 577 | |||
| 578 | #[allow(clippy::too_many_lines)] | 579 | #[allow(clippy::too_many_lines)] |
| 579 | pub async 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)>, |
| @@ -593,7 +594,7 @@ pub async fn generate_cover_letter_and_patch_events( | |||
| 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(sign_event(EventBuilder::new( | 596 | events.push(sign_event(EventBuilder::new( |
| 596 | nostr::event::Kind::Custom(PATCH_KIND), | 597 | nostr::event::Kind::GitPatch, |
| 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}", |
| 599 | commits.last().unwrap(), | 600 | commits.last().unwrap(), |
| @@ -601,7 +602,7 @@ pub async fn generate_cover_letter_and_patch_events( | |||
| 601 | ), | 602 | ), |
| 602 | [ | 603 | [ |
| 603 | repo_ref.maintainers.iter().map(|m| Tag::coordinate(Coordinate { | 604 | repo_ref.maintainers.iter().map(|m| Tag::coordinate(Coordinate { |
| 604 | kind: nostr::Kind::Custom(REPO_REF_KIND), | 605 | kind: nostr::Kind::GitRepoAnnouncement, |
| 605 | public_key: *m, | 606 | public_key: *m, |
| 606 | identifier: repo_ref.identifier.to_string(), | 607 | identifier: repo_ref.identifier.to_string(), |
| 607 | relays: repo_ref.relays.clone(), | 608 | relays: repo_ref.relays.clone(), |
| @@ -789,7 +790,7 @@ pub fn event_is_cover_letter(event: &nostr::Event) -> bool { | |||
| 789 | // TODO: look for Subject:[ PATCH 0/n ] but watch out for: | 790 | // TODO: look for Subject:[ PATCH 0/n ] but watch out for: |
| 790 | // [PATCH v1 0/n ] or | 791 | // [PATCH v1 0/n ] or |
| 791 | // [PATCH subsystem v2 0/n ] | 792 | // [PATCH subsystem v2 0/n ] |
| 792 | event.kind.as_u16().eq(&PATCH_KIND) | 793 | event.kind.eq(&Kind::GitPatch) |
| 793 | && event.iter_tags().any(|t| t.as_vec()[1].eq("root")) | 794 | && event.iter_tags().any(|t| t.as_vec()[1].eq("root")) |
| 794 | && event.iter_tags().any(|t| t.as_vec()[1].eq("cover-letter")) | 795 | && event.iter_tags().any(|t| t.as_vec()[1].eq("cover-letter")) |
| 795 | } | 796 | } |
| @@ -860,16 +861,15 @@ pub fn event_to_cover_letter(event: &nostr::Event) -> Result<CoverLetter> { | |||
| 860 | } | 861 | } |
| 861 | 862 | ||
| 862 | pub fn event_is_patch_set_root(event: &nostr::Event) -> bool { | 863 | pub fn event_is_patch_set_root(event: &nostr::Event) -> bool { |
| 863 | event.kind.as_u16().eq(&PATCH_KIND) && event.iter_tags().any(|t| t.as_vec()[1].eq("root")) | 864 | event.kind.eq(&Kind::GitPatch) && event.iter_tags().any(|t| t.as_vec()[1].eq("root")) |
| 864 | } | 865 | } |
| 865 | 866 | ||
| 866 | pub fn event_is_revision_root(event: &nostr::Event) -> bool { | 867 | pub fn event_is_revision_root(event: &nostr::Event) -> bool { |
| 867 | event.kind.as_u16().eq(&PATCH_KIND) | 868 | event.kind.eq(&Kind::GitPatch) && event.iter_tags().any(|t| t.as_vec()[1].eq("revision-root")) |
| 868 | && event.iter_tags().any(|t| t.as_vec()[1].eq("revision-root")) | ||
| 869 | } | 869 | } |
| 870 | 870 | ||
| 871 | pub fn patch_supports_commit_ids(event: &nostr::Event) -> bool { | 871 | pub fn patch_supports_commit_ids(event: &nostr::Event) -> bool { |
| 872 | event.kind.as_u16().eq(&PATCH_KIND) | 872 | event.kind.eq(&Kind::GitPatch) |
| 873 | && event | 873 | && event |
| 874 | .iter_tags() | 874 | .iter_tags() |
| 875 | .any(|t| t.as_vec()[0].eq("commit-pgp-sig")) | 875 | .any(|t| t.as_vec()[0].eq("commit-pgp-sig")) |
| @@ -897,7 +897,7 @@ pub async fn generate_patch_event( | |||
| 897 | 897 | ||
| 898 | sign_event( | 898 | sign_event( |
| 899 | EventBuilder::new( | 899 | EventBuilder::new( |
| 900 | nostr::event::Kind::Custom(PATCH_KIND), | 900 | nostr::event::Kind::GitPatch, |
| 901 | git_repo | 901 | git_repo |
| 902 | .make_patch_from_commit(commit, &series_count) | 902 | .make_patch_from_commit(commit, &series_count) |
| 903 | .context(format!("cannot make patch for commit {commit}"))?, | 903 | .context(format!("cannot make patch for commit {commit}"))?, |
| @@ -907,7 +907,7 @@ pub async fn generate_patch_event( | |||
| 907 | .iter() | 907 | .iter() |
| 908 | .map(|m| { | 908 | .map(|m| { |
| 909 | Tag::coordinate(Coordinate { | 909 | Tag::coordinate(Coordinate { |
| 910 | kind: nostr::Kind::Custom(REPO_REF_KIND), | 910 | kind: nostr::Kind::GitRepoAnnouncement, |
| 911 | public_key: *m, | 911 | public_key: *m, |
| 912 | identifier: repo_ref.identifier.to_string(), | 912 | identifier: repo_ref.identifier.to_string(), |
| 913 | relays: repo_ref.relays.clone(), | 913 | relays: repo_ref.relays.clone(), |
| @@ -1238,7 +1238,7 @@ mod tests { | |||
| 1238 | 1238 | ||
| 1239 | fn generate_cover_letter(title: &str, description: &str) -> Result<nostr::Event> { | 1239 | fn generate_cover_letter(title: &str, description: &str) -> Result<nostr::Event> { |
| 1240 | Ok(nostr::event::EventBuilder::new( | 1240 | Ok(nostr::event::EventBuilder::new( |
| 1241 | nostr::event::Kind::Custom(PATCH_KIND), | 1241 | nostr::event::Kind::GitPatch, |
| 1242 | format!("From ea897e987ea9a7a98e7a987e97987ea98e7a3334 Mon Sep 17 00:00:00 2001\nSubject: [PATCH 0/2] {title}\n\n{description}"), | 1242 | format!("From ea897e987ea9a7a98e7a987e97987ea98e7a3334 Mon Sep 17 00:00:00 2001\nSubject: [PATCH 0/2] {title}\n\n{description}"), |
| 1243 | [ | 1243 | [ |
| 1244 | Tag::hashtag("cover-letter"), | 1244 | Tag::hashtag("cover-letter"), |