alterware-launcher/src/github.rs

24 lines
695 B
Rust
Raw Normal View History

2023-08-29 00:47:40 -04:00
use semver::Version;
2023-08-29 15:53:47 -04:00
pub fn latest(owner: &str, repo: &str) -> String {
2023-08-29 00:47:40 -04:00
let github_body = crate::http::get_body_string(
format!(
"https://api.github.com/repos/{}/{}/releases/latest",
2023-08-29 15:53:47 -04:00
owner, repo
2023-08-29 00:47:40 -04:00
)
.as_str(),
);
let github_json: serde_json::Value = serde_json::from_str(&github_body).unwrap();
2023-08-29 15:53:47 -04:00
github_json["tag_name"]
2023-08-29 00:47:40 -04:00
.to_string()
2023-08-29 15:53:47 -04:00
.replace(['v', '"'].as_ref(), "")
}
pub fn latest_version(owner: &str, repo: &str) -> Version {
Version::parse(&latest(owner, repo)).unwrap()
2023-08-29 00:47:40 -04:00
}
2023-08-29 15:53:47 -04:00
pub fn latest_release_url(owner: &str, repo: &str) -> String {
format!("https://github.com/{}/{}/releases/latest", owner, repo)
2023-08-29 00:47:40 -04:00
}