chore: Rename PatchStatus to PatchPrStatus

Signed-off-by: Awiteb <a@4rs.nl>
This commit is contained in:
Awiteb
2025-08-27 22:50:05 +00:00
parent f996fd351b
commit cc3aed0e89
8 changed files with 46 additions and 40 deletions

View File

@@ -17,7 +17,7 @@
use clap::Args; use clap::Args;
use nostr::hashes::sha1::Hash as Sha1Hash; use nostr::hashes::sha1::Hash as Sha1Hash;
use super::PatchStatus; use super::PatchPrStatus;
use crate::{ use crate::{
cli::{ cli::{
CliOptions, CliOptions,
@@ -59,7 +59,7 @@ impl CommandRunner for ApplyArgs {
options, options,
self.patch_id, self.patch_id,
self.naddrs, self.naddrs,
PatchStatus::MergedApplied, PatchPrStatus::MergedApplied,
Some(either::Either::Right(self.applied_commits)), Some(either::Either::Right(self.applied_commits)),
self.applied_patches.into_event_ids(), self.applied_patches.into_event_ids(),
|patch_status| { |patch_status| {

View File

@@ -16,7 +16,7 @@
use clap::Args; use clap::Args;
use super::PatchStatus; use super::PatchPrStatus;
use crate::{ use crate::{
cli::{ cli::{
CliOptions, CliOptions,
@@ -50,7 +50,7 @@ impl CommandRunner for CloseArgs {
options, options,
self.patch_id, self.patch_id,
self.naddrs, self.naddrs,
PatchStatus::Closed, PatchPrStatus::Closed,
None, None,
Vec::new(), Vec::new(),
|patch_status| { |patch_status| {

View File

@@ -16,7 +16,7 @@
use clap::Args; use clap::Args;
use super::PatchStatus; use super::PatchPrStatus;
use crate::{ use crate::{
cli::{ cli::{
CliOptions, CliOptions,
@@ -50,7 +50,7 @@ impl CommandRunner for DraftArgs {
options, options,
self.patch_id, self.patch_id,
self.naddrs, self.naddrs,
PatchStatus::Draft, PatchPrStatus::Draft,
None, None,
Vec::new(), Vec::new(),
|patch_status| { |patch_status| {

View File

@@ -17,7 +17,7 @@
use clap::Args; use clap::Args;
use nostr::hashes::sha1::Hash as Sha1Hash; use nostr::hashes::sha1::Hash as Sha1Hash;
use super::PatchStatus; use super::PatchPrStatus;
use crate::{ use crate::{
cli::{ cli::{
CliOptions, CliOptions,
@@ -58,7 +58,7 @@ impl CommandRunner for MergeArgs {
options, options,
self.patch_id, self.patch_id,
self.naddrs, self.naddrs,
PatchStatus::MergedApplied, PatchPrStatus::MergedApplied,
Some(either::Either::Left(self.merge_commit)), Some(either::Either::Left(self.merge_commit)),
self.merged_patches.into_event_ids(), self.merged_patches.into_event_ids(),
|patch_status| { |patch_status| {

View File

@@ -109,19 +109,30 @@ pub struct GitPatch {
} }
#[derive(Debug)] #[derive(Debug)]
pub enum PatchStatus { pub enum PatchPrStatus {
/// The patch is currently open /// The patch/pr is currently open
Open, Open,
/// The patch has been merged/applied /// The patch/pr has been merged/applied
MergedApplied, MergedApplied,
/// The patch has been closed /// The patch/pr has been closed
Closed, Closed,
/// A patch that has been drafted but not yet applied. /// A patch/pr that has been drafted but not yet applied.
Draft, Draft,
} }
impl PatchStatus { impl PatchPrStatus {
/// Maps the issue status to its corresponding Nostr kind. /// 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] #[inline]
pub fn kind(&self) -> Kind { pub fn kind(&self) -> Kind {
match self { 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 { pub const fn as_str(&self) -> &'static str {
match self { match self {
Self::Open => "Open", Self::Open => "Open",
@@ -142,45 +153,45 @@ impl PatchStatus {
} }
} }
/// Check if the patch is open. /// Check if the status is open.
#[inline] #[inline]
pub fn is_open(&self) -> bool { pub fn is_open(&self) -> bool {
matches!(self, Self::Open) matches!(self, Self::Open)
} }
/// Check if the patch is merged/applied. /// Check if the status is merged/applied.
#[inline] #[inline]
pub fn is_merged_or_applied(&self) -> bool { pub fn is_merged_or_applied(&self) -> bool {
matches!(self, Self::MergedApplied) matches!(self, Self::MergedApplied)
} }
/// Check if the patch is closed. /// Check if the status is closed.
#[inline] #[inline]
pub fn is_closed(&self) -> bool { pub fn is_closed(&self) -> bool {
matches!(self, Self::Closed) matches!(self, Self::Closed)
} }
/// Check if the patch is drafted /// Check if the status is draft
#[inline] #[inline]
pub fn is_drafted(&self) -> bool { pub fn is_drafted(&self) -> bool {
matches!(self, Self::Draft) matches!(self, Self::Draft)
} }
} }
impl From<&PatchStatus> for Kind { impl From<&PatchPrStatus> for Kind {
fn from(status: &PatchStatus) -> Self { fn from(status: &PatchPrStatus) -> Self {
status.kind() status.kind()
} }
} }
impl fmt::Display for PatchStatus { impl fmt::Display for PatchPrStatus {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.as_str()) write!(f, "{}", self.as_str())
} }
} }
impl TryFrom<Kind> for PatchStatus { impl TryFrom<Kind> for PatchPrStatus {
type Error = N34Error; type Error = N34Error;
fn try_from(kind: Kind) -> Result<Self, Self::Error> { fn try_from(kind: Kind) -> Result<Self, Self::Error> {

View File

@@ -16,7 +16,7 @@
use clap::Args; use clap::Args;
use super::PatchStatus; use super::PatchPrStatus;
use crate::{ use crate::{
cli::{ cli::{
CliOptions, CliOptions,
@@ -50,7 +50,7 @@ impl CommandRunner for ReopenArgs {
options, options,
self.patch_id, self.patch_id,
self.naddrs, self.naddrs,
PatchStatus::Open, PatchPrStatus::Open,
None, None,
Vec::new(), Vec::new(),
|patch_status| { |patch_status| {

View File

@@ -28,7 +28,7 @@ use nostr::{
use super::{ use super::{
issue::IssueStatus, issue::IssueStatus,
patch::PatchStatus, patch::PatchPrStatus,
types::{NaddrOrSet, NostrEvent}, types::{NaddrOrSet, NostrEvent},
}; };
use crate::{ use crate::{
@@ -133,10 +133,10 @@ pub async fn patch_status_command(
options: CliOptions, options: CliOptions,
patch_id: NostrEvent, patch_id: NostrEvent,
naddrs: Option<Vec<NaddrOrSet>>, naddrs: Option<Vec<NaddrOrSet>>,
new_status: PatchStatus, new_status: PatchPrStatus,
merge_or_applied_commits: Option<Either<Sha1Hash, Vec<Sha1Hash>>>, merge_or_applied_commits: Option<Either<Sha1Hash, Vec<Sha1Hash>>>,
merge_or_applied_patches: Vec<EventId>, merge_or_applied_patches: Vec<EventId>,
check_fn: impl FnOnce(&PatchStatus) -> N34Result<()>, check_fn: impl FnOnce(&PatchPrStatus) -> N34Result<()>,
) -> N34Result<()> { ) -> N34Result<()> {
let naddrs = utils::naddrs_or_file( let naddrs = utils::naddrs_or_file(
naddrs.flat_naddrs(&options.config.sets)?, naddrs.flat_naddrs(&options.config.sets)?,

View File

@@ -39,7 +39,7 @@ use nostr_sdk::{Client, ClientOptions};
use traits::TokenUtils; use traits::TokenUtils;
use crate::{ use crate::{
cli::{CliOptions, issue::IssueStatus, patch::PatchStatus}, cli::{CliOptions, issue::IssueStatus, patch::PatchPrStatus},
error::{N34Error, N34Result}, error::{N34Error, N34Result},
}; };
@@ -307,24 +307,19 @@ impl NostrClient {
root_patch: EventId, root_patch: EventId,
root_revision: Option<EventId>, root_revision: Option<EventId>,
authorized_pubkeys: Vec<PublicKey>, authorized_pubkeys: Vec<PublicKey>,
) -> N34Result<PatchStatus> { ) -> N34Result<PatchPrStatus> {
let (root_status, event_tags) = self let (root_status, event_tags) = self
.fetch_events( .fetch_events(
Filter::new() Filter::new()
.event(root_patch) .event(root_patch)
.kinds([ .kinds(PatchPrStatus::all_kinds())
Kind::GitStatusOpen,
Kind::GitStatusApplied,
Kind::GitStatusClosed,
Kind::GitStatusDraft,
])
.authors(utils::dedup(authorized_pubkeys.into_iter())), .authors(utils::dedup(authorized_pubkeys.into_iter())),
) )
.await? .await?
.into_iter() .into_iter()
.max_by_key(|e| e.created_at) .max_by_key(|e| e.created_at)
.map(|status| N34Result::Ok((PatchStatus::try_from(status.kind)?, status.tags))) .map(|status| N34Result::Ok((PatchPrStatus::try_from(status.kind)?, status.tags)))
.unwrap_or_else(|| Ok((PatchStatus::Open, Tags::new())))?; .unwrap_or_else(|| Ok((PatchPrStatus::Open, Tags::new())))?;
if let Some(revision_id) = root_revision if let Some(revision_id) = root_revision
&& root_status.is_merged_or_applied() && root_status.is_merged_or_applied()
@@ -332,7 +327,7 @@ impl NostrClient {
.filter(TagKind::e()) .filter(TagKind::e())
.any(|t| t.is_reply() && t.content().is_some_and(|c| c == revision_id.to_hex())) .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) Ok(root_status)