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)]
#[serde(rename_all = "camelCase")]
pub struct IssueStatusCategory {
pub id: u64,
pub key: String,
pub name: String,
}
#[derive(Deserialize, Debug)]

View file

@ -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(())

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 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<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 {
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,
})
}

View file

@ -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