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

Method post_json

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

Source from the content-addressed store, hash-verified

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

Callers 7

is_repositoryMethod · 0.80
statusMethod · 0.80
logMethod · 0.80
list_branchesMethod · 0.80
checkoutMethod · 0.80
list_remotesMethod · 0.80
list_stashesMethod · 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