write workpackage on openproject
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
use crate::cli::Issue2Work;
|
||||
use crate::config::Config;
|
||||
use gitlab::{Gitlab, Issue};
|
||||
use gitlab::api::{Query, issues};
|
||||
use crate::openproject::client::Client;
|
||||
use gitlab::{ GitlabBuilder, Issue, Project};
|
||||
use gitlab::api::{issues, AsyncQuery, projects};
|
||||
use url::Url;
|
||||
use crate::error::GeneralError;
|
||||
use crate::gitlab::issue::IssueBundle;
|
||||
|
||||
#[derive(Debug)]
|
||||
struct IssueInfo {
|
||||
@@ -10,22 +13,39 @@ struct IssueInfo {
|
||||
iid: u64,
|
||||
}
|
||||
|
||||
pub(crate) fn issue2work(config: Config, args: &Issue2Work) {
|
||||
pub(crate) async fn issue2work(config: Config, args: &Issue2Work) -> Result<(), GeneralError> {
|
||||
let url = Url::parse(&*args.issue_url)
|
||||
.expect("issue_url is not valid");
|
||||
let data = extract_issue_info(&url).unwrap();
|
||||
|
||||
let client = Gitlab::new("gitlab.com", config.gitlab.token).unwrap();
|
||||
let client = GitlabBuilder::new("gitlab.com", config.gitlab.token).build_async().await?;
|
||||
|
||||
let endpoint = issues::ProjectIssues::builder()
|
||||
.iid(data.iid)
|
||||
.project(String::from(data.project))
|
||||
.build()
|
||||
.unwrap()
|
||||
;
|
||||
|
||||
let issues: Vec<Issue> = endpoint.query_async(&client).await.unwrap();
|
||||
let issue = issues.first().unwrap();
|
||||
|
||||
let project_endpoint = projects::Project::builder()
|
||||
.project(issue.project_id.value())
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
let issue: Vec<Issue> = endpoint.query(&client).unwrap();
|
||||
let project: Project = project_endpoint.query_async(&client).await.unwrap();
|
||||
|
||||
println!("{:?}", issue.first());
|
||||
let issue_bundle = IssueBundle::new(&issue, &project);
|
||||
|
||||
let open_project_client = Client::from_config(&config.openproject);
|
||||
|
||||
let work_package = open_project_client.create_work_package(&(&issue_bundle).into(), &args.project_id).await?;
|
||||
|
||||
println!("new work package created: {:?}, edit at {}/projects/{}/work_packages/{}", work_package.subject, config.openproject.base_url, args.project_id, work_package.id);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn extract_issue_info(url: &Url) -> Option<IssueInfo> {
|
||||
|
||||
Reference in New Issue
Block a user