diff --git a/src/jira.rs b/src/jira.rs index 6b329ec..bf55933 100644 --- a/src/jira.rs +++ b/src/jira.rs @@ -44,7 +44,9 @@ pub struct Priority { #[derive(Deserialize, Debug)] #[serde(rename_all = "camelCase")] pub struct IssueStatusCategory { + pub id: u64, pub key: String, + pub name: String, } #[derive(Deserialize, Debug)] diff --git a/src/main.rs b/src/main.rs index 7b8481e..b06d01f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -33,13 +33,21 @@ async fn main() -> Result<()> { } async fn run() -> Result<()> { + let t = Tasks::try_new()?; + // print!("{ANSI_CLEAR}"); // let gitlab_user = tasks.gitlab.me().await?; // info!("{gitlab_user:#?}"); // let jira_user = tasks.jira.me().await?; - // info!("{:?}", tasks.sync().await?); - let tasks = Tasks::try_new()?; - for t in tasks.all()?.values() { + // tasks.purge_all()?; + let tasks = t.all()?; + + if tasks.len() < 1 { + info!("{:?}", t.sync().await?); + } + let mut vtasks: Vec<&task::Task> = tasks.values().collect(); + vtasks.sort_unstable(); + for t in vtasks { info!("{}", t); } Ok(()) diff --git a/src/task.rs b/src/task.rs index c315e84..308d604 100644 --- a/src/task.rs +++ b/src/task.rs @@ -1,17 +1,17 @@ -use std::{collections::HashSet, fmt::Display}; +use std::{cmp::Ordering, collections::HashSet, fmt::Display}; use serde::{Deserialize, Serialize}; use sled::IVec; use crate::jira::Issue; -#[derive(Serialize, Deserialize, Debug)] +#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)] pub struct MergeRequestRef { pub url: String, pub state: String, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)] pub struct Task { pub jira_key: String, pub description: String, @@ -22,6 +22,29 @@ pub struct Task { pub tags: HashSet, } +const STATUS_PRIORITY: [&str; 4] = ["Blocked", "InProgress", "DevReady", "Backlog"]; + +impl PartialOrd for Task { + fn partial_cmp(&self, other: &Self) -> Option { + if self.eq(other) { + return Some(Ordering::Equal); + } + let a = STATUS_PRIORITY.iter().position(self.status); + let b = STATUS_PRIORITY.iter().position(other.status); + if Some(o) = a.partial_cmp(b) { + if o != Ordering::Equal { + return o; + } + } + } +} + +// impl Ord for Task { +// fn cmp(&self, other: &Self) -> std::cmp::Ordering { +// todo!() +// } +// } + impl Display for Task { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let Self { @@ -33,7 +56,9 @@ impl Display for Task { status, tags, } = self; - f.write_fmt(format_args!("{jira_key}: {status} {description}",)) + f.write_fmt(format_args!( + "{jira_key}: <{status}> {description} [p{jira_priority}]", + )) } } @@ -69,7 +94,7 @@ impl TryFrom<&Issue> for Task { merge_requests: vec![], jira_priority: value.fields.priority.id.parse()?, local_priority: value.fields.priority.id.parse()?, - status: value.fields.status.status_category.key.to_owned(), + status: value.fields.status.name.to_owned(), tags, }) } diff --git a/src/tasks.rs b/src/tasks.rs index f141dfe..1dd3c1e 100644 --- a/src/tasks.rs +++ b/src/tasks.rs @@ -6,7 +6,7 @@ use std::{ process::Command, sync::OnceLock, }; -use tracing::info; +use tracing::{info, warn}; use crate::task::Task; @@ -89,6 +89,7 @@ impl Tasks { } pub fn purge_all(&self) -> Result<()> { + warn!("Purging all local tasks..."); for (_, t) in self.all()? { self.delete(&t)?; } @@ -101,7 +102,15 @@ impl Tasks { let regex = RE.get_or_init(|| Regex::new(r"^\s*\:[a-zA-Z0-9_-]+\:\s*").unwrap()); let mut changed = false; if let Some(m) = regex.find(&task.description) { - task.description = task.description[..m.range().end].to_owned(); + task.description = task.description[m.range().end..].to_owned(); + changed = true; + } + if task.status.starts_with("Blocked") { + task.status = "Blocked".to_owned(); + changed = true; + } + if task.status.starts_with("In Development") { + task.status = "InProgress".to_owned(); changed = true; } if changed { @@ -141,16 +150,16 @@ impl Tasks { .map(|s| s.to_owned()), ); + info!("Creating new tasks from issues without a task"); for key in issue_keys.difference(&task_keys) { let issue = issues.get(key).unwrap(); let mut task: Task = issue.try_into()?; - self.cleanup(&mut task); - self.save(&task); + self.cleanup(&mut task)?; + self.save(&task)?; + info!("Created task {}", task); tasks.insert(task.jira_key.clone(), task); } - info!("Creating new tasks from issues without a task"); - // TODO: blocking? maybe should be async? // while let Ok(_res) = rx.recv() { // awaiting all the tasks in the joinset