Skip to content

Commit

Permalink
feat!: nip34 set pr kind to patch kind
Browse files Browse the repository at this point in the history
this enables consistancy of display with simple clients that are just taking
the output of `git format-patch`
  • Loading branch information
DanConwayDev committed Feb 13, 2024
1 parent 2d6800b commit 1022344
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 19 deletions.
15 changes: 9 additions & 6 deletions src/sub_commands/prs/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,6 @@ mod tests_unique_and_duplicate {
}
}

pub static PR_KIND: u64 = 318;
pub static PATCH_KIND: u64 = 1617;

pub fn generate_pr_and_patch_events(
Expand All @@ -367,7 +366,7 @@ pub fn generate_pr_and_patch_events(

if let Some((title, description)) = cover_letter_title_description {
events.push(EventBuilder::new(
nostr::event::Kind::Custom(PR_KIND),
nostr::event::Kind::Custom(PATCH_KIND),
format!(
"From {} Mon Sep 17 00:00:00 2001\nSubject: [PATCH 0/{}] {title}\n\n{description}",
commits.last().unwrap(),
Expand Down Expand Up @@ -444,7 +443,12 @@ pub struct CoverLetter {
}

pub fn event_is_cover_letter(event: &nostr::Event) -> bool {
event.kind.as_u64().eq(&PR_KIND) && event.iter_tags().any(|t| t.as_vec()[1].eq("cover-letter"))
// TODO: look for Subject:[ PATCH 0/n ] but watch out for:
// [PATCH v1 0/n ] or
// [PATCH subsystem v2 0/n ]
event.kind.as_u64().eq(&PATCH_KIND)
&& event.iter_tags().any(|t| t.as_vec()[1].eq("root"))
&& event.iter_tags().any(|t| t.as_vec()[1].eq("cover-letter"))
}
pub fn event_to_cover_letter(event: &nostr::Event) -> Result<CoverLetter> {
if !event_is_patch_set_root(event) {
Expand Down Expand Up @@ -502,8 +506,7 @@ pub fn event_to_cover_letter(event: &nostr::Event) -> Result<CoverLetter> {
}

pub fn event_is_patch_set_root(event: &nostr::Event) -> bool {
(event.kind.as_u64().eq(&PR_KIND) || event.kind.as_u64().eq(&PATCH_KIND))
&& event.iter_tags().any(|t| t.as_vec()[1].eq("root"))
event.kind.as_u64().eq(&PATCH_KIND) && event.iter_tags().any(|t| t.as_vec()[1].eq("root"))
}

#[allow(clippy::too_many_arguments)]
Expand Down Expand Up @@ -848,7 +851,7 @@ mod tests {

fn generate_cover_letter(title: &str, description: &str) -> Result<nostr::Event> {
Ok(nostr::event::EventBuilder::new(
nostr::event::Kind::Custom(PR_KIND),
nostr::event::Kind::Custom(PATCH_KIND),
format!("From ea897e987ea9a7a98e7a987e97987ea98e7a3334 Mon Sep 17 00:00:00 2001\nSubject: [PATCH 0/2] {title}\n\n{description}"),
[
Tag::Hashtag("cover-letter".to_string()),
Expand Down
14 changes: 3 additions & 11 deletions src/sub_commands/prs/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ use crate::{
client::Connect,
git::{Repo, RepoActions},
repo_ref::{self, RepoRef, REPO_REF_KIND},
sub_commands::prs::create::{
event_is_cover_letter, event_to_cover_letter, PATCH_KIND, PR_KIND,
},
sub_commands::prs::create::{event_is_cover_letter, event_to_cover_letter, PATCH_KIND},
Cli,
};

Expand Down Expand Up @@ -195,10 +193,7 @@ pub async fn find_pr_events(
repo_ref.relays.clone(),
vec![
nostr::Filter::default()
.kinds(vec![
nostr::Kind::Custom(PR_KIND),
nostr::Kind::Custom(PATCH_KIND),
])
.kind(nostr::Kind::Custom(PATCH_KIND))
.custom_tag(nostr::Alphabet::T, vec!["root"])
.identifiers(
repo_ref
Expand All @@ -208,10 +203,7 @@ pub async fn find_pr_events(
),
// also pick up prs from the same repo but no target at our maintainers repo events
nostr::Filter::default()
.kinds(vec![
nostr::Kind::Custom(PR_KIND),
nostr::Kind::Custom(PATCH_KIND),
])
.kind(nostr::Kind::Custom(PATCH_KIND))
.custom_tag(nostr::Alphabet::T, vec!["root"])
.reference(root_commit),
],
Expand Down
1 change: 0 additions & 1 deletion test_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use strip_ansi_escapes::strip_str;
pub mod git;
pub mod relay;

pub static PR_KIND: u64 = 318;
pub static PATCH_KIND: u64 = 1617;
pub static REPOSITORY_KIND: u64 = 30617;

Expand Down
3 changes: 2 additions & 1 deletion tests/prs_create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ fn cli_message_creating_patches() -> Result<()> {
}

fn is_cover_letter(event: &nostr::Event) -> bool {
event.kind.as_u64().eq(&PR_KIND) && event.iter_tags().any(|t| t.as_vec()[1].eq("cover-letter"))
event.kind.as_u64().eq(&PATCH_KIND)
&& event.iter_tags().any(|t| t.as_vec()[1].eq("cover-letter"))
}

fn is_patch(event: &nostr::Event) -> bool {
Expand Down

0 comments on commit 1022344

Please sign in to comment.