Rename patch/issue "status"

This reverts to the previous naming, since after serialization
we would otherwise end up with `{ status: { status: closed } }`.

Signed-off-by: Alexis Sellier <alexis@radicle.xyz>
This commit is contained in:
Alexis Sellier 2022-12-09 10:44:59 +01:00
parent de0e54a186
commit 5d2be57cd9
No known key found for this signature in database
4 changed files with 43 additions and 43 deletions

View File

@ -8,7 +8,7 @@ use crate::terminal as term;
use crate::terminal::args::{Args, Error, Help}; use crate::terminal::args::{Args, Error, Help};
use radicle::cob::common::{Reaction, Tag}; use radicle::cob::common::{Reaction, Tag};
use radicle::cob::issue::{CloseReason, IssueId, Issues, Status}; use radicle::cob::issue::{CloseReason, IssueId, Issues, State};
use radicle::storage::WriteStorage; use radicle::storage::WriteStorage;
pub const HELP: Help = Help { pub const HELP: Help = Help {
@ -59,7 +59,7 @@ pub enum Operation {
}, },
State { State {
id: IssueId, id: IssueId,
state: Status, state: State,
}, },
Delete { Delete {
id: IssueId, id: IssueId,
@ -86,7 +86,7 @@ impl Args for Options {
let mut title: Option<String> = None; let mut title: Option<String> = None;
let mut reaction: Option<Reaction> = None; let mut reaction: Option<Reaction> = None;
let mut description: Option<String> = None; let mut description: Option<String> = None;
let mut state: Option<Status> = None; let mut state: Option<State> = None;
while let Some(arg) = parser.next()? { while let Some(arg) = parser.next()? {
match arg { match arg {
@ -97,15 +97,15 @@ impl Args for Options {
title = Some(parser.value()?.to_string_lossy().into()); title = Some(parser.value()?.to_string_lossy().into());
} }
Long("closed") if op == Some(OperationName::State) => { Long("closed") if op == Some(OperationName::State) => {
state = Some(Status::Closed { state = Some(State::Closed {
reason: CloseReason::Other, reason: CloseReason::Other,
}); });
} }
Long("open") if op == Some(OperationName::State) => { Long("open") if op == Some(OperationName::State) => {
state = Some(Status::Open); state = Some(State::Open);
} }
Long("solved") if op == Some(OperationName::State) => { Long("solved") if op == Some(OperationName::State) => {
state = Some(Status::Closed { state = Some(State::Closed {
reason: CloseReason::Solved, reason: CloseReason::Solved,
}); });
} }

View File

@ -333,7 +333,7 @@ async fn issues_handler(
"id": id, "id": id,
"author": issue.author(), "author": issue.author(),
"title": issue.title(), "title": issue.title(),
"status": issue.status(), "status": issue.state(),
"discussion": issue.comments().collect::<Vec<_>>(), "discussion": issue.comments().collect::<Vec<_>>(),
"tags": issue.tags().collect::<Vec<_>>(), "tags": issue.tags().collect::<Vec<_>>(),
}) })
@ -360,7 +360,7 @@ async fn issue_handler(
"id": issue_id, "id": issue_id,
"author": issue.author(), "author": issue.author(),
"title": issue.title(), "title": issue.title(),
"status": issue.status(), "status": issue.state(),
"discussion": issue.comments().collect::<Vec<_>>(), "discussion": issue.comments().collect::<Vec<_>>(),
"tags": issue.tags().collect::<Vec<_>>(), "tags": issue.tags().collect::<Vec<_>>(),
}); });

View File

@ -47,7 +47,7 @@ pub enum CloseReason {
/// Issue state. /// Issue state.
#[derive(Debug, Default, Clone, Copy, PartialOrd, Ord, PartialEq, Eq, Serialize, Deserialize)] #[derive(Debug, Default, Clone, Copy, PartialOrd, Ord, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase", tag = "status")] #[serde(rename_all = "camelCase", tag = "status")]
pub enum Status { pub enum State {
/// The issue is closed. /// The issue is closed.
Closed { reason: CloseReason }, Closed { reason: CloseReason },
/// The issue is open. /// The issue is open.
@ -55,7 +55,7 @@ pub enum Status {
Open, Open,
} }
impl std::fmt::Display for Status { impl std::fmt::Display for State {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self { match self {
Self::Closed { .. } => write!(f, "closed"), Self::Closed { .. } => write!(f, "closed"),
@ -64,11 +64,11 @@ impl std::fmt::Display for Status {
} }
} }
impl Status { impl State {
pub fn lifecycle_message(self) -> String { pub fn lifecycle_message(self) -> String {
match self { match self {
Status::Open => "Open issue".to_owned(), State::Open => "Open issue".to_owned(),
Status::Closed { .. } => "Close issue".to_owned(), State::Closed { .. } => "Close issue".to_owned(),
} }
} }
} }
@ -77,7 +77,7 @@ impl Status {
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq)]
pub struct Issue { pub struct Issue {
title: LWWReg<Max<String>, clock::Lamport>, title: LWWReg<Max<String>, clock::Lamport>,
status: LWWReg<Max<Status>, clock::Lamport>, state: LWWReg<Max<State>, clock::Lamport>,
tags: LWWSet<Tag>, tags: LWWSet<Tag>,
thread: Thread, thread: Thread,
} }
@ -85,7 +85,7 @@ pub struct Issue {
impl Semilattice for Issue { impl Semilattice for Issue {
fn merge(&mut self, other: Self) { fn merge(&mut self, other: Self) {
self.title.merge(other.title); self.title.merge(other.title);
self.status.merge(other.status); self.state.merge(other.state);
self.thread.merge(other.thread); self.thread.merge(other.thread);
} }
} }
@ -94,7 +94,7 @@ impl Default for Issue {
fn default() -> Self { fn default() -> Self {
Self { Self {
title: Max::from(String::default()).into(), title: Max::from(String::default()).into(),
status: Max::from(Status::default()).into(), state: Max::from(State::default()).into(),
tags: LWWSet::default(), tags: LWWSet::default(),
thread: Thread::default(), thread: Thread::default(),
} }
@ -132,8 +132,8 @@ impl Issue {
self.title.get().as_str() self.title.get().as_str()
} }
pub fn status(&self) -> &Status { pub fn state(&self) -> &State {
self.status.get() self.state.get()
} }
pub fn tags(&self) -> impl Iterator<Item = &Tag> { pub fn tags(&self) -> impl Iterator<Item = &Tag> {
@ -161,8 +161,8 @@ impl Issue {
Action::Title { title } => { Action::Title { title } => {
self.title.set(title, op.clock); self.title.set(title, op.clock);
} }
Action::Lifecycle { status } => { Action::Lifecycle { state } => {
self.status.set(status, op.clock); self.state.set(state, op.clock);
} }
Action::Tag { add, remove } => { Action::Tag { add, remove } => {
for tag in add { for tag in add {
@ -208,8 +208,8 @@ impl<'a, 'g> IssueMut<'a, 'g> {
} }
/// Lifecycle an issue. /// Lifecycle an issue.
pub fn lifecycle<G: Signer>(&mut self, status: Status, signer: &G) -> Result<OpId, Error> { pub fn lifecycle<G: Signer>(&mut self, state: State, signer: &G) -> Result<OpId, Error> {
let action = Action::Lifecycle { status }; let action = Action::Lifecycle { state };
self.apply("Lifecycle", action, signer) self.apply("Lifecycle", action, signer)
} }
@ -388,7 +388,7 @@ impl<'a> Issues<'a> {
#[serde(tag = "type", rename_all = "camelCase")] #[serde(tag = "type", rename_all = "camelCase")]
pub enum Action { pub enum Action {
Title { title: String }, Title { title: String },
Lifecycle { status: Status }, Lifecycle { state: State },
Tag { add: Vec<Tag>, remove: Vec<Tag> }, Tag { add: Vec<Tag>, remove: Vec<Tag> },
Thread { action: thread::Action }, Thread { action: thread::Action },
} }
@ -411,8 +411,8 @@ mod test {
fn test_ordering() { fn test_ordering() {
assert!(CloseReason::Solved > CloseReason::Other); assert!(CloseReason::Solved > CloseReason::Other);
assert!( assert!(
Status::Open State::Open
> Status::Closed { > State::Closed {
reason: CloseReason::Solved reason: CloseReason::Solved
} }
); );
@ -434,7 +434,7 @@ mod test {
assert_eq!(issue.author(), Some(issues.author())); assert_eq!(issue.author(), Some(issues.author()));
assert_eq!(issue.description(), Some("Blah blah blah.")); assert_eq!(issue.description(), Some("Blah blah blah."));
assert_eq!(issue.comments().count(), 1); assert_eq!(issue.comments().count(), 1);
assert_eq!(issue.status(), &Status::Open); assert_eq!(issue.state(), &State::Open);
} }
#[test] #[test]
@ -448,7 +448,7 @@ mod test {
issue issue
.lifecycle( .lifecycle(
Status::Closed { State::Closed {
reason: CloseReason::Other, reason: CloseReason::Other,
}, },
&signer, &signer,
@ -458,15 +458,15 @@ mod test {
let id = issue.id; let id = issue.id;
let mut issue = issues.get_mut(&id).unwrap(); let mut issue = issues.get_mut(&id).unwrap();
assert_eq!( assert_eq!(
*issue.status(), *issue.state(),
Status::Closed { State::Closed {
reason: CloseReason::Other reason: CloseReason::Other
} }
); );
issue.lifecycle(Status::Open, &signer).unwrap(); issue.lifecycle(State::Open, &signer).unwrap();
let issue = issues.get(&id).unwrap().unwrap(); let issue = issues.get(&id).unwrap().unwrap();
assert_eq!(*issue.status(), Status::Open); assert_eq!(*issue.state(), State::Open);
} }
#[test] #[test]
@ -566,12 +566,12 @@ mod test {
#[test] #[test]
fn test_issue_state_serde() { fn test_issue_state_serde() {
assert_eq!( assert_eq!(
serde_json::to_value(Status::Open).unwrap(), serde_json::to_value(State::Open).unwrap(),
serde_json::json!({ "status": "open" }) serde_json::json!({ "status": "open" })
); );
assert_eq!( assert_eq!(
serde_json::to_value(Status::Closed { serde_json::to_value(State::Closed {
reason: CloseReason::Solved reason: CloseReason::Solved
}) })
.unwrap(), .unwrap(),

View File

@ -120,8 +120,8 @@ pub struct Patch {
pub title: LWWReg<Max<String>>, pub title: LWWReg<Max<String>>,
/// Patch description. /// Patch description.
pub description: LWWReg<Max<String>>, pub description: LWWReg<Max<String>>,
/// Current status of the patch. /// Current state of the patch.
pub status: LWWReg<Max<Status>>, pub state: LWWReg<Max<State>>,
/// Target this patch is meant to be merged in. /// Target this patch is meant to be merged in.
pub target: LWWReg<Max<MergeTarget>>, pub target: LWWReg<Max<MergeTarget>>,
/// Associated tags. /// Associated tags.
@ -135,7 +135,7 @@ impl Semilattice for Patch {
fn merge(&mut self, other: Self) { fn merge(&mut self, other: Self) {
self.title.merge(other.title); self.title.merge(other.title);
self.description.merge(other.description); self.description.merge(other.description);
self.status.merge(other.status); self.state.merge(other.state);
self.target.merge(other.target); self.target.merge(other.target);
self.tags.merge(other.tags); self.tags.merge(other.tags);
self.revisions.merge(other.revisions); self.revisions.merge(other.revisions);
@ -147,7 +147,7 @@ impl Default for Patch {
Self { Self {
title: Max::from(String::default()).into(), title: Max::from(String::default()).into(),
description: Max::from(String::default()).into(), description: Max::from(String::default()).into(),
status: Max::from(Status::default()).into(), state: Max::from(State::default()).into(),
target: Max::from(MergeTarget::default()).into(), target: Max::from(MergeTarget::default()).into(),
tags: LWWSet::default(), tags: LWWSet::default(),
revisions: GMap::default(), revisions: GMap::default(),
@ -160,8 +160,8 @@ impl Patch {
self.title.get().get() self.title.get().get()
} }
pub fn status(&self) -> Status { pub fn state(&self) -> State {
*self.status.get().get() *self.state.get().get()
} }
pub fn target(&self) -> MergeTarget { pub fn target(&self) -> MergeTarget {
@ -217,11 +217,11 @@ impl Patch {
} }
pub fn is_proposed(&self) -> bool { pub fn is_proposed(&self) -> bool {
matches!(self.status.get().get(), Status::Proposed) matches!(self.state.get().get(), State::Proposed)
} }
pub fn is_archived(&self) -> bool { pub fn is_archived(&self) -> bool {
matches!(self.status.get().get(), &Status::Archived) matches!(self.state.get().get(), &State::Archived)
} }
/// Apply a list of operations to the state. /// Apply a list of operations to the state.
@ -383,7 +383,7 @@ impl Revision {
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)] #[derive(Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub enum Status { pub enum State {
#[default] #[default]
Proposed, Proposed,
Draft, Draft,
@ -978,7 +978,7 @@ mod test {
assert_eq!(patch.title(), "My first patch"); assert_eq!(patch.title(), "My first patch");
assert_eq!(patch.description(), Some("Blah blah blah.")); assert_eq!(patch.description(), Some("Blah blah blah."));
assert_eq!(patch.author().id(), &author); assert_eq!(patch.author().id(), &author);
assert_eq!(patch.status(), Status::Proposed); assert_eq!(patch.state(), State::Proposed);
assert_eq!(patch.target(), target); assert_eq!(patch.target(), target);
assert_eq!(patch.version(), 0); assert_eq!(patch.version(), 0);