From e99d84f078ae6502e3cc13f9c27b554e0667c8bc Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Tue, 19 Mar 2024 17:13:49 -0500 Subject: [PATCH] Desyncs in progress --- src/client.rs | 2 +- src/main.rs | 5 +---- src/tasks.rs | 28 ++++++++++++++++++++++++---- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/client.rs b/src/client.rs index a5b51d6..a763863 100644 --- a/src/client.rs +++ b/src/client.rs @@ -4,7 +4,6 @@ use reqwest_middleware::{ClientBuilder, ClientWithMiddleware, RequestBuilder}; use reqwest_retry::{policies::ExponentialBackoff, RetryTransientMiddleware}; use reqwest_tracing::TracingMiddleware; use serde::de; -use tracing::debug; pub struct Client { client: ClientWithMiddleware, @@ -18,6 +17,7 @@ pub trait ResourceRequest { impl ResourceRequest for RequestBuilder { async fn res(self) -> Result { /* + use tracing::debug; let body = self.send().await?.text().await?; debug!(body); serde_json::from_str(&body).map_err(|e| e.into()) diff --git a/src/main.rs b/src/main.rs index 8b42b03..08313ed 100644 --- a/src/main.rs +++ b/src/main.rs @@ -37,9 +37,6 @@ async fn run() -> Result<()> { let gitlab_user = tasks.gitlab.me().await?; info!("{gitlab_user:#?}"); let jira_user = tasks.jira.me().await?; - info!("{jira_user:#?}"); - let issues = tasks.jira.assigned_open_issues().await?; - info!("{issues:#?}"); - info!("{}", issues.len()); + info!("{:?}", tasks.desyncs().await?); Ok(()) } diff --git a/src/tasks.rs b/src/tasks.rs index e6653cd..8c31f8d 100644 --- a/src/tasks.rs +++ b/src/tasks.rs @@ -1,6 +1,7 @@ use std::{collections::HashSet, env, process::Command}; use serde::{Deserialize, Serialize}; +use sled::IVec; use crate::{gitlab::GitLab, jira::Jira, result::Result}; @@ -28,6 +29,20 @@ pub struct Tasks { db: sled::Db, } +impl TryFrom for Task { + type Error = anyhow::Error; + + fn try_from(value: IVec) -> std::prelude::v1::Result { + serde_json::from_slice(&value).map_err(|e| e.into()) + } +} + +#[derive(Debug)] +pub struct Desyncs { + issues: Vec, + tasks: Vec, +} + impl Tasks { pub fn try_new() -> Result { let gl_token = env::var("GITLAB_TOKEN").or_else(|_| -> Result { @@ -53,15 +68,20 @@ impl Tasks { Ok(Self { gitlab, jira, db }) } - pub async fn all(&self) -> Result> { - Ok(vec![]) + pub fn all(&self) -> Result> { + self.db + .open_tree("tasks")? + .scan_prefix(&[]) + .map(|t| Task::try_from(t?.1)) + .collect::>>() } /// fetches jira issues and compares to known local tasks /// for use when sync'ing local tasks to remote state (jira, gitlab) - pub async fn desyncs(&self) -> Result<()> { + pub async fn desyncs(&self) -> Result { let issues = self.jira.assigned_open_issues().await?; + let tasks = self.all()?; - Ok(()) + Ok(Desyncs { issues, tasks }) } }