Compare commits
4 Commits
1d8a70768f
...
ab0df54893
Author | SHA1 | Date | |
---|---|---|---|
ab0df54893 | |||
7b6cc33ecb | |||
696fd15cfa | |||
957c5b91bc |
@ -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
|
|
@ -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
5
.changes/v0.2.0.md
Normal 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
|
@ -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).
|
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
|
## v0.1.0 - 2024-01-08
|
||||||
### Added
|
### Added
|
||||||
* Initiate changie versioning
|
* Initiate changie versioning
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
use crate::error::GeneralError;
|
use crate::error::GeneralError;
|
||||||
use crate::gitea::issue::Issue;
|
use crate::gitea::issue::Issue;
|
||||||
use crate::openproject::client::Client;
|
|
||||||
use crate::openproject::root::RootClient;
|
|
||||||
use crate::openproject::user::GetMe;
|
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
pub(crate) async fn debug(config: Config) -> Result<(), GeneralError> {
|
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);
|
println!("issue: {:?}", issue);
|
||||||
|
|
||||||
return Ok(());
|
Ok(())
|
||||||
|
|
||||||
|
/*
|
||||||
let open_project_client = Client::from_config(&config.openproject);
|
let open_project_client = Client::from_config(&config.openproject);
|
||||||
println!("base_url: {}", open_project_client.base_url);
|
println!("base_url: {}", open_project_client.base_url);
|
||||||
println!("base_url: will get root");
|
println!("base_url: will get root");
|
||||||
@ -30,4 +28,6 @@ pub(crate) async fn debug(config: Config) -> Result<(), GeneralError> {
|
|||||||
println!("me: {:?}", u);
|
println!("me: {:?}", u);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
@ -1,22 +1,21 @@
|
|||||||
use url::Url;
|
|
||||||
use crate::cli::Issue2Work;
|
use crate::cli::Issue2Work;
|
||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
use crate::error::GeneralError;
|
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::client::has_client_for_url;
|
||||||
|
use crate::gitea::issue::{issue_html_url_to_api, Issue};
|
||||||
use crate::openproject::user::{GetMe, User};
|
use crate::openproject::user::{GetMe, User};
|
||||||
use crate::openproject::work::{WorkPackage, WorkPackageWriter, WorkPackageWriterAssignee};
|
use crate::openproject::work::WorkPackageWriter;
|
||||||
use crate::planning::Issue2WorkActionTrait;
|
use crate::planning::Issue2WorkActionTrait;
|
||||||
|
use url::Url;
|
||||||
|
|
||||||
pub(crate) struct GiteaAction {}
|
pub(crate) struct GiteaAction {}
|
||||||
|
|
||||||
impl Issue2WorkActionTrait for GiteaAction {
|
impl Issue2WorkActionTrait for GiteaAction {
|
||||||
async fn run(&self, url: &Url, config: &Config, args: &Issue2Work) -> Result<(), GeneralError> {
|
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 gitea_client = crate::gitea::client::Client::from_config(config.gitea.first().unwrap());
|
||||||
let issue: Issue = gitea_client
|
let issue: Issue = gitea_client.get(issue_html_url_to_api(url)?).await?;
|
||||||
.get(issue_html_url_to_api(url)?)
|
let open_project_client =
|
||||||
.await?;
|
crate::openproject::client::Client::from_config(&config.openproject);
|
||||||
let open_project_client = crate::openproject::client::Client::from_config(&config.openproject);
|
|
||||||
|
|
||||||
let work_package = create_work_package_from_issue(
|
let work_package = create_work_package_from_issue(
|
||||||
&issue,
|
&issue,
|
||||||
@ -26,7 +25,7 @@ impl Issue2WorkActionTrait for GiteaAction {
|
|||||||
Some(u)
|
Some(u)
|
||||||
}
|
}
|
||||||
false => None,
|
false => None,
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
let work_package = open_project_client
|
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 {
|
fn create_work_package_from_issue(issue: &Issue, assignee: Option<User>) -> WorkPackageWriter {
|
||||||
WorkPackageWriter {
|
WorkPackageWriter {
|
||||||
subject: format!(
|
subject: format!("{} ({}/{})", issue.title, issue.repository.full_name, issue.number),
|
||||||
"{} ({})",
|
|
||||||
issue.title,
|
|
||||||
issue.repository.full_name
|
|
||||||
),
|
|
||||||
work_type: "TASK".into(),
|
work_type: "TASK".into(),
|
||||||
description: crate::openproject::work::DescriptionWriter {
|
description: crate::openproject::work::DescriptionWriter {
|
||||||
format: "markdown".into(),
|
format: "markdown".into(),
|
||||||
raw: format!("From Gitea issue: {} \n\n{}", issue.html_url, issue.body),
|
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 crate::error::GeneralError;
|
||||||
use reqwest::header::{HeaderMap, ACCEPT, AUTHORIZATION};
|
use reqwest::header::{HeaderMap, ACCEPT, AUTHORIZATION};
|
||||||
use reqwest::{ClientBuilder, StatusCode};
|
use reqwest::{ClientBuilder, StatusCode};
|
||||||
@ -54,7 +54,7 @@ impl Client {
|
|||||||
|
|
||||||
pub async fn get<T: DeserializeOwned>(&self, url: Url) -> Result<T, GeneralError> {
|
pub async fn get<T: DeserializeOwned>(&self, url: Url) -> Result<T, GeneralError> {
|
||||||
let mut headers = HeaderMap::new();
|
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()?);
|
headers.append(ACCEPT, "application/json".parse()?);
|
||||||
|
|
||||||
let client = ClientBuilder::new()
|
let client = ClientBuilder::new()
|
||||||
@ -92,7 +92,19 @@ mod test {
|
|||||||
token: "<PASSWORD>".into(),
|
token: "<PASSWORD>".into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
assert_eq!(is_client_for_url(&Url::parse("https://gitea.champs-libres.be/something/somewhere").unwrap(), &config), true);
|
assert_eq!(
|
||||||
assert_eq!(is_client_for_url(&Url::parse("https://somewhere.else/something/somewhere").unwrap(), &config), false);
|
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,13 +1,13 @@
|
|||||||
|
use crate::error::GeneralError;
|
||||||
use crate::gitea::client::Client;
|
use crate::gitea::client::Client;
|
||||||
use crate::gitea::repository::Repository;
|
use crate::gitea::repository::Repository;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
use crate::error::GeneralError;
|
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
pub struct Issue {
|
pub struct Issue {
|
||||||
pub id: u64,
|
pub id: u64,
|
||||||
number: u64,
|
pub number: u64,
|
||||||
pub title: String,
|
pub title: String,
|
||||||
pub body: String,
|
pub body: String,
|
||||||
pub repository: Repository,
|
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 issue = parts.next().unwrap();
|
||||||
let iid = parts.next().unwrap();
|
let iid = parts.next().unwrap();
|
||||||
|
|
||||||
if (!issue.eq("issues")) {
|
if !issue.eq("issues") {
|
||||||
return Err(GeneralError {
|
return Err(GeneralError {
|
||||||
description: format!("Issue url is not valid: {}", url),
|
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)
|
Ok(url)
|
||||||
}
|
}
|
||||||
@ -51,6 +62,9 @@ mod tests {
|
|||||||
let url = Url::parse("https://gitea.champs-libres.be/champs-libres/test/issues/1").unwrap();
|
let url = Url::parse("https://gitea.champs-libres.be/champs-libres/test/issues/1").unwrap();
|
||||||
let result = issue_html_url_to_api(&url).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 client;
|
||||||
pub mod issue;
|
pub mod issue;
|
||||||
pub mod repository;
|
pub mod repository;
|
||||||
pub(crate) mod action;
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use crate::openproject::user::User;
|
use crate::openproject::user::User;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Serialize, Debug)]
|
#[derive(Serialize, Debug)]
|
||||||
pub struct WorkPackageWriterAssignee {
|
pub struct WorkPackageWriterAssignee {
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
use crate::cli::Issue2Work;
|
use crate::cli::Issue2Work;
|
||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
use crate::error::GeneralError;
|
use crate::error::GeneralError;
|
||||||
use crate::gitlab::client::ClientProvider;
|
|
||||||
use gitlab::{AsyncGitlab, GitlabBuilder};
|
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
pub(crate) mod issue2work;
|
pub(crate) mod issue2work;
|
||||||
|
Loading…
Reference in New Issue
Block a user