aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com>2022-11-13 15:22:43 +0100
committerGitHub <noreply@github.com>2022-11-13 15:22:43 +0100
commit8393a08f4cb937805d41bb9a0f7901fb5221746e (patch)
tree4fe05334c13d59b680214667fb7ea8df3a0ac7cb
parentf1756396ecba4ace6d62ee94e03d060c8f337de3 (diff)
downloadFlightCore-8393a08f4cb937805d41bb9a0f7901fb5221746e.tar.gz
FlightCore-8393a08f4cb937805d41bb9a0f7901fb5221746e.zip
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.
-rw-r--r--src-tauri/src/github/release_notes.rs15
1 files 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<Vec<ReleaseInfo>, String> {
+// Fetches repo release API and returns response as string
+async fn fetch_github_releases_api(url: &str) -> Result<String, String> {
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<Vec<ReleaseInfo>, String> {
.await
.unwrap();
+ Ok(res)
+}
+
+#[tauri::command]
+pub async fn get_northstar_release_notes() -> Result<Vec<ReleaseInfo>, 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::Value> =
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")