Compare commits

...

4 Commits

Author SHA1 Message Date
ab0df54893
release 0.2.0
Some checks failed
Release binary for cl-cli / build-and-release (push) Failing after 1m57s
2024-11-14 14:22:56 +01:00
7b6cc33ecb
Refactor Gitea client and improve issue handling
Update the authorization header format in the Gitea client. Enhance issue details in work package creation and make `number` field public in the `Issue` struct.
2024-11-14 14:22:39 +01:00
696fd15cfa
cargo fixes 2024-10-25 00:42:23 +02:00
957c5b91bc
cargo fixes 2024-10-25 00:41:46 +02:00
11 changed files with 62 additions and 39 deletions

View File

@ -1,4 +0,0 @@
kind: Added
body: Add an option `--assign-to-me` to automatically assign the openproject's user
to the newly created work package
time: 2024-03-17T21:35:42.724855046+01:00

View File

@ -1,3 +0,0 @@
kind: Added
body: Allow to configure multiple gitlab instances
time: 2024-03-17T21:35:56.447907065+01:00

5
.changes/v0.2.0.md Normal file
View File

@ -0,0 +1,5 @@
## v0.2.0 - 2024-11-14
### Added
* Add an option `--assign-to-me` to automatically assign the openproject's user to the newly created work package
* Allow to configure multiple gitlab instances
* Create work pakcage from gitea

View File

@ -6,6 +6,12 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html),
and is generated by [Changie](https://github.com/miniscruff/changie).
## v0.2.0 - 2024-11-14
### Added
* Add an option `--assign-to-me` to automatically assign the openproject's user to the newly created work package
* Allow to configure multiple gitlab instances
* Create work pakcage from gitea
## v0.1.0 - 2024-01-08
### Added
* Initiate changie versioning

View File

@ -1,9 +1,6 @@
use crate::config::Config;
use crate::error::GeneralError;
use crate::gitea::issue::Issue;
use crate::openproject::client::Client;
use crate::openproject::root::RootClient;
use crate::openproject::user::GetMe;
use url::Url;
pub(crate) async fn debug(config: Config) -> Result<(), GeneralError> {
@ -19,8 +16,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 +28,6 @@ pub(crate) async fn debug(config: Config) -> Result<(), GeneralError> {
println!("me: {:?}", u);
Ok(())
*/
}

View File

@ -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, issue.number),
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(),
}
}
}

View File

@ -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};
@ -54,7 +54,7 @@ impl Client {
pub async fn get<T: DeserializeOwned>(&self, url: Url) -> Result<T, GeneralError> {
let mut headers = HeaderMap::new();
headers.append(AUTHORIZATION, self.token.parse()?);
headers.append(AUTHORIZATION, format!("token {}", self.token).parse()?);
headers.append(ACCEPT, "application/json".parse()?);
let client = ClientBuilder::new()
@ -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
);
}
}

View File

@ -1,13 +1,13 @@
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 {
pub id: u64,
number: u64,
pub number: u64,
pub title: String,
pub body: String,
pub repository: Repository,
@ -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"
);
}
}

View File

@ -1,4 +1,4 @@
pub(crate) mod action;
pub mod client;
pub mod issue;
pub mod repository;
pub(crate) mod action;

View File

@ -1,5 +1,5 @@
use serde::{Deserialize, Serialize};
use crate::openproject::user::User;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Debug)]
pub struct WorkPackageWriterAssignee {

View File

@ -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;