MCPcopy Create free account
hub / github.com/AI45Lab/Code / post_unit

Method post_unit

core/src/workspace/remote_git.rs:261–288  ·  view source on GitHub ↗
(&self, op: &'static str, body: &Req)

Source from the content-addressed store, hash-verified

259 }
260
261 async fn post_unit<Req>(&self, op: &'static str, body: &Req) -> Result<()>
262 where
263 Req: Serialize + ?Sized,
264 {
265 let url = self.endpoint(op);
266 let mut req = self.http.post(&url).json(body);
267 if let Some(token) = self.bearer_token.as_deref() {
268 if !token.is_empty() {
269 req = req.bearer_auth(token);
270 }
271 }
272
273 let start = std::time::Instant::now();
274 let send_result = req.send().await;
275 let status_code = send_result.as_ref().ok().map(|r| r.status().as_u16());
276 let ok = matches!(send_result.as_ref(), Ok(r) if r.status().is_success());
277 emit_remote_git_event(op, &self.repo_id, status_code, ok, start.elapsed(), None);
278
279 let resp =
280 send_result.map_err(|e| anyhow!("remote git call '{}' transport error: {}", op, e))?;
281
282 let status = resp.status();
283 if status.is_success() {
284 return Ok(());
285 }
286 let body_text = resp.text().await.unwrap_or_default();
287 Err(map_error_response(op, status, &body_text))
288 }
289
290 /// Like [`Self::post_json`] but with a hard cap on the streamed response
291 /// body in bytes, intended for endpoints that can legitimately return

Callers 2

create_branchMethod · 0.80
stashMethod · 0.80

Calls 9

nowFunction · 0.85
emit_remote_git_eventFunction · 0.85
map_error_responseFunction · 0.85
endpointMethod · 0.45
postMethod · 0.45
is_emptyMethod · 0.45
sendMethod · 0.45
statusMethod · 0.45
textMethod · 0.45

Tested by

no test coverage detected