WIP regex

This commit is contained in:
Daniel Flanagan 2024-03-19 22:53:49 -05:00
parent e99d84f078
commit 1451ce8f11
3 changed files with 48 additions and 1 deletions

1
Cargo.lock generated
View file

@ -1325,6 +1325,7 @@ version = "0.1.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"color-eyre", "color-eyre",
"regex",
"reqwest", "reqwest",
"reqwest-middleware", "reqwest-middleware",
"reqwest-retry", "reqwest-retry",

View file

@ -8,6 +8,7 @@ edition = "2021"
[dependencies] [dependencies]
anyhow = "1.0.81" anyhow = "1.0.81"
color-eyre = "0.6.3" color-eyre = "0.6.3"
regex = "1.10.3"
reqwest = { version = "0.11.26", features = ["json", "socks"] } reqwest = { version = "0.11.26", features = ["json", "socks"] }
reqwest-middleware = "0.2.5" reqwest-middleware = "0.2.5"
reqwest-retry = "0.4.0" reqwest-retry = "0.4.0"

View file

@ -1,4 +1,5 @@
use std::{collections::HashSet, env, process::Command}; use std::{sync::OnceLock, collections::HashSet, env, process::Command};
use regex::Regex;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use sled::IVec; use sled::IVec;
@ -37,6 +38,14 @@ impl TryFrom<IVec> for Task {
} }
} }
impl TryInto<IVec> for &Task {
type Error = anyhow::Error;
fn try_into(self) -> std::prelude::v1::Result<IVec, Self::Error> {
Ok(IVec::from(serde_json::to_vec(self)?))
}
}
#[derive(Debug)] #[derive(Debug)]
pub struct Desyncs { pub struct Desyncs {
issues: Vec<crate::jira::Issue>, issues: Vec<crate::jira::Issue>,
@ -76,6 +85,42 @@ impl Tasks {
.collect::<Result<Vec<Task>>>() .collect::<Result<Vec<Task>>>()
} }
pub fn get(&self, key: &str) -> Result<Option<Task>> {
let ivec = self.db.open_tree("tasks")?.get(key)?;
match ivec {
Some(v) => Ok(Some(Task::try_from(v)?)),
None => Ok(None),
}
}
pub fn save(&self, task: &Task) -> Result<()> {
let ivec: IVec = task.try_into()?;
let _previous_value = self.db.open_tree("tasks")?.insert(&task.jira_key, ivec)?;
self.db.flush()?;
Ok(())
}
pub fn delete(&self, task: &Task) -> Result<()> {
let _previous_value = self.db.open_tree("tasks")?.remove(&task.jira_key)?;
self.db.flush()?;
Ok(())
}
pub fn purge_all(&self) -> Result<()> {
for t in self.all()? {
self.delete(&t)?;
}
self.db.flush()?;
Ok(())
}
pub fn cleanup(&self, task: &mut Task) -> Result<()> {
static RE: OnceLock<Regex> = OnceLock::new(|| Regex::new(r"^\s*\:[a-zA-Z0-9_-]+\:\s*").unwrap());
let mut changed = false;
t.description.match
Ok(())
}
/// fetches jira issues and compares to known local tasks /// fetches jira issues and compares to known local tasks
/// for use when sync'ing local tasks to remote state (jira, gitlab) /// for use when sync'ing local tasks to remote state (jira, gitlab)
pub async fn desyncs(&self) -> Result<Desyncs> { pub async fn desyncs(&self) -> Result<Desyncs> {