cargo fixes
This commit is contained in:
parent
1d8a70768f
commit
957c5b91bc
@ -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(())
|
||||
|
||||
*/
|
||||
}
|
||||
|
@ -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<User>) -> 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(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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: "<PASSWORD>".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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -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<Url, GeneralError> {
|
||||
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"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
pub(crate) mod action;
|
||||
pub mod client;
|
||||
pub mod issue;
|
||||
pub mod repository;
|
||||
pub(crate) mod action;
|
||||
|
@ -1,5 +1,5 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use crate::openproject::user::User;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Debug)]
|
||||
pub struct WorkPackageWriterAssignee {
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user