diff options
author | GeckoEidechse <gecko.eidechse+git@pm.me> | 2023-05-06 01:50:03 +0200 |
---|---|---|
committer | GeckoEidechse <gecko.eidechse+git@pm.me> | 2023-05-06 01:50:03 +0200 |
commit | 7efd2f5c5e9e380ca463d97a54b862da6b96da16 (patch) | |
tree | d2c6624e5e350fb04d14144fa25a0a66db51c383 /src-tauri/src/github/pull_requests.rs | |
parent | 10616b295eb23c8250a0d874fe05211f73a8ba81 (diff) | |
parent | d15190c1fa16420c44d3c9f4a2b58b0f5826178b (diff) | |
download | FlightCore-7efd2f5c5e9e380ca463d97a54b862da6b96da16.tar.gz FlightCore-7efd2f5c5e9e380ca463d97a54b862da6b96da16.zip |
Merge branch 'main' into fix/handle-failed-downloadfix/handle-failed-download
Diffstat (limited to 'src-tauri/src/github/pull_requests.rs')
-rw-r--r-- | src-tauri/src/github/pull_requests.rs | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/src-tauri/src/github/pull_requests.rs b/src-tauri/src/github/pull_requests.rs index 96ac623f..a56fb647 100644 --- a/src-tauri/src/github/pull_requests.rs +++ b/src-tauri/src/github/pull_requests.rs @@ -66,17 +66,34 @@ pub enum PullRequestType { /// Parse pull requests from specified URL pub async fn get_pull_requests(url: String) -> Result<Vec<PullsApiResponseElement>, String> { - let json_response = match fetch_github_releases_api(&url).await { - Ok(result) => result, - Err(err) => return Err(err), - }; + let mut all_pull_requests: Vec<PullsApiResponseElement> = vec![]; - let pulls_response: Vec<PullsApiResponseElement> = match serde_json::from_str(&json_response) { - Ok(res) => res, - Err(err) => return Err(err.to_string()), - }; + let mut i = 1; // pagination on GitHub starts with `1`. + loop { + let paginated_url = format!("{}?page={}", url, i); + + let json_response = match fetch_github_releases_api(&paginated_url).await { + Ok(result) => result, + Err(err) => return Err(err), + }; + + let pulls_response: Vec<PullsApiResponseElement> = + match serde_json::from_str(&json_response) { + Ok(res) => res, + Err(err) => return Err(err.to_string()), + }; + + // Check if we still got a result + if pulls_response.is_empty() { + // Empty result means we went through all pages with content + break; + } + + all_pull_requests.extend(pulls_response); + i += 1; + } - Ok(pulls_response) + Ok(all_pull_requests) } /// Gets either launcher or mods PRs |