From 8393a08f4cb937805d41bb9a0f7901fb5221746e Mon Sep 17 00:00:00 2001 From: GeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com> Date: Sun, 13 Nov 2022 15:22:43 +0100 Subject: refactor: Splice out GH release API fetch function (#47) So that it can be re-used by other functions later such as for checking newest FlightCore version by checking against GitHub releases. --- src-tauri/src/github/release_notes.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src-tauri/src/github/release_notes.rs b/src-tauri/src/github/release_notes.rs index db705dab..20c535ba 100644 --- a/src-tauri/src/github/release_notes.rs +++ b/src-tauri/src/github/release_notes.rs @@ -8,11 +8,10 @@ pub struct ReleaseInfo { pub body: String } -#[tauri::command] -pub async fn get_northstar_release_notes() -> Result, String> { +// Fetches repo release API and returns response as string +async fn fetch_github_releases_api(url: &str) -> Result { println!("Fetching releases notes from GitHub API"); - let url = "https://api.github.com/repos/R2Northstar/Northstar/releases"; let user_agent = "GeckoEidechse/FlightCore"; let client = reqwest::Client::new(); let res = client @@ -25,10 +24,18 @@ pub async fn get_northstar_release_notes() -> Result, String> { .await .unwrap(); + Ok(res) +} + +#[tauri::command] +pub async fn get_northstar_release_notes() -> Result, String> { + let url = "https://api.github.com/repos/R2Northstar/Northstar/releases"; + let res = fetch_github_releases_api(url).await?; + let json_response: Vec = serde_json::from_str(&res).expect("JSON was not well-formatted"); println!("Done checking GitHub API"); - + return Ok( json_response.iter().map(|release| ReleaseInfo { name: release.get("name") -- cgit v1.2.3