use crate::config::Config;
use http::Method;
use reqwest::{header::HeaderMap, Client, RequestBuilder};
use serde::Serialize;
use serde_json::Value;
use std::collections::HashMap;
pub struct JiraClient {
client: Client,
config: Config,
}
impl JiraClient {
pub fn new(config: Config) -> Self {
let mut headers = HeaderMap::new();
headers.insert("Content-Type", "application/json".parse().unwrap());
let client = Client::builder().default_headers(headers).build().unwrap();
Self { client, config }
}
pub fn get_client(&self) -> &Client {
&self.client
}
pub fn get_config(&self) -> &Config {
&self.config
}
pub fn init_request(&self, method_str: &str, endpoint: &str) -> RequestBuilder {
let method_str_ucase = method_str.to_uppercase();
let method = method_str_ucase.as_bytes();
let url = format!("{}{}", self.config.jira_url, endpoint);
self
.client
.request(Method::from_bytes(method).unwrap(), &url)
.basic_auth(&self.config.jira_user, Some(&self.config.jira_password))
}
}
#[derive(Debug, Serialize)]
pub struct JiraIssue {
pub update: Option<HashMap<String, HashMap<String, Vec<String>>>>,
pub fields: Value,
}