From 8bb4cf0da499aa6cbc9f0322a358d9d48c64c16c Mon Sep 17 00:00:00 2001
From: Awiteb
Date: Sun, 3 Aug 2025 12:29:07 +0000
Subject: [PATCH] refactor: Move `root` and `root-revision` to constants
Signed-off-by: Awiteb
---
src/cli/commands/patch/mod.rs | 5 +++++
src/cli/commands/patch/send.rs | 8 ++++++--
src/nostr_utils/traits.rs | 5 +++--
3 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/src/cli/commands/patch/mod.rs b/src/cli/commands/patch/mod.rs
index 61176e8..4ac5401 100644
--- a/src/cli/commands/patch/mod.rs
+++ b/src/cli/commands/patch/mod.rs
@@ -68,6 +68,11 @@ static PATCH_VERSION_NUMBER_RE: LazyLock = LazyLock::new(|| {
Regex::new(r"\[PATCH\s+(?:v(?\d+)\s*)?(?\d+)/(?:\d+)").unwrap()
});
+/// Content of the hashtag representing the root patch.
+pub const ROOT_HASHTAG_CONTENT: &str = "root";
+/// Content of the hashtag representing the root revision patch.
+pub const REVISION_ROOT_HASHTAG_CONTENT: &str = "root-revision";
+
#[derive(Subcommand, Debug)]
pub enum PatchSubcommands {
/// Send one or more patches to a repository.
diff --git a/src/cli/commands/patch/send.rs b/src/cli/commands/patch/send.rs
index 9feab2a..25bfa4a 100644
--- a/src/cli/commands/patch/send.rs
+++ b/src/cli/commands/patch/send.rs
@@ -30,6 +30,7 @@ use super::GitPatch;
use crate::{
cli::{
CliOptions,
+ patch::{REVISION_ROOT_HASHTAG_CONTENT, ROOT_HASHTAG_CONTENT},
traits::{CommandRunner, OptionNaddrOrSetVecExt, RelayOrSetVecExt},
types::{NaddrOrSet, NostrEvent},
},
@@ -241,14 +242,17 @@ async fn make_patch(
event_builder =
event_builder.tag(utils::event_reply_tag(&root_id, write_relay, Marker::Root));
} else {
- event_builder = event_builder.tag(Tag::hashtag("root"));
+ event_builder = event_builder.tag(Tag::hashtag(ROOT_HASHTAG_CONTENT));
}
+ // Handles the case where there is a patch to reply to but no root. This
+ // indicates we are processing a revision, as the root revision should reply
+ // directly to the original patch.
if let Some(reply_to_id) = reply_to {
if root.is_none() {
event_builder = event_builder.tags([
utils::event_reply_tag(&reply_to_id, write_relay, Marker::Reply),
- Tag::hashtag("root-revision"),
+ Tag::hashtag(REVISION_ROOT_HASHTAG_CONTENT),
]);
} else {
event_builder = event_builder.tag(utils::event_reply_tag(
diff --git a/src/nostr_utils/traits.rs b/src/nostr_utils/traits.rs
index 712a10b..d4eb102 100644
--- a/src/nostr_utils/traits.rs
+++ b/src/nostr_utils/traits.rs
@@ -30,6 +30,7 @@ use nostr::{
};
use crate::cli::issue::ISSUE_ALT_PREFIX;
+use crate::cli::patch::{REVISION_ROOT_HASHTAG_CONTENT, ROOT_HASHTAG_CONTENT};
use crate::error::{N34Error, N34Result};
@@ -245,7 +246,7 @@ impl Event {
&& self
.tags
.filter(TagKind::t())
- .any(|t| t.content() == Some("root"))
+ .any(|t| t.content() == Some(ROOT_HASHTAG_CONTENT))
}
/// Returns whether the patch is patch-revision or not
@@ -255,7 +256,7 @@ impl Event {
&& self
.tags
.filter(TagKind::t())
- .any(|t| t.content() == Some("root-revision"))
+ .any(|t| t.content() == Some(REVISION_ROOT_HASHTAG_CONTENT))
}
/// Gets the root patch ID from a patch-revision event by finding the `e`