aboutsummaryrefslogtreecommitdiff
path: root/src-tauri
diff options
context:
space:
mode:
authorGeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com>2023-04-30 20:14:33 +0200
committerGitHub <noreply@github.com>2023-04-30 20:14:33 +0200
commit0d4392a8d50e2a44dee9a74cb82d5e1fabfc98d5 (patch)
tree852e56d3f8ba7a5aea7917363196c905042fb3f7 /src-tauri
parent171de5959c2ac5f522f52f7ebd99fd3eb2619091 (diff)
downloadFlightCore-0d4392a8d50e2a44dee9a74cb82d5e1fabfc98d5.tar.gz
FlightCore-0d4392a8d50e2a44dee9a74cb82d5e1fabfc98d5.zip
fix: Fetch multiple pages from GitHub PR API (#298)
* fix: Fetch multiple pages from GitHub PR API Previously we only fetched the first page which caused us to miss older pull requests. * feat: Only check as many pages as we need Instead of checking a static x amount of pages in the API we only wanna fetch as many pages as we actually need.
Diffstat (limited to 'src-tauri')
-rw-r--r--src-tauri/src/github/pull_requests.rs35
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