Skip to content

Commit

Permalink
init: Check all releases (#21417) (#21419)
Browse files Browse the repository at this point in the history
(cherry picked from commit 69e1b68)

Co-authored-by: Jon Cinque <[email protected]>
  • Loading branch information
mergify[bot] and joncinque authored Nov 25, 2021
1 parent b030d4b commit 6e656de
Showing 1 changed file with 43 additions and 28 deletions.
71 changes: 43 additions & 28 deletions install/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -859,39 +859,54 @@ fn check_for_newer_github_release(
version_filter: Option<semver::VersionReq>,
prerelease_allowed: bool,
) -> reqwest::Result<Option<String>> {
let url =
reqwest::Url::parse("https://api.github.com/repos/solana-labs/solana/releases").unwrap();
let mut page = 1;
const PER_PAGE: usize = 100;
let client = reqwest::blocking::Client::builder()
.user_agent("solana-install")
.build()?;
let request = client.get(url).build()?;
let response = client.execute(request)?;

let mut releases = response
.json::<GithubReleases>()?
.0
.into_iter()
.filter_map(
|GithubRelease {
tag_name,
prerelease,
}| {
if let Ok(version) = semver_of(&tag_name) {
if (prerelease_allowed || !prerelease)
&& version_filter
.as_ref()
.map_or(true, |version_filter| version_filter.matches(&version))
{
return Some(version);
}
}
None
},
let mut all_releases = vec![];
let mut releases = vec![];

while page == 1 || releases.len() == PER_PAGE {
let url = reqwest::Url::parse_with_params(
"https://api.github.com/repos/solana-labs/solana/releases",
&[
("per_page", &format!("{}", PER_PAGE)),
("page", &format!("{}", page)),
],
)
.collect::<Vec<_>>();
.unwrap();
let request = client.get(url).build()?;
let response = client.execute(request)?;

releases = response
.json::<GithubReleases>()?
.0
.into_iter()
.filter_map(
|GithubRelease {
tag_name,
prerelease,
}| {
if let Ok(version) = semver_of(&tag_name) {
if (prerelease_allowed || !prerelease)
&& version_filter
.as_ref()
.map_or(true, |version_filter| version_filter.matches(&version))
{
return Some(version);
}
}
None
},
)
.collect::<Vec<_>>();
all_releases.extend_from_slice(&releases);
page += 1;
}

releases.sort();
Ok(releases.pop().map(|r| r.to_string()))
all_releases.sort();
Ok(all_releases.pop().map(|r| r.to_string()))
}

pub enum SemverUpdateType {
Expand Down

0 comments on commit 6e656de

Please sign in to comment.