upleb.uk

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

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/sub_commands/prs/create.rs15
-rw-r--r--src/sub_commands/prs/list.rs14
-rw-r--r--test_utils/src/lib.rs1
-rw-r--r--tests/prs_create.rs3
4 files changed, 14 insertions, 19 deletions
diff --git a/src/sub_commands/prs/create.rs b/src/sub_commands/prs/create.rs
index e5a7c1e..35e29d3 100644
--- a/src/sub_commands/prs/create.rs
+++ b/src/sub_commands/prs/create.rs
@@ -349,7 +349,6 @@ mod tests_unique_and_duplicate {
349 } 349 }
350} 350}
351 351
352pub static PR_KIND: u64 = 318;
353pub static PATCH_KIND: u64 = 1617; 352pub static PATCH_KIND: u64 = 1617;
354 353
355pub fn generate_pr_and_patch_events( 354pub fn generate_pr_and_patch_events(
@@ -367,7 +366,7 @@ pub fn generate_pr_and_patch_events(
367 366
368 if let Some((title, description)) = cover_letter_title_description { 367 if let Some((title, description)) = cover_letter_title_description {
369 events.push(EventBuilder::new( 368 events.push(EventBuilder::new(
370 nostr::event::Kind::Custom(PR_KIND), 369 nostr::event::Kind::Custom(PATCH_KIND),
371 format!( 370 format!(
372 "From {} Mon Sep 17 00:00:00 2001\nSubject: [PATCH 0/{}] {title}\n\n{description}", 371 "From {} Mon Sep 17 00:00:00 2001\nSubject: [PATCH 0/{}] {title}\n\n{description}",
373 commits.last().unwrap(), 372 commits.last().unwrap(),
@@ -444,7 +443,12 @@ pub struct CoverLetter {
444} 443}
445 444
446pub fn event_is_cover_letter(event: &nostr::Event) -> bool { 445pub fn event_is_cover_letter(event: &nostr::Event) -> bool {
447 event.kind.as_u64().eq(&PR_KIND) && event.iter_tags().any(|t| t.as_vec()[1].eq("cover-letter")) 446 // TODO: look for Subject:[ PATCH 0/n ] but watch out for:
447 // [PATCH v1 0/n ] or
448 // [PATCH subsystem v2 0/n ]
449 event.kind.as_u64().eq(&PATCH_KIND)
450 && event.iter_tags().any(|t| t.as_vec()[1].eq("root"))
451 && event.iter_tags().any(|t| t.as_vec()[1].eq("cover-letter"))
448} 452}
449pub fn event_to_cover_letter(event: &nostr::Event) -> Result<CoverLetter> { 453pub fn event_to_cover_letter(event: &nostr::Event) -> Result<CoverLetter> {
450 if !event_is_patch_set_root(event) { 454 if !event_is_patch_set_root(event) {
@@ -502,8 +506,7 @@ pub fn event_to_cover_letter(event: &nostr::Event) -> Result<CoverLetter> {
502} 506}
503 507
504pub fn event_is_patch_set_root(event: &nostr::Event) -> bool { 508pub fn event_is_patch_set_root(event: &nostr::Event) -> bool {
505 (event.kind.as_u64().eq(&PR_KIND) || event.kind.as_u64().eq(&PATCH_KIND)) 509 event.kind.as_u64().eq(&PATCH_KIND) && event.iter_tags().any(|t| t.as_vec()[1].eq("root"))
506 && event.iter_tags().any(|t| t.as_vec()[1].eq("root"))
507} 510}
508 511
509#[allow(clippy::too_many_arguments)] 512#[allow(clippy::too_many_arguments)]
@@ -848,7 +851,7 @@ mod tests {
848 851
849 fn generate_cover_letter(title: &str, description: &str) -> Result<nostr::Event> { 852 fn generate_cover_letter(title: &str, description: &str) -> Result<nostr::Event> {
850 Ok(nostr::event::EventBuilder::new( 853 Ok(nostr::event::EventBuilder::new(
851 nostr::event::Kind::Custom(PR_KIND), 854 nostr::event::Kind::Custom(PATCH_KIND),
852 format!("From ea897e987ea9a7a98e7a987e97987ea98e7a3334 Mon Sep 17 00:00:00 2001\nSubject: [PATCH 0/2] {title}\n\n{description}"), 855 format!("From ea897e987ea9a7a98e7a987e97987ea98e7a3334 Mon Sep 17 00:00:00 2001\nSubject: [PATCH 0/2] {title}\n\n{description}"),
853 [ 856 [
854 Tag::Hashtag("cover-letter".to_string()), 857 Tag::Hashtag("cover-letter".to_string()),
diff --git a/src/sub_commands/prs/list.rs b/src/sub_commands/prs/list.rs
index 36cbd02..d4dcfec 100644
--- a/src/sub_commands/prs/list.rs
+++ b/src/sub_commands/prs/list.rs
@@ -10,9 +10,7 @@ use crate::{
10 client::Connect, 10 client::Connect,
11 git::{Repo, RepoActions}, 11 git::{Repo, RepoActions},
12 repo_ref::{self, RepoRef, REPO_REF_KIND}, 12 repo_ref::{self, RepoRef, REPO_REF_KIND},
13 sub_commands::prs::create::{ 13 sub_commands::prs::create::{event_is_cover_letter, event_to_cover_letter, PATCH_KIND},
14 event_is_cover_letter, event_to_cover_letter, PATCH_KIND, PR_KIND,
15 },
16 Cli, 14 Cli,
17}; 15};
18 16
@@ -195,10 +193,7 @@ pub async fn find_pr_events(
195 repo_ref.relays.clone(), 193 repo_ref.relays.clone(),
196 vec![ 194 vec![
197 nostr::Filter::default() 195 nostr::Filter::default()
198 .kinds(vec![ 196 .kind(nostr::Kind::Custom(PATCH_KIND))
199 nostr::Kind::Custom(PR_KIND),
200 nostr::Kind::Custom(PATCH_KIND),
201 ])
202 .custom_tag(nostr::Alphabet::T, vec!["root"]) 197 .custom_tag(nostr::Alphabet::T, vec!["root"])
203 .identifiers( 198 .identifiers(
204 repo_ref 199 repo_ref
@@ -208,10 +203,7 @@ pub async fn find_pr_events(
208 ), 203 ),
209 // also pick up prs from the same repo but no target at our maintainers repo events 204 // also pick up prs from the same repo but no target at our maintainers repo events
210 nostr::Filter::default() 205 nostr::Filter::default()
211 .kinds(vec![ 206 .kind(nostr::Kind::Custom(PATCH_KIND))
212 nostr::Kind::Custom(PR_KIND),
213 nostr::Kind::Custom(PATCH_KIND),
214 ])
215 .custom_tag(nostr::Alphabet::T, vec!["root"]) 207 .custom_tag(nostr::Alphabet::T, vec!["root"])
216 .reference(root_commit), 208 .reference(root_commit),
217 ], 209 ],
diff --git a/test_utils/src/lib.rs b/test_utils/src/lib.rs
index 0e34983..089b052 100644
--- a/test_utils/src/lib.rs
+++ b/test_utils/src/lib.rs
@@ -11,7 +11,6 @@ use strip_ansi_escapes::strip_str;
11pub mod git; 11pub mod git;
12pub mod relay; 12pub mod relay;
13 13
14pub static PR_KIND: u64 = 318;
15pub static PATCH_KIND: u64 = 1617; 14pub static PATCH_KIND: u64 = 1617;
16pub static REPOSITORY_KIND: u64 = 30617; 15pub static REPOSITORY_KIND: u64 = 30617;
17 16
diff --git a/tests/prs_create.rs b/tests/prs_create.rs
index 316c9fe..5d55ab9 100644
--- a/tests/prs_create.rs
+++ b/tests/prs_create.rs
@@ -143,7 +143,8 @@ fn cli_message_creating_patches() -> Result<()> {
143} 143}
144 144
145fn is_cover_letter(event: &nostr::Event) -> bool { 145fn is_cover_letter(event: &nostr::Event) -> bool {
146 event.kind.as_u64().eq(&PR_KIND) && event.iter_tags().any(|t| t.as_vec()[1].eq("cover-letter")) 146 event.kind.as_u64().eq(&PATCH_KIND)
147 && event.iter_tags().any(|t| t.as_vec()[1].eq("cover-letter"))
147} 148}
148 149
149fn is_patch(event: &nostr::Event) -> bool { 150fn is_patch(event: &nostr::Event) -> bool {