aboutsummaryrefslogtreecommitdiff
path: root/ticket/src
diff options
context:
space:
mode:
Diffstat (limited to 'ticket/src')
-rw-r--r--ticket/src/actions.rs17
-rw-r--r--ticket/src/main.rs47
-rw-r--r--ticket/src/tui.rs16
3 files changed, 51 insertions, 29 deletions
diff --git a/ticket/src/actions.rs b/ticket/src/actions.rs
index 3e237ff..0d371b3 100644
--- a/ticket/src/actions.rs
+++ b/ticket/src/actions.rs
@@ -10,18 +10,21 @@ use log::*;
use shared::find_root;
use std::{
fs,
- path::PathBuf,
+ path::{
+ Path,
+ PathBuf,
+ },
};
pub fn get_open_tickets() -> Result<Vec<Ticket>> {
- get_tickets(open_tickets()?)
+ get_tickets(&open_tickets()?)
}
pub fn get_closed_tickets() -> Result<Vec<Ticket>> {
- get_tickets(closed_tickets()?)
+ get_tickets(&closed_tickets()?)
}
-fn get_tickets(path: PathBuf) -> Result<Vec<Ticket>> {
+fn get_tickets(path: &Path) -> Result<Vec<Ticket>> {
let mut out = Vec::new();
debug!("Looking for ticket.");
for entry in fs::read_dir(&path)? {
@@ -63,14 +66,14 @@ pub fn get_all_ticketsv0() -> Result<Vec<TicketV0>> {
Ok(tickets)
}
pub fn get_open_ticketsv0() -> Result<Vec<TicketV0>> {
- get_ticketsv0(open_tickets()?)
+ get_ticketsv0(&open_tickets()?)
}
pub fn get_closed_ticketsv0() -> Result<Vec<TicketV0>> {
- get_ticketsv0(closed_tickets()?)
+ get_ticketsv0(&closed_tickets()?)
}
-fn get_ticketsv0(path: PathBuf) -> Result<Vec<TicketV0>> {
+fn get_ticketsv0(path: &Path) -> Result<Vec<TicketV0>> {
let mut out = Vec::new();
debug!("Looking for ticket.");
for entry in fs::read_dir(&path)? {
diff --git a/ticket/src/main.rs b/ticket/src/main.rs
index 11e27e8..74a5699 100644
--- a/ticket/src/main.rs
+++ b/ticket/src/main.rs
@@ -1,3 +1,6 @@
+//! ticket is a cli tool to create, delete, and manage tickets as part of
+//! repository, rather than a separate service outside the history of the
+//! code.
mod actions;
mod tui;
@@ -18,6 +21,7 @@ use serde::{
Serialize,
};
use std::{
+ convert::TryInto,
env,
fs,
process,
@@ -55,9 +59,9 @@ enum Cmd {
#[paw::main]
fn main(args: Args) {
- env::var("RUST_LOG").map(drop).unwrap_or_else(|_| {
- env::set_var("RUST_LOG", "info");
- });
+ env::var("RUST_LOG")
+ .ok()
+ .map_or_else(|| env::set_var("RUST_LOG", "info"), drop);
pretty_env_logger::init();
if let Some(cmd) = args.cmd {
@@ -116,8 +120,8 @@ fn new() -> Result<()> {
"Create buffer file for the description at {}.",
description.display()
);
- fs::File::create(&description)?;
- Command::new(&env::var("EDITOR").unwrap_or_else(|_| "vi".into()))
+ let _ = fs::File::create(&description)?;
+ let _ = Command::new(&env::var("EDITOR").unwrap_or_else(|_| "vi".into()))
.arg(&description)
.spawn()?
.wait()?;
@@ -131,7 +135,11 @@ fn new() -> Result<()> {
title,
status: Status::Open,
id: Uuid::new_v1(
- Timestamp::from_unix(Context::new(1), Utc::now().timestamp() as u64, 0),
+ Timestamp::from_unix(
+ Context::new(1),
+ Utc::now().timestamp().try_into()?,
+ 0,
+ ),
&[0, 5, 2, 4, 9, 3],
)?,
assignees: Vec::new(),
@@ -254,15 +262,15 @@ fn migrate() -> Result<()> {
let open_tickets_path = open_tickets()?;
let closed_tickets_path = closed_tickets()?;
- for t in tickets.into_iter() {
+ for t in tickets {
let ticket = Ticket {
title: t.title,
status: t.status,
id: Uuid::new_v1(
- Timestamp::from_unix(&ctx, Utc::now().timestamp() as u64, 0),
+ Timestamp::from_unix(&ctx, Utc::now().timestamp().try_into()?, 0),
&[0, 5, 2, 4, 9, 3],
)?,
- assignees: t.assignee.map(|a| vec![a]).unwrap_or_else(Vec::new),
+ assignees: t.assignee.map_or_else(Vec::new, |a| vec![a]),
description: t.description,
comments: Vec::new(),
version: Version::V1,
@@ -289,7 +297,9 @@ fn migrate() -> Result<()> {
Ok(())
}
-#[derive(Serialize, Deserialize)]
+#[derive(Serialize, Deserialize, Debug)]
+/// The fundamental type this tool revolves around. The ticket represents
+/// everything about an issue or future plan for the code base.
pub struct Ticket {
title: String,
status: Status,
@@ -300,15 +310,21 @@ pub struct Ticket {
version: Version,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Serialize, Deserialize, Debug)]
+/// Enum representing what version of the ticket it is and the assumptions that
+/// can be made about it
pub enum Version {
+ /// The first version
V1,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Serialize, Deserialize, Debug)]
+/// Newtype to represent a User or maintainer
pub struct User(String);
-#[derive(Serialize, Deserialize)]
+#[derive(Serialize, Deserialize, Debug)]
+/// Original version of the tickets on disk. This exists for historical reasons
+/// but is deprecated and likely to be removed.
pub struct TicketV0 {
title: String,
status: Status,
@@ -317,8 +333,11 @@ pub struct TicketV0 {
description: String,
}
-#[derive(Serialize, Deserialize)]
+#[derive(Serialize, Deserialize, Debug)]
+/// What is the current state of a ticket
pub enum Status {
+ /// The ticket has been opened but the issue has not been resolved
Open,
+ /// The ticket has a corresponding fix and has been closed
Closed,
}
diff --git a/ticket/src/tui.rs b/ticket/src/tui.rs
index e1aa666..01f00bf 100644
--- a/ticket/src/tui.rs
+++ b/ticket/src/tui.rs
@@ -130,8 +130,8 @@ pub struct Config {
}
impl Default for Config {
- fn default() -> Config {
- Config {
+ fn default() -> Self {
+ Self {
exit_key: Key::Char('q'),
tick_rate: Duration::from_millis(250),
}
@@ -139,11 +139,11 @@ impl Default for Config {
}
impl Events {
- pub fn new() -> Events {
- Events::with_config(Config::default())
+ pub fn new() -> Self {
+ Self::with_config(Config::default())
}
- pub fn with_config(config: Config) -> Events {
+ pub fn with_config(config: Config) -> Self {
let (tx, rx) = mpsc::channel();
let input_handle = {
let tx = tx.clone();
@@ -171,7 +171,7 @@ impl Events {
}
})
};
- Events {
+ Self {
rx,
input_handle,
tick_handle,
@@ -198,8 +198,8 @@ pub fn run() -> Result<()> {
tabs: TabsState::new(vec!["Open", "Closed"]),
tickets: {
let mut map = BTreeMap::new();
- map.insert("Open".into(), get_open_tickets()?);
- map.insert("Closed".into(), get_closed_tickets()?);
+ let _ = map.insert("Open".into(), get_open_tickets()?);
+ let _ = map.insert("Closed".into(), get_closed_tickets()?);
TicketState::new(map)
},
};