From 957c5b91bc20a2cbfbb347ffcafa5d3ac1315ea3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 25 Oct 2024 00:41:46 +0200 Subject: [PATCH] cargo fixes --- src/debug.rs | 5 ++++- src/gitea/action.rs | 25 ++++++++++--------------- src/gitea/client.rs | 18 +++++++++++++++--- src/gitea/issue.rs | 22 ++++++++++++++++++---- src/gitea/mod.rs | 2 +- src/openproject/work.rs | 2 +- src/planning/mod.rs | 2 -- 7 files changed, 49 insertions(+), 27 deletions(-) diff --git a/src/debug.rs b/src/debug.rs index 790abea..a579b01 100644 --- a/src/debug.rs +++ b/src/debug.rs @@ -19,8 +19,9 @@ pub(crate) async fn debug(config: Config) -> Result<(), GeneralError> { println!("issue: {:?}", issue); - return Ok(()); + Ok(()) + /* let open_project_client = Client::from_config(&config.openproject); println!("base_url: {}", open_project_client.base_url); println!("base_url: will get root"); @@ -30,4 +31,6 @@ pub(crate) async fn debug(config: Config) -> Result<(), GeneralError> { println!("me: {:?}", u); Ok(()) + + */ } diff --git a/src/gitea/action.rs b/src/gitea/action.rs index c93a473..7b2d71c 100644 --- a/src/gitea/action.rs +++ b/src/gitea/action.rs @@ -1,22 +1,21 @@ -use url::Url; use crate::cli::Issue2Work; use crate::config::Config; use crate::error::GeneralError; -use crate::gitea::issue::{issue_html_url_to_api, Issue}; use crate::gitea::client::has_client_for_url; +use crate::gitea::issue::{issue_html_url_to_api, Issue}; use crate::openproject::user::{GetMe, User}; -use crate::openproject::work::{WorkPackage, WorkPackageWriter, WorkPackageWriterAssignee}; +use crate::openproject::work::WorkPackageWriter; use crate::planning::Issue2WorkActionTrait; +use url::Url; pub(crate) struct GiteaAction {} impl Issue2WorkActionTrait for GiteaAction { async fn run(&self, url: &Url, config: &Config, args: &Issue2Work) -> Result<(), GeneralError> { let gitea_client = crate::gitea::client::Client::from_config(config.gitea.first().unwrap()); - let issue: Issue = gitea_client - .get(issue_html_url_to_api(url)?) - .await?; - let open_project_client = crate::openproject::client::Client::from_config(&config.openproject); + let issue: Issue = gitea_client.get(issue_html_url_to_api(url)?).await?; + let open_project_client = + crate::openproject::client::Client::from_config(&config.openproject); let work_package = create_work_package_from_issue( &issue, @@ -26,7 +25,7 @@ impl Issue2WorkActionTrait for GiteaAction { Some(u) } false => None, - } + }, ); let work_package = open_project_client @@ -48,16 +47,12 @@ impl Issue2WorkActionTrait for GiteaAction { fn create_work_package_from_issue(issue: &Issue, assignee: Option) -> WorkPackageWriter { WorkPackageWriter { - subject: format!( - "{} ({})", - issue.title, - issue.repository.full_name - ), + subject: format!("{} ({})", issue.title, issue.repository.full_name), work_type: "TASK".into(), description: crate::openproject::work::DescriptionWriter { format: "markdown".into(), raw: format!("From Gitea issue: {} \n\n{}", issue.html_url, issue.body), }, - assignee: assignee.into() + assignee: assignee.into(), } -} \ No newline at end of file +} diff --git a/src/gitea/client.rs b/src/gitea/client.rs index 65dc5f9..89c4424 100644 --- a/src/gitea/client.rs +++ b/src/gitea/client.rs @@ -1,4 +1,4 @@ -use crate::config::{Config, GiteaConfig, GitlabConfig}; +use crate::config::{Config, GiteaConfig}; use crate::error::GeneralError; use reqwest::header::{HeaderMap, ACCEPT, AUTHORIZATION}; use reqwest::{ClientBuilder, StatusCode}; @@ -92,7 +92,19 @@ mod test { token: "".into(), }; - assert_eq!(is_client_for_url(&Url::parse("https://gitea.champs-libres.be/something/somewhere").unwrap(), &config), true); - assert_eq!(is_client_for_url(&Url::parse("https://somewhere.else/something/somewhere").unwrap(), &config), false); + assert_eq!( + is_client_for_url( + &Url::parse("https://gitea.champs-libres.be/something/somewhere").unwrap(), + &config + ), + true + ); + assert_eq!( + is_client_for_url( + &Url::parse("https://somewhere.else/something/somewhere").unwrap(), + &config + ), + false + ); } } diff --git a/src/gitea/issue.rs b/src/gitea/issue.rs index e087049..63ab1c8 100644 --- a/src/gitea/issue.rs +++ b/src/gitea/issue.rs @@ -1,8 +1,8 @@ +use crate::error::GeneralError; use crate::gitea::client::Client; use crate::gitea::repository::Repository; use serde::Deserialize; use url::Url; -use crate::error::GeneralError; #[derive(Debug, Deserialize)] pub struct Issue { @@ -31,13 +31,24 @@ pub fn issue_html_url_to_api(url: &Url) -> Result { let issue = parts.next().unwrap(); let iid = parts.next().unwrap(); - if (!issue.eq("issues")) { + if !issue.eq("issues") { return Err(GeneralError { description: format!("Issue url is not valid: {}", url), }); } - let url = Url::parse(format!("{}://{}/api/v1/repos/{}/{}/issues/{}", url.scheme(), url.host().unwrap(), domain, repo, iid).as_str()).unwrap(); + let url = Url::parse( + format!( + "{}://{}/api/v1/repos/{}/{}/issues/{}", + url.scheme(), + url.host().unwrap(), + domain, + repo, + iid + ) + .as_str(), + ) + .unwrap(); Ok(url) } @@ -51,6 +62,9 @@ mod tests { let url = Url::parse("https://gitea.champs-libres.be/champs-libres/test/issues/1").unwrap(); let result = issue_html_url_to_api(&url).unwrap(); - assert_eq!(result.as_str(), "https://gitea.champs-libres.be/api/v1/repos/champs-libres/test/issues/1"); + assert_eq!( + result.as_str(), + "https://gitea.champs-libres.be/api/v1/repos/champs-libres/test/issues/1" + ); } } diff --git a/src/gitea/mod.rs b/src/gitea/mod.rs index 32c6c76..f729d5e 100644 --- a/src/gitea/mod.rs +++ b/src/gitea/mod.rs @@ -1,4 +1,4 @@ +pub(crate) mod action; pub mod client; pub mod issue; pub mod repository; -pub(crate) mod action; diff --git a/src/openproject/work.rs b/src/openproject/work.rs index 5520698..b1a9980 100644 --- a/src/openproject/work.rs +++ b/src/openproject/work.rs @@ -1,5 +1,5 @@ -use serde::{Deserialize, Serialize}; use crate::openproject::user::User; +use serde::{Deserialize, Serialize}; #[derive(Serialize, Debug)] pub struct WorkPackageWriterAssignee { diff --git a/src/planning/mod.rs b/src/planning/mod.rs index 23561e9..55261ba 100644 --- a/src/planning/mod.rs +++ b/src/planning/mod.rs @@ -1,8 +1,6 @@ use crate::cli::Issue2Work; use crate::config::Config; use crate::error::GeneralError; -use crate::gitlab::client::ClientProvider; -use gitlab::{AsyncGitlab, GitlabBuilder}; use url::Url; pub(crate) mod issue2work;