(&self, op: &'static str, body: &Req)
| 224 | } |
| 225 | |
| 226 | async fn post_json<Req, Resp>(&self, op: &'static str, body: &Req) -> Result<Resp> |
| 227 | where |
| 228 | Req: Serialize + ?Sized, |
| 229 | Resp: for<'de> Deserialize<'de>, |
| 230 | { |
| 231 | let url = self.endpoint(op); |
| 232 | let mut req = self.http.post(&url).json(body); |
| 233 | if let Some(token) = self.bearer_token.as_deref() { |
| 234 | if !token.is_empty() { |
| 235 | req = req.bearer_auth(token); |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | let start = std::time::Instant::now(); |
| 240 | let send_result = req.send().await; |
| 241 | let status_code = send_result.as_ref().ok().map(|r| r.status().as_u16()); |
| 242 | let ok = matches!(send_result.as_ref(), Ok(r) if r.status().is_success()); |
| 243 | emit_remote_git_event(op, &self.repo_id, status_code, ok, start.elapsed(), None); |
| 244 | |
| 245 | let resp = |
| 246 | send_result.map_err(|e| anyhow!("remote git call '{}' transport error: {}", op, e))?; |
| 247 | |
| 248 | let status = resp.status(); |
| 249 | if status.is_success() { |
| 250 | let parsed = resp |
| 251 | .json::<Resp>() |
| 252 | .await |
| 253 | .map_err(|e| anyhow!("remote git '{}' response body decode error: {}", op, e))?; |
| 254 | return Ok(parsed); |
| 255 | } |
| 256 | |
| 257 | let body_text = resp.text().await.unwrap_or_default(); |
| 258 | Err(map_error_response(op, status, &body_text)) |
| 259 | } |
| 260 | |
| 261 | async fn post_unit<Req>(&self, op: &'static str, body: &Req) -> Result<()> |
| 262 | where |
no test coverage detected