From 79f55ad6488ddb628438580acf54a1d23a990cb3 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Mon, 2 Dec 2024 08:39:25 +0000 Subject: feat: limit `pr` branch names to 60 chars there needs to a limit so the total length of the ref name is < 252 keeping it shorter makes it easier for other contributors to work with --- src/lib/git_events.rs | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'src/lib/git_events.rs') diff --git a/src/lib/git_events.rs b/src/lib/git_events.rs index c4d6770..10194bb 100644 --- a/src/lib/git_events.rs +++ b/src/lib/git_events.rs @@ -178,7 +178,7 @@ pub async fn generate_patch_event( if thread_event_id.is_none() { vec![Tag::custom( TagKind::Custom(std::borrow::Cow::Borrowed("branch-name")), - vec![branch_name.to_string()], + vec![branch_name.chars().take(60).collect::()], )] } else { vec![] @@ -380,7 +380,7 @@ pub async fn generate_cover_letter_and_patch_events( branch_name.to_string() } else { branch_name - }], + }.chars().take(60).collect::()], ), ] } @@ -419,11 +419,16 @@ pub async fn generate_cover_letter_and_patch_events( && !branch_name.eq("origin/main") && !branch_name.eq("origin/master") { - Some(if let Some(branch_name) = branch_name.strip_prefix("pr/") { - branch_name.to_string() - } else { - branch_name - }) + Some( + if let Some(branch_name) = branch_name.strip_prefix("pr/") { + branch_name.to_string() + } else { + branch_name + } + .chars() + .take(60) + .collect::(), + ) } else { None } @@ -514,7 +519,7 @@ pub fn event_to_cover_letter(event: &nostr::Event) -> Result { branch_name: if let Ok(name) = match tag_value(event, "branch-name") { Ok(name) => { if !name.eq("main") && !name.eq("master") { - Ok(name) + Ok(name.chars().take(60).collect::()) } else { Err(()) } @@ -535,7 +540,10 @@ pub fn event_to_cover_letter(event: &nostr::Event) -> Result { }) .collect(); s - }, + } + .chars() + .take(60) + .collect(), event_id: Some(event.id), }) } -- cgit v1.2.3