v2 #2

Merged
dzu merged 24 commits from dev into main 2026-02-21 11:06:58 +01:00
Showing only changes of commit b3b08936f2 - Show all commits

add: cacheId parsing and priting
All checks were successful
Build and update the action / build-and-upload (push) Successful in 2m54s

Artem Diachenko 2026-02-17 20:15:00 +00:00

View file

@ -1,4 +1,4 @@
use std::{ffi::OsString, path::PathBuf, str::FromStr, string::FromUtf8Error}; use std::{ffi::OsString, io::Read, path::PathBuf, str::FromStr, string::FromUtf8Error};
use anyhow::{Context, Result, bail}; use anyhow::{Context, Result, bail};
use flate2::{Compression, GzBuilder}; use flate2::{Compression, GzBuilder};
@ -93,7 +93,6 @@ struct CacheId(u64);
impl Client { impl Client {
fn reserve(&self, key: &CacheKey, cache_size: usize) -> Result<CacheId> { fn reserve(&self, key: &CacheKey, cache_size: usize) -> Result<CacheId> {
let uri = format!("{}_apis/artifactcache/caches", self.base_url); let uri = format!("{}_apis/artifactcache/caches", self.base_url);
println!("will use uri: {uri}");
let request = Request::builder() let request = Request::builder()
.uri(uri) .uri(uri)
.method(Method::POST) .method(Method::POST)
@ -118,7 +117,25 @@ impl Client {
); );
} }
todo!() let mut body = Vec::with_capacity(100);
response
.into_body()
.read_to_end(&mut body)
.context("reading response body")?;
let body_value =
serde_json::from_slice::<serde_json::Value>(&body).context("parsing response body")?;
println!("{body_value:#?}");
let cache_id = body_value
.get("result")
.context("response.result")?
.get("cacheId")
.context("response.result.cacheId")?
.as_u64()
.context("cacheId as u64")?;
Ok(CacheId(cache_id))
} }
} }
@ -160,4 +177,6 @@ fn main() {
let cache_id = client.reserve(&key, output.len()).unwrap(); let cache_id = client.reserve(&key, output.len()).unwrap();
println!("Reserved cache with id {cache_id:?}"); println!("Reserved cache with id {cache_id:?}");
todo!();
} }