Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
76 changes: 70 additions & 6 deletions src/backend/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::file;
use crate::http::HTTP;
use crate::install_context::InstallContext;
use crate::lockfile::{PlatformInfo, ProvenanceType};
use crate::registry::REGISTRY;
use crate::toolset::ToolVersionOptions;
use crate::toolset::{ToolRequest, ToolVersion};
use crate::{backend::Backend, forgejo, github, gitlab};
Expand Down Expand Up @@ -392,7 +393,10 @@ impl Backend for UnifiedGitBackend {
}
}
} else {
match github::get_release_for_url(&api_url, &repo, "latest").await {
match self
.get_github_release_for_url(&api_url, &repo, "latest")
.await
{
Ok(r) => Some(r.tag_name),
Err(e) => {
debug!("Failed to fetch latest GitHub release for {repo}: {e}");
Expand Down Expand Up @@ -426,10 +430,19 @@ impl Backend for UnifiedGitBackend {
let api_url = opts.api_url();
let version_prefix = opts.version_prefix();

let use_versions_host = self.use_versions_host_for_github_metadata();
match try_with_v_prefix_and_repo(version, version_prefix, Some(&repo), |candidate| {
let api_url = api_url.clone();
let repo = repo.clone();
async move { github::get_release_for_url(&api_url, &repo, &candidate).await }
async move {
github::get_release_for_url_with_versions_host(
&api_url,
&repo,
&candidate,
use_versions_host,
)
.await
}
})
.await
{
Expand Down Expand Up @@ -605,6 +618,28 @@ impl UnifiedGitBackend {
}
}

fn use_versions_host_for_github_metadata(&self) -> bool {
let full = self.ba.full();
REGISTRY
.get(self.ba.short.as_str())
.is_some_and(|rt| rt.backends().iter().any(|b| *b == full))
}
Comment thread
greptile-apps[bot] marked this conversation as resolved.

async fn get_github_release_for_url(
&self,
api_url: &str,
repo: &str,
tag: &str,
) -> Result<github::GithubRelease> {
github::get_release_for_url_with_versions_host(
api_url,
repo,
tag,
self.use_versions_host_for_github_metadata(),
)
.await
}

/// Detect what provenance type is available for a release by checking its assets
/// and querying the GitHub attestation API.
async fn detect_provenance_type(
Expand All @@ -620,11 +655,20 @@ impl UnifiedGitBackend {
let version = &tv.version;
let version_prefix = opts.version_prefix();

let use_versions_host = self.use_versions_host_for_github_metadata();
let release =
try_with_v_prefix_and_repo(version, version_prefix, Some(repo), |candidate| {
let api_url = api_url.to_string();
let repo = repo.to_string();
async move { github::get_release_for_url(&api_url, &repo, &candidate).await }
async move {
github::get_release_for_url_with_versions_host(
&api_url,
&repo,
&candidate,
use_versions_host,
)
.await
}
})
.await
.ok();
Expand Down Expand Up @@ -782,11 +826,20 @@ impl UnifiedGitBackend {
if settings.slsa && settings.github.slsa {
let version = &tv.version;
let version_prefix = opts.version_prefix();
let use_versions_host = self.use_versions_host_for_github_metadata();
let release =
try_with_v_prefix_and_repo(version, version_prefix, Some(repo), |candidate| {
let api_url = api_url.to_string();
let repo = repo.to_string();
async move { github::get_release_for_url(&api_url, &repo, &candidate).await }
async move {
github::get_release_for_url_with_versions_host(
&api_url,
&repo,
&candidate,
use_versions_host,
)
.await
}
})
.await?;

Expand Down Expand Up @@ -1181,7 +1234,9 @@ impl UnifiedGitBackend {
version: &str,
target: &PlatformTarget,
) -> Result<ReleaseAsset> {
let release = github::get_release_for_url(api_url, repo, version).await?;
let release = self
.get_github_release_for_url(api_url, repo, version)
.await?;
let available_assets: Vec<String> = release.assets.iter().map(|a| a.name.clone()).collect();

// Build asset list with URLs for checksum fetching
Expand Down Expand Up @@ -1884,11 +1939,20 @@ impl UnifiedGitBackend {

// Try to get the release (with version prefix support)
let version_prefix = opts.version_prefix();
let use_versions_host = self.use_versions_host_for_github_metadata();
let release =
match try_with_v_prefix_and_repo(version, version_prefix, Some(&repo), |candidate| {
let api_url = api_url.to_string();
let repo = repo.clone();
async move { github::get_release_for_url(&api_url, &repo, &candidate).await }
async move {
github::get_release_for_url_with_versions_host(
&api_url,
&repo,
&candidate,
use_versions_host,
)
.await
}
})
.await
{
Expand Down
6 changes: 5 additions & 1 deletion src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1151,7 +1151,11 @@ pub trait Backend: Debug + Send + Sync {
}
is_registry_backend
} else {
true // Not in registry, safe to use versions host
trace!(
"Skipping versions host for {} because it is not in the registry",
ba.short
);
false
}
};

Expand Down
23 changes: 21 additions & 2 deletions src/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,12 +296,21 @@ pub async fn get_release(repo: &str, tag: &str) -> Result<GithubRelease> {
}

pub async fn get_release_for_url(api_url: &str, repo: &str, tag: &str) -> Result<GithubRelease> {
get_release_for_url_with_versions_host(api_url, repo, tag, true).await
}

pub async fn get_release_for_url_with_versions_host(
api_url: &str,
repo: &str,
tag: &str,
use_versions_host: bool,
) -> Result<GithubRelease> {
let key = format!("{api_url}-{repo}-{tag}").to_kebab_case();
let cache = get_release_cache(&key).await;
let cache = cache.get(&key).unwrap();
cache
.get_or_try_init_async_if(
async || get_release_(api_url, repo, tag).await,
async || get_release_with_options(api_url, repo, tag, use_versions_host).await,
should_cache_release,
)
.await
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Outdated
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Expand Down Expand Up @@ -357,7 +366,17 @@ fn pick_best_build_revision(releases: Vec<GithubRelease>, version: &str) -> Opti
}

async fn get_release_(api_url: &str, repo: &str, tag: &str) -> Result<GithubRelease> {
if is_public_github_api_base(api_url)
get_release_with_options(api_url, repo, tag, true).await
}

async fn get_release_with_options(
api_url: &str,
repo: &str,
tag: &str,
use_versions_host: bool,
) -> Result<GithubRelease> {
if use_versions_host
&& is_public_github_api_base(api_url)
&& let Ok(Some(release)) = crate::versions_host::github_release(repo, tag).await
{
trace!("got GitHub release {repo}@{tag} from mise-versions");
Expand Down
Loading