Work on task sorting

This commit is contained in:
Daniel Flanagan 2024-03-20 12:20:20 -05:00
parent 6e6e86da98
commit d2e3c60bb4
4 changed files with 58 additions and 14 deletions

View file

@ -44,7 +44,9 @@ pub struct Priority {
#[derive(Deserialize, Debug)] #[derive(Deserialize, Debug)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct IssueStatusCategory { pub struct IssueStatusCategory {
pub id: u64,
pub key: String, pub key: String,
pub name: String,
} }
#[derive(Deserialize, Debug)] #[derive(Deserialize, Debug)]

View file

@ -33,13 +33,21 @@ async fn main() -> Result<()> {
} }
async fn run() -> Result<()> { async fn run() -> Result<()> {
let t = Tasks::try_new()?;
// print!("{ANSI_CLEAR}"); // print!("{ANSI_CLEAR}");
// let gitlab_user = tasks.gitlab.me().await?; // let gitlab_user = tasks.gitlab.me().await?;
// info!("{gitlab_user:#?}"); // info!("{gitlab_user:#?}");
// let jira_user = tasks.jira.me().await?; // let jira_user = tasks.jira.me().await?;
// info!("{:?}", tasks.sync().await?); // tasks.purge_all()?;
let tasks = Tasks::try_new()?; let tasks = t.all()?;
for t in tasks.all()?.values() {
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); info!("{}", t);
} }
Ok(()) Ok(())

View file

@ -1,17 +1,17 @@
use std::{collections::HashSet, fmt::Display}; use std::{cmp::Ordering, collections::HashSet, fmt::Display};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use sled::IVec; use sled::IVec;
use crate::jira::Issue; use crate::jira::Issue;
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug, PartialEq, Eq)]
pub struct MergeRequestRef { pub struct MergeRequestRef {
pub url: String, pub url: String,
pub state: String, pub state: String,
} }
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug, PartialEq, Eq)]
pub struct Task { pub struct Task {
pub jira_key: String, pub jira_key: String,
pub description: String, pub description: String,
@ -22,6 +22,29 @@ pub struct Task {
pub tags: HashSet<String>, pub tags: HashSet<String>,
} }
const STATUS_PRIORITY: [&str; 4] = ["Blocked", "InProgress", "DevReady", "Backlog"];
impl PartialOrd for Task {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
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 { impl Display for Task {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let Self { let Self {
@ -33,7 +56,9 @@ impl Display for Task {
status, status,
tags, tags,
} = self; } = 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![], merge_requests: vec![],
jira_priority: value.fields.priority.id.parse()?, jira_priority: value.fields.priority.id.parse()?,
local_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, tags,
}) })
} }

View file

@ -6,7 +6,7 @@ use std::{
process::Command, process::Command,
sync::OnceLock, sync::OnceLock,
}; };
use tracing::info; use tracing::{info, warn};
use crate::task::Task; use crate::task::Task;
@ -89,6 +89,7 @@ impl Tasks {
} }
pub fn purge_all(&self) -> Result<()> { pub fn purge_all(&self) -> Result<()> {
warn!("Purging all local tasks...");
for (_, t) in self.all()? { for (_, t) in self.all()? {
self.delete(&t)?; 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 regex = RE.get_or_init(|| Regex::new(r"^\s*\:[a-zA-Z0-9_-]+\:\s*").unwrap());
let mut changed = false; let mut changed = false;
if let Some(m) = regex.find(&task.description) { 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; changed = true;
} }
if changed { if changed {
@ -141,16 +150,16 @@ impl Tasks {
.map(|s| s.to_owned()), .map(|s| s.to_owned()),
); );
info!("Creating new tasks from issues without a task");
for key in issue_keys.difference(&task_keys) { for key in issue_keys.difference(&task_keys) {
let issue = issues.get(key).unwrap(); let issue = issues.get(key).unwrap();
let mut task: Task = issue.try_into()?; let mut task: Task = issue.try_into()?;
self.cleanup(&mut task); self.cleanup(&mut task)?;
self.save(&task); self.save(&task)?;
info!("Created task {}", task);
tasks.insert(task.jira_key.clone(), task); tasks.insert(task.jira_key.clone(), task);
} }
info!("Creating new tasks from issues without a task");
// TODO: blocking? maybe should be async? // TODO: blocking? maybe should be async?
// while let Ok(_res) = rx.recv() { // while let Ok(_res) = rx.recv() {
// awaiting all the tasks in the joinset // awaiting all the tasks in the joinset