Skip to content

Commit

Permalink
refactor: Use octocrab library for fetching release notes (#809)
Browse files Browse the repository at this point in the history
Instead of writing our own logic to achieve this.
  • Loading branch information
GeckoEidechse authored Feb 14, 2024
1 parent 7380c39 commit 4702db4
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions src-tauri/src/github/release_notes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 4702db4

Please sign in to comment.