aboutsummaryrefslogtreecommitdiff
path: root/src-tauri/src/github/release_notes.rs
diff options
context:
space:
mode:
authorGeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com>2024-02-14 20:32:59 +0100
committerGitHub <noreply@github.com>2024-02-14 20:32:59 +0100
commit4702db40da7f3762614b030159cbd44fc59536a8 (patch)
treee7e30c4203b3e39e88bf79c0882c92820d0a8d00 /src-tauri/src/github/release_notes.rs
parent7380c390f8fd536152feb4ff0211bf45c28174fc (diff)
downloadFlightCore-4702db40da7f3762614b030159cbd44fc59536a8.tar.gz
FlightCore-4702db40da7f3762614b030159cbd44fc59536a8.zip
refactor: Use `octocrab` library for fetching release notes (#809)
Instead of writing our own logic to achieve this.
Diffstat (limited to 'src-tauri/src/github/release_notes.rs')
-rw-r--r--src-tauri/src/github/release_notes.rs38
1 files changed, 26 insertions, 12 deletions
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<bool, String> {
#[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 = 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<ReleaseInfo> = 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<ReleaseInfo> = 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)