From 4702db40da7f3762614b030159cbd44fc59536a8 Mon Sep 17 00:00:00 2001 From: GeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com> Date: Wed, 14 Feb 2024 20:32:59 +0100 Subject: refactor: Use `octocrab` library for fetching release notes (#809) Instead of writing our own logic to achieve this. --- src-tauri/src/github/release_notes.rs | 38 ++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 12 deletions(-) (limited to 'src-tauri/src') diff --git a/src-tauri/src/github/release_notes.rs b/src-tauri/src/github/release_notes.rs index 16b65183..cbe3d0b1 100644 --- a/src-tauri/src/github/release_notes.rs +++ b/src-tauri/src/github/release_notes.rs @@ -98,19 +98,33 @@ pub async fn check_is_flightcore_outdated() -> Result { #[tauri::command] pub async fn get_northstar_release_notes() -> Result, String> { - let url = "https://api.github.com/repos/R2Northstar/Northstar/releases"; - let res = match fetch_github_releases_api(url).await { - Ok(res) => res, - Err(err) => return Err(format!("Failed getting Northstar release notes: {err}")), - }; + let octocrab = octocrab::instance(); + let page = octocrab + .repos("R2Northstar", "Northstar") + .releases() + .list() + // Optional Parameters + .per_page(25) + .page(1u32) + // Send the request + .send() + .await + .unwrap(); + + // TODO there's probably a way to automatically serialize into the struct but I don't know yet how to + let mut release_info_vector: Vec = vec![]; + for item in page.items { + let release_info = ReleaseInfo { + name: item.name.ok_or(String::from("Release name not found"))?, + published_at: item + .published_at + .ok_or(String::from("Release date not found"))? + .to_rfc3339(), + body: item.body.ok_or(String::from("Release body not found"))?, + }; + release_info_vector.push(release_info); + } - let release_info_vector: Vec = match serde_json::from_str(&res) { - Ok(res) => res, - Err(err) => { - log::warn!("{err}"); - return Err("Could not fetch release notes. JSON was not well-formatted".to_string()); - } - }; log::info!("Done checking GitHub API"); Ok(release_info_vector) -- cgit v1.2.3