chore: log Tuleap HTTP calls for debugging
This commit is contained in:
parent
1709905064
commit
c2636f86c7
1 changed files with 37 additions and 21 deletions
|
|
@ -1,4 +1,5 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use std::time::Instant;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct TrackerField {
|
||||
|
|
@ -31,16 +32,43 @@ impl TuleapClient {
|
|||
}
|
||||
}
|
||||
|
||||
async fn send_get(&self, url: &str) -> Result<reqwest::Response, String> {
|
||||
let started_at = Instant::now();
|
||||
eprintln!("[tuleap] -> GET {}", url);
|
||||
|
||||
let response = self
|
||||
.http
|
||||
.get(url)
|
||||
.basic_auth(&self.username, Some(&self.password))
|
||||
.send()
|
||||
.await;
|
||||
|
||||
match response {
|
||||
Ok(resp) => {
|
||||
eprintln!(
|
||||
"[tuleap] <- GET {} | status={} | {}ms",
|
||||
url,
|
||||
resp.status(),
|
||||
started_at.elapsed().as_millis()
|
||||
);
|
||||
Ok(resp)
|
||||
}
|
||||
Err(err) => {
|
||||
eprintln!(
|
||||
"[tuleap] xx GET {} | error={} | {}ms",
|
||||
url,
|
||||
err,
|
||||
started_at.elapsed().as_millis()
|
||||
);
|
||||
Err(format!("request failed: {}", err))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub async fn test_connection(&self) -> Result<(), String> {
|
||||
let url = format!("{}/api/projects?limit=1", self.base_url);
|
||||
let resp = self
|
||||
.http
|
||||
.get(&url)
|
||||
.basic_auth(&self.username, Some(&self.password))
|
||||
.send()
|
||||
.await
|
||||
.map_err(|e| format!("request failed: {}", e))?;
|
||||
let resp = self.send_get(&url).await?;
|
||||
|
||||
if resp.status().is_success() {
|
||||
Ok(())
|
||||
|
|
@ -51,13 +79,7 @@ impl TuleapClient {
|
|||
|
||||
pub async fn get_tracker_fields(&self, tracker_id: i32) -> Result<Vec<TrackerField>, String> {
|
||||
let url = format!("{}/api/trackers/{}", self.base_url, tracker_id);
|
||||
let resp = self
|
||||
.http
|
||||
.get(&url)
|
||||
.basic_auth(&self.username, Some(&self.password))
|
||||
.send()
|
||||
.await
|
||||
.map_err(|e| format!("request failed: {}", e))?;
|
||||
let resp = self.send_get(&url).await?;
|
||||
|
||||
if !resp.status().is_success() {
|
||||
return Err(format!("get tracker fields failed: HTTP {}", resp.status()));
|
||||
|
|
@ -81,13 +103,7 @@ impl TuleapClient {
|
|||
"{}/api/trackers/{}/artifacts?values=all&limit={}&offset={}",
|
||||
self.base_url, tracker_id, limit, offset
|
||||
);
|
||||
let resp = self
|
||||
.http
|
||||
.get(&url)
|
||||
.basic_auth(&self.username, Some(&self.password))
|
||||
.send()
|
||||
.await
|
||||
.map_err(|e| format!("request failed: {}", e))?;
|
||||
let resp = self.send_get(&url).await?;
|
||||
|
||||
if !resp.status().is_success() {
|
||||
return Err(format!("get artifacts failed: HTTP {}", resp.status()));
|
||||
|
|
|
|||
Loading…
Reference in a new issue