Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(pagination): should be optional #106

Merged
merged 1 commit into from
May 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions axoupdater/src/release/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,27 +149,41 @@ pub(crate) async fn get_github_releases(
let mut data: Vec<Release> = vec![];

while pages_remain {
// fetch the releases
let resp = get_releases(&client, &url, token).await?;

// collect the response headers
let headers = resp.headers();
let link_header = &headers[reqwest::header::LINK]
.to_str()
.expect("header was not ascii")
.to_string();
pages_remain = link_header.contains("rel=\"next\"");
let link_header = &headers
.get(reqwest::header::LINK)
.as_ref()
.map(|link_header_val| {
link_header_val
.to_str()
.expect("header was not ascii")
.to_string()
});

// append the data
let mut body: Vec<Release> = resp
.json::<Vec<GithubRelease>>()
.await?
.into_iter()
.filter_map(|gh| Release::try_from_github(app_name, gh).ok())
.collect();
data.append(&mut body);
dbg!(&data);

if pages_remain {
url = get_next_url(link_header).expect("detected a next but it was a lie");
}
// check headers to see pages remain and if they do update the URL
pages_remain = if let Some(link_header) = link_header {
if link_header.contains("rel=\"next\"") {
url = get_next_url(link_header).expect("detected a next but it was a lie");
true
} else {
false
}
} else {
false
};
}

Ok(data
Expand Down
Loading