refactor: Move root and root-revision to constants
Signed-off-by: Awiteb <a@4rs.nl>
This commit is contained in:
@@ -68,6 +68,11 @@ static PATCH_VERSION_NUMBER_RE: LazyLock<Regex> = LazyLock::new(|| {
|
|||||||
Regex::new(r"\[PATCH\s+(?:v(?<version>\d+)\s*)?(?<number>\d+)/(?:\d+)").unwrap()
|
Regex::new(r"\[PATCH\s+(?:v(?<version>\d+)\s*)?(?<number>\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)]
|
#[derive(Subcommand, Debug)]
|
||||||
pub enum PatchSubcommands {
|
pub enum PatchSubcommands {
|
||||||
/// Send one or more patches to a repository.
|
/// Send one or more patches to a repository.
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ use super::GitPatch;
|
|||||||
use crate::{
|
use crate::{
|
||||||
cli::{
|
cli::{
|
||||||
CliOptions,
|
CliOptions,
|
||||||
|
patch::{REVISION_ROOT_HASHTAG_CONTENT, ROOT_HASHTAG_CONTENT},
|
||||||
traits::{CommandRunner, OptionNaddrOrSetVecExt, RelayOrSetVecExt},
|
traits::{CommandRunner, OptionNaddrOrSetVecExt, RelayOrSetVecExt},
|
||||||
types::{NaddrOrSet, NostrEvent},
|
types::{NaddrOrSet, NostrEvent},
|
||||||
},
|
},
|
||||||
@@ -241,14 +242,17 @@ async fn make_patch(
|
|||||||
event_builder =
|
event_builder =
|
||||||
event_builder.tag(utils::event_reply_tag(&root_id, write_relay, Marker::Root));
|
event_builder.tag(utils::event_reply_tag(&root_id, write_relay, Marker::Root));
|
||||||
} else {
|
} 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 let Some(reply_to_id) = reply_to {
|
||||||
if root.is_none() {
|
if root.is_none() {
|
||||||
event_builder = event_builder.tags([
|
event_builder = event_builder.tags([
|
||||||
utils::event_reply_tag(&reply_to_id, write_relay, Marker::Reply),
|
utils::event_reply_tag(&reply_to_id, write_relay, Marker::Reply),
|
||||||
Tag::hashtag("root-revision"),
|
Tag::hashtag(REVISION_ROOT_HASHTAG_CONTENT),
|
||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
event_builder = event_builder.tag(utils::event_reply_tag(
|
event_builder = event_builder.tag(utils::event_reply_tag(
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ use nostr::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use crate::cli::issue::ISSUE_ALT_PREFIX;
|
use crate::cli::issue::ISSUE_ALT_PREFIX;
|
||||||
|
use crate::cli::patch::{REVISION_ROOT_HASHTAG_CONTENT, ROOT_HASHTAG_CONTENT};
|
||||||
use crate::error::{N34Error, N34Result};
|
use crate::error::{N34Error, N34Result};
|
||||||
|
|
||||||
|
|
||||||
@@ -245,7 +246,7 @@ impl Event {
|
|||||||
&& self
|
&& self
|
||||||
.tags
|
.tags
|
||||||
.filter(TagKind::t())
|
.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
|
/// Returns whether the patch is patch-revision or not
|
||||||
@@ -255,7 +256,7 @@ impl Event {
|
|||||||
&& self
|
&& self
|
||||||
.tags
|
.tags
|
||||||
.filter(TagKind::t())
|
.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`
|
/// Gets the root patch ID from a patch-revision event by finding the `e`
|
||||||
|
|||||||
Reference in New Issue
Block a user