21 lines
887 B
Rust
21 lines
887 B
Rust
|
|
use anyhow::{Result, bail};
|
||
|
|
use regex::Regex;
|
||
|
|
|
||
|
|
/// Resolves the latest release tag for `repo` via its public Atom feed.
|
||
|
|
///
|
||
|
|
/// Deliberately not a full XML parse: the feed's newest entry is always
|
||
|
|
/// first, and its `<link rel="alternate" .../releases/tag/<tag>"/>` is the
|
||
|
|
/// first such link in the document, so a single regex match is sufficient.
|
||
|
|
/// Revisit with a real XML parser if GitHub's feed shape ever changes.
|
||
|
|
pub fn latest_github_release(client: &reqwest::blocking::Client, repo: &str) -> Result<String> {
|
||
|
|
let url = format!("https://github.com/{repo}/releases.atom");
|
||
|
|
let body = client.get(&url).send()?.error_for_status()?.text()?;
|
||
|
|
|
||
|
|
let pattern = format!(r#"releases/tag/([^"]+)""#);
|
||
|
|
let re = Regex::new(&pattern)?;
|
||
|
|
match re.captures(&body) {
|
||
|
|
Some(caps) => Ok(caps[1].to_string()),
|
||
|
|
None => bail!("no release tag found in {url}"),
|
||
|
|
}
|
||
|
|
}
|