v0.4.1 : Phase 1 complete (17/17) - dashboard TUI (#33), favoris/notes/tags (#39), profils d'environnement (#40), completions dynamiques + man pages (#41), packaging officiel + CI (#42), self-update Gitea, state v3, 212 tests
This commit is contained in:
+15
-6
@@ -150,19 +150,28 @@ fn github_auth_header() -> Option<String> {
|
||||
}
|
||||
|
||||
pub fn latest_release(repo: &str) -> Result<GhRelease> {
|
||||
match latest_release_api(repo) {
|
||||
latest_release_with_base(repo, None)
|
||||
}
|
||||
|
||||
/// Resolve the latest release, with an optional API base URL override
|
||||
/// (e.g. https://git.dracodev.net/api/v1 for a Gitea instance).
|
||||
pub fn latest_release_with_base(repo: &str, api_base: Option<&str>) -> Result<GhRelease> {
|
||||
let github = api_base.is_none() || api_base == Some("https://api.github.com");
|
||||
match latest_release_api(repo, api_base) {
|
||||
Ok(release) => Ok(release),
|
||||
Err(e) if format!("{e:#}").contains("rate limit") => {
|
||||
// The API is rate limited (60 unauthenticated requests/hour):
|
||||
// fall back to the GitHub web pages, which are not limited.
|
||||
Err(e) if github && format!("{e:#}").contains("rate limit") => {
|
||||
// The GitHub API is rate limited (60 unauthenticated
|
||||
// requests/hour): fall back to the GitHub web pages, which are
|
||||
// not limited. (Gitea has no equivalent web fallback.)
|
||||
latest_release_web(repo)
|
||||
}
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
}
|
||||
|
||||
fn latest_release_api(repo: &str) -> Result<GhRelease> {
|
||||
let url = format!("https://api.github.com/repos/{repo}/releases/latest");
|
||||
fn latest_release_api(repo: &str, api_base: Option<&str>) -> Result<GhRelease> {
|
||||
let base = api_base.unwrap_or("https://api.github.com");
|
||||
let url = format!("{base}/repos/{repo}/releases/latest");
|
||||
let mut req = ureq::get(&url).set("User-Agent", USER_AGENT);
|
||||
if let Some(auth) = github_auth_header() {
|
||||
req = req.set("Authorization", &auth);
|
||||
|
||||
Reference in New Issue
Block a user