Skip to content

Commit

Permalink
Merge pull request #106 from axodotdev/pagination-optional
Browse files Browse the repository at this point in the history
fix(pagination): should be optional
  • Loading branch information
mistydemeo committed May 9, 2024
2 parents 6a1ccb8 + 528b35a commit 2d86af7
Showing 1 changed file with 23 additions and 9 deletions.
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

0 comments on commit 2d86af7

Please sign in to comment.