commit
184e2b8c7b
@ -0,0 +1 @@ |
||||
/target |
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,12 @@ |
||||
[package] |
||||
name = "Jira" |
||||
version = "0.1.0" |
||||
edition = "2021" |
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
||||
|
||||
[dependencies] |
||||
actix-web = "4.2.1" |
||||
reqwest = {version = "0.11.11", features = ["blocking"]} |
||||
serde_json = "1.0.85" |
||||
serde = { version = "1.0.144", features = ["derive"]} |
||||
@ -0,0 +1,49 @@ |
||||
use reqwest::{Client,Url}; |
||||
use reqwest::header::{HeaderMap, HeaderValue}; |
||||
use crate::structs; |
||||
|
||||
pub struct JiraClient<'a> { |
||||
http_client: Client, |
||||
basic_auth: (&'a str, &'a str), |
||||
base_url: &'a str |
||||
} |
||||
impl<'a> JiraClient<'a> { |
||||
pub fn new(base_url: &'a str, api_key: &'a str, user: &'a str) -> Self { |
||||
let mut headers = HeaderMap::new(); |
||||
headers.insert("Accept", HeaderValue::from_static("application/json")); |
||||
let client = Client::new(); |
||||
JiraClient { http_client: client, basic_auth: (user, api_key), base_url: base_url } |
||||
} |
||||
async fn get(&self, endpoint: String) -> Result<serde_json::Value, Box<dyn std::error::Error>>{ |
||||
let resp = self.http_client.get(endpoint) |
||||
.basic_auth(self.basic_auth.0, Some(self.basic_auth.1)) |
||||
.send().await?.text().await?; |
||||
let js: serde_json::Value = serde_json::from_str(&resp)?; |
||||
Ok(js) |
||||
} |
||||
|
||||
pub async fn get_issue(&self, issue_id: String) -> Result<serde_json::Value, Box<dyn std::error::Error>>{ |
||||
let endpoint = format!("{}/rest/api/3/issue/{}",self.base_url , issue_id); |
||||
self.get(endpoint).await |
||||
} |
||||
|
||||
pub async fn create_issue(&self, body_data: String) -> bool { |
||||
let endpoint = format!("{}/rest/api/3/issue",self.base_url); |
||||
let resp = self.http_client.post(endpoint) |
||||
.basic_auth(self.basic_auth.0, Some(self.basic_auth.1)) |
||||
.body(body_data) |
||||
.send().await; |
||||
resp.is_ok() |
||||
} |
||||
|
||||
pub async fn search_issue_with_jql(&self, jql_search : structs::JQLIssueSearch) -> Result<serde_json::Value, Box<dyn std::error::Error>> { |
||||
let endpoint = format!("{}/rest/api/3/search",self.base_url); |
||||
let resp = self.http_client.post(endpoint) |
||||
.basic_auth(self.basic_auth.0, Some(self.basic_auth.1)) |
||||
.body(serde_json::to_string(&jql_search).unwrap()) |
||||
.send().await?.text().await?; |
||||
let js: serde_json::Value = serde_json::from_str(&resp)?; |
||||
Ok(js) |
||||
} |
||||
} |
||||
|
||||
@ -0,0 +1,2 @@ |
||||
mod client; |
||||
pub mod structs; |
||||
@ -0,0 +1,35 @@ |
||||
use serde::{Deserialize, Serialize}; |
||||
use serde_json::Result; |
||||
use std::fs::File; |
||||
use std::io::BufReader; |
||||
use std::path::Path; |
||||
|
||||
#[derive(Debug, Serialize, Deserialize)] |
||||
pub struct JQLIssueSearch { |
||||
jql: String, |
||||
maxResults : usize, |
||||
fieldsByKeys : bool, |
||||
fields : Vec<String>, |
||||
startAt : usize, |
||||
expand : Option<Vec<String>>, |
||||
} |
||||
|
||||
impl JQLIssueSearch { |
||||
pub fn new(jql: String, fields: Vec<String>, mut fields_by_keys: Option<bool>,
|
||||
mut max_results: Option<usize>, mut start_at: Option<usize>, expand: Option<Vec<String>>) -> Self { |
||||
JQLIssueSearch { |
||||
jql, |
||||
fields, |
||||
fieldsByKeys : *fields_by_keys.get_or_insert(false), |
||||
maxResults: *max_results.get_or_insert(50), |
||||
startAt : *start_at.get_or_insert(0), |
||||
expand : expand |
||||
} |
||||
} |
||||
pub fn from_file(file_path: String) -> Self { |
||||
let file = File::open(file_path).unwrap(); |
||||
let reader = BufReader::new(file); |
||||
serde_json::from_reader(reader).unwrap() |
||||
} |
||||
} |
||||
|
||||
@ -0,0 +1,3 @@ |
||||
use serde::{Serialize, Deserialize}; |
||||
use serde_json::{Result,json}; |
||||
|
||||
Loading…
Reference in new issue