From cc3aed0e89c4dca442f9c8e9b1f29283e3b58ef4 Mon Sep 17 00:00:00 2001
From: Awiteb
Date: Wed, 27 Aug 2025 22:50:05 +0000
Subject: [PATCH] chore: Rename `PatchStatus` to `PatchPrStatus`
Signed-off-by: Awiteb
---
src/cli/commands/patch/apply.rs | 4 +--
src/cli/commands/patch/close.rs | 4 +--
src/cli/commands/patch/draft.rs | 4 +--
src/cli/commands/patch/merge.rs | 4 +--
src/cli/commands/patch/mod.rs | 43 ++++++++++++++++++++------------
src/cli/commands/patch/reopen.rs | 4 +--
src/cli/common_commands.rs | 6 ++---
src/nostr_utils/mod.rs | 17 +++++--------
8 files changed, 46 insertions(+), 40 deletions(-)
diff --git a/src/cli/commands/patch/apply.rs b/src/cli/commands/patch/apply.rs
index 82f51ee..b105539 100644
--- a/src/cli/commands/patch/apply.rs
+++ b/src/cli/commands/patch/apply.rs
@@ -17,7 +17,7 @@
use clap::Args;
use nostr::hashes::sha1::Hash as Sha1Hash;
-use super::PatchStatus;
+use super::PatchPrStatus;
use crate::{
cli::{
CliOptions,
@@ -59,7 +59,7 @@ impl CommandRunner for ApplyArgs {
options,
self.patch_id,
self.naddrs,
- PatchStatus::MergedApplied,
+ PatchPrStatus::MergedApplied,
Some(either::Either::Right(self.applied_commits)),
self.applied_patches.into_event_ids(),
|patch_status| {
diff --git a/src/cli/commands/patch/close.rs b/src/cli/commands/patch/close.rs
index 3582ab7..ca90256 100644
--- a/src/cli/commands/patch/close.rs
+++ b/src/cli/commands/patch/close.rs
@@ -16,7 +16,7 @@
use clap::Args;
-use super::PatchStatus;
+use super::PatchPrStatus;
use crate::{
cli::{
CliOptions,
@@ -50,7 +50,7 @@ impl CommandRunner for CloseArgs {
options,
self.patch_id,
self.naddrs,
- PatchStatus::Closed,
+ PatchPrStatus::Closed,
None,
Vec::new(),
|patch_status| {
diff --git a/src/cli/commands/patch/draft.rs b/src/cli/commands/patch/draft.rs
index 14ebdb5..1d85ffb 100644
--- a/src/cli/commands/patch/draft.rs
+++ b/src/cli/commands/patch/draft.rs
@@ -16,7 +16,7 @@
use clap::Args;
-use super::PatchStatus;
+use super::PatchPrStatus;
use crate::{
cli::{
CliOptions,
@@ -50,7 +50,7 @@ impl CommandRunner for DraftArgs {
options,
self.patch_id,
self.naddrs,
- PatchStatus::Draft,
+ PatchPrStatus::Draft,
None,
Vec::new(),
|patch_status| {
diff --git a/src/cli/commands/patch/merge.rs b/src/cli/commands/patch/merge.rs
index d8efc6c..489d905 100644
--- a/src/cli/commands/patch/merge.rs
+++ b/src/cli/commands/patch/merge.rs
@@ -17,7 +17,7 @@
use clap::Args;
use nostr::hashes::sha1::Hash as Sha1Hash;
-use super::PatchStatus;
+use super::PatchPrStatus;
use crate::{
cli::{
CliOptions,
@@ -58,7 +58,7 @@ impl CommandRunner for MergeArgs {
options,
self.patch_id,
self.naddrs,
- PatchStatus::MergedApplied,
+ PatchPrStatus::MergedApplied,
Some(either::Either::Left(self.merge_commit)),
self.merged_patches.into_event_ids(),
|patch_status| {
diff --git a/src/cli/commands/patch/mod.rs b/src/cli/commands/patch/mod.rs
index 2cd5660..b90c6a6 100644
--- a/src/cli/commands/patch/mod.rs
+++ b/src/cli/commands/patch/mod.rs
@@ -109,19 +109,30 @@ pub struct GitPatch {
}
#[derive(Debug)]
-pub enum PatchStatus {
- /// The patch is currently open
+pub enum PatchPrStatus {
+ /// The patch/pr is currently open
Open,
- /// The patch has been merged/applied
+ /// The patch/pr has been merged/applied
MergedApplied,
- /// The patch has been closed
+ /// The patch/pr has been closed
Closed,
- /// A patch that has been drafted but not yet applied.
+ /// A patch/pr that has been drafted but not yet applied.
Draft,
}
-impl PatchStatus {
- /// Maps the issue status to its corresponding Nostr kind.
+impl PatchPrStatus {
+ /// Returns all status kinds
+ #[inline]
+ pub const fn all_kinds() -> [Kind; 4] {
+ [
+ Kind::GitStatusOpen,
+ Kind::GitStatusApplied,
+ Kind::GitStatusClosed,
+ Kind::GitStatusDraft,
+ ]
+ }
+
+ /// Maps the patch/pr status to its corresponding Nostr kind.
#[inline]
pub fn kind(&self) -> Kind {
match self {
@@ -132,7 +143,7 @@ impl PatchStatus {
}
}
- /// Returns the string representation of the patch status.
+ /// Returns the string representation of the patch/pr status.
pub const fn as_str(&self) -> &'static str {
match self {
Self::Open => "Open",
@@ -142,45 +153,45 @@ impl PatchStatus {
}
}
- /// Check if the patch is open.
+ /// Check if the status is open.
#[inline]
pub fn is_open(&self) -> bool {
matches!(self, Self::Open)
}
- /// Check if the patch is merged/applied.
+ /// Check if the status is merged/applied.
#[inline]
pub fn is_merged_or_applied(&self) -> bool {
matches!(self, Self::MergedApplied)
}
- /// Check if the patch is closed.
+ /// Check if the status is closed.
#[inline]
pub fn is_closed(&self) -> bool {
matches!(self, Self::Closed)
}
- /// Check if the patch is drafted
+ /// Check if the status is draft
#[inline]
pub fn is_drafted(&self) -> bool {
matches!(self, Self::Draft)
}
}
-impl From<&PatchStatus> for Kind {
- fn from(status: &PatchStatus) -> Self {
+impl From<&PatchPrStatus> for Kind {
+ fn from(status: &PatchPrStatus) -> Self {
status.kind()
}
}
-impl fmt::Display for PatchStatus {
+impl fmt::Display for PatchPrStatus {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.as_str())
}
}
-impl TryFrom for PatchStatus {
+impl TryFrom for PatchPrStatus {
type Error = N34Error;
fn try_from(kind: Kind) -> Result {
diff --git a/src/cli/commands/patch/reopen.rs b/src/cli/commands/patch/reopen.rs
index 8ef32a4..890323b 100644
--- a/src/cli/commands/patch/reopen.rs
+++ b/src/cli/commands/patch/reopen.rs
@@ -16,7 +16,7 @@
use clap::Args;
-use super::PatchStatus;
+use super::PatchPrStatus;
use crate::{
cli::{
CliOptions,
@@ -50,7 +50,7 @@ impl CommandRunner for ReopenArgs {
options,
self.patch_id,
self.naddrs,
- PatchStatus::Open,
+ PatchPrStatus::Open,
None,
Vec::new(),
|patch_status| {
diff --git a/src/cli/common_commands.rs b/src/cli/common_commands.rs
index 0c3b24c..baa30cc 100644
--- a/src/cli/common_commands.rs
+++ b/src/cli/common_commands.rs
@@ -28,7 +28,7 @@ use nostr::{
use super::{
issue::IssueStatus,
- patch::PatchStatus,
+ patch::PatchPrStatus,
types::{NaddrOrSet, NostrEvent},
};
use crate::{
@@ -133,10 +133,10 @@ pub async fn patch_status_command(
options: CliOptions,
patch_id: NostrEvent,
naddrs: Option>,
- new_status: PatchStatus,
+ new_status: PatchPrStatus,
merge_or_applied_commits: Option>>,
merge_or_applied_patches: Vec,
- check_fn: impl FnOnce(&PatchStatus) -> N34Result<()>,
+ check_fn: impl FnOnce(&PatchPrStatus) -> N34Result<()>,
) -> N34Result<()> {
let naddrs = utils::naddrs_or_file(
naddrs.flat_naddrs(&options.config.sets)?,
diff --git a/src/nostr_utils/mod.rs b/src/nostr_utils/mod.rs
index 712089c..e94eeeb 100644
--- a/src/nostr_utils/mod.rs
+++ b/src/nostr_utils/mod.rs
@@ -39,7 +39,7 @@ use nostr_sdk::{Client, ClientOptions};
use traits::TokenUtils;
use crate::{
- cli::{CliOptions, issue::IssueStatus, patch::PatchStatus},
+ cli::{CliOptions, issue::IssueStatus, patch::PatchPrStatus},
error::{N34Error, N34Result},
};
@@ -307,24 +307,19 @@ impl NostrClient {
root_patch: EventId,
root_revision: Option,
authorized_pubkeys: Vec,
- ) -> N34Result {
+ ) -> N34Result {
let (root_status, event_tags) = self
.fetch_events(
Filter::new()
.event(root_patch)
- .kinds([
- Kind::GitStatusOpen,
- Kind::GitStatusApplied,
- Kind::GitStatusClosed,
- Kind::GitStatusDraft,
- ])
+ .kinds(PatchPrStatus::all_kinds())
.authors(utils::dedup(authorized_pubkeys.into_iter())),
)
.await?
.into_iter()
.max_by_key(|e| e.created_at)
- .map(|status| N34Result::Ok((PatchStatus::try_from(status.kind)?, status.tags)))
- .unwrap_or_else(|| Ok((PatchStatus::Open, Tags::new())))?;
+ .map(|status| N34Result::Ok((PatchPrStatus::try_from(status.kind)?, status.tags)))
+ .unwrap_or_else(|| Ok((PatchPrStatus::Open, Tags::new())))?;
if let Some(revision_id) = root_revision
&& root_status.is_merged_or_applied()
@@ -332,7 +327,7 @@ impl NostrClient {
.filter(TagKind::e())
.any(|t| t.is_reply() && t.content().is_some_and(|c| c == revision_id.to_hex()))
{
- return Ok(PatchStatus::Closed);
+ return Ok(PatchPrStatus::Closed);
}
Ok(root_status)