Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 38 additions & 2 deletions src/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,7 @@ async fn get_release_with_options(
tag: &str,
use_versions_host: bool,
) -> Result<GithubRelease> {
if use_versions_host
&& is_public_github_api_base(api_url)
if can_use_versions_host_for_release_metadata(api_url, tag, use_versions_host)
&& let Ok(Some(release)) = crate::versions_host::github_release(repo, tag).await
{
trace!("got GitHub release {repo}@{tag} from mise-versions");
Expand All @@ -394,6 +393,19 @@ fn is_public_github_api_base(api_url: &str) -> bool {
api_url.trim_end_matches('/') == API_URL
}

fn can_use_versions_host_for_release_metadata(
api_url: &str,
tag: &str,
use_versions_host: bool,
) -> bool {
use_versions_host
&& is_public_github_api_base(api_url)
// The versions-host release metadata endpoint uses the tag as a path segment.
// Tags containing `/` currently 400 at the service boundary, so skip the
// lookup and fall back directly to the GitHub API.
&& !tag.contains('/')
}

fn next_page(headers: &HeaderMap) -> Option<String> {
let link = headers
.get("link")
Expand Down Expand Up @@ -902,6 +914,30 @@ something_else = "value"
assert!(best.is_none());
}

#[test]
fn test_can_use_versions_host_for_release_metadata() {
assert!(can_use_versions_host_for_release_metadata(
"https://api.github.com",
"v1.0.0",
true
));
assert!(!can_use_versions_host_for_release_metadata(
"https://api.github.com",
"@biomejs/biome@2.4.16",
true
));
assert!(!can_use_versions_host_for_release_metadata(
"https://ghe.example.com/api/v3",
"v1.0.0",
true
));
assert!(!can_use_versions_host_for_release_metadata(
"https://api.github.com",
"v1.0.0",
false
));
}

#[test]
fn test_build_revision_ignores_non_numeric_suffix() {
let releases = vec![
Expand Down
Loading