38 lines
1 KiB
Rust
38 lines
1 KiB
Rust
|
use crate::jira_config::JiraConfig;
|
||
|
use crate::types::issue::JiraIssue;
|
||
|
use reqwest::header::{HeaderMap, HeaderValue, CONTENT_TYPE};
|
||
|
use serde::Deserialize;
|
||
|
|
||
|
#[derive(Deserialize)]
|
||
|
pub struct JiraSearchResponse {
|
||
|
pub issues: Vec<JiraIssue>,
|
||
|
pub total: u32,
|
||
|
}
|
||
|
|
||
|
pub async fn run(
|
||
|
config: &JiraConfig,
|
||
|
jql: &str,
|
||
|
) -> Result<JiraSearchResponse, Box<dyn std::error::Error>> {
|
||
|
let client = reqwest::Client::new();
|
||
|
|
||
|
let mut headers = HeaderMap::new();
|
||
|
headers.insert(CONTENT_TYPE, HeaderValue::from_static("application/json"));
|
||
|
|
||
|
let query = [("jql", jql)];
|
||
|
|
||
|
let response = client
|
||
|
.get(format!("{}/rest/api/2/search", config.url))
|
||
|
.basic_auth(&config.email, Some(&config.api_token))
|
||
|
.headers(headers)
|
||
|
.query(&query)
|
||
|
.send()
|
||
|
.await?;
|
||
|
|
||
|
if !response.status().is_success() {
|
||
|
let error_text = response.text().await?;
|
||
|
return Err(format!("Failed to fetch issues: {}", error_text).into());
|
||
|
}
|
||
|
|
||
|
Ok(response.json::<JiraSearchResponse>().await?)
|
||
|
}
|