Desyncs in progress

This commit is contained in:
Daniel Flanagan 2024-03-19 17:13:49 -05:00
parent 1bcdcda955
commit e99d84f078
3 changed files with 26 additions and 9 deletions

View file

@ -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<T: de::DeserializeOwned>(self) -> Result<T> {
/*
use tracing::debug;
let body = self.send().await?.text().await?;
debug!(body);
serde_json::from_str(&body).map_err(|e| e.into())

View file

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

View file

@ -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<IVec> for Task {
type Error = anyhow::Error;
fn try_from(value: IVec) -> std::prelude::v1::Result<Self, Self::Error> {
serde_json::from_slice(&value).map_err(|e| e.into())
}
}
#[derive(Debug)]
pub struct Desyncs {
issues: Vec<crate::jira::Issue>,
tasks: Vec<Task>,
}
impl Tasks {
pub fn try_new() -> Result<Self> {
let gl_token = env::var("GITLAB_TOKEN").or_else(|_| -> Result<String> {
@ -53,15 +68,20 @@ impl Tasks {
Ok(Self { gitlab, jira, db })
}
pub async fn all(&self) -> Result<Vec<Task>> {
Ok(vec![])
pub fn all(&self) -> Result<Vec<Task>> {
self.db
.open_tree("tasks")?
.scan_prefix(&[])
.map(|t| Task::try_from(t?.1))
.collect::<Result<Vec<Task>>>()
}
/// 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<Desyncs> {
let issues = self.jira.assigned_open_issues().await?;
let tasks = self.all()?;
Ok(())
Ok(Desyncs { issues, tasks })
}
}