Skip to content
Open
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions arch.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ func getAdditionalArch(arch string, goarm uint8, universalArch string) []string
if arch == "amd64" {
additionalArch = append(additionalArch, "x86_64")
}
if arch == "386" {
additionalArch = append(additionalArch, "i386", "x86", "x86_32")
}
if universalArch != "" {
additionalArch = append(additionalArch, universalArch)
}
Expand Down
2 changes: 2 additions & 0 deletions arch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ func TestAdditionalArch(t *testing.T) {
{"arm", 4, "", []string{"arm"}}, // go is not supporting below armv5
{"amd64", 0, "", []string{"amd64", "x86_64"}},
{"amd64", 0, "all", []string{"amd64", "x86_64", "all"}},
{"386", 0, "", []string{"386", "i386", "x86", "x86_32"}},
{"386", 0, "all", []string{"386", "i386", "x86", "x86_32", "all"}},
}

for _, testItem := range testData {
Expand Down
37 changes: 37 additions & 0 deletions github_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io"
"net/http"
"os"
"strings"

"github.com/google/go-github/v74/github"
"golang.org/x/oauth2"
Expand Down Expand Up @@ -93,6 +94,42 @@ func (s *GitHubSource) DownloadReleaseAsset(ctx context.Context, rel *Release, a
if rel == nil {
return nil, ErrInvalidRelease
}
// Check if the AssetURL contains more than one "https://"
useGithubProxy := strings.Count(rel.AssetURL, "https://") > 1
Comment on lines +97 to +98
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Proxy detection only checks AssetURL, but ValidationAssetURL may differ.

If rel.ValidationAssetURL uses a proxy but rel.AssetURL doesn't (or vice versa), the current logic will use the wrong download path for one of them. Consider checking both URLs or the specific URL being requested.

🔎 Proposed fix
-	// Check if the AssetURL contains more than one "https://"
-	useGithubProxy := strings.Count(rel.AssetURL, "https://") > 1
-	// If the AssetURL contains more than 2 "https://", it means it's using a GitHub Proxy service.
+	// Determine the download URL based on asset ID first
+	var downloadURL string
+	if rel.AssetID == assetID {
+		downloadURL = rel.AssetURL
+	} else if rel.ValidationAssetID == assetID {
+		downloadURL = rel.ValidationAssetURL
+	}
+
+	// Check if the selected URL contains more than one "https://" (indicates GitHub Proxy usage)
+	useGithubProxy := downloadURL != "" && strings.Count(downloadURL, "https://") > 1
+	// If the URL contains more than 1 "https://", it means it's using a GitHub Proxy service.

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In github_source.go around lines 97-98, proxy detection only inspects
rel.AssetURL which can differ from rel.ValidationAssetURL; update the logic to
detect proxies for the actual URL being used (check both rel.AssetURL and
rel.ValidationAssetURL as appropriate) and set useGithubProxy based on the
specific URL you will request (e.g., compute proxy flags for each URL or derive
useGithubProxy = strings.Count(urlBeingRequested, "https://") > 1 so the
download/validation path uses the correct proxy decision).

// If the AssetURL contains more than 2 "https://", it means it's using a GitHub Proxy service.
// In this case, we should download the asset directly from the AssetURL instead of using the GitHub API.
// This is a workaround for the issue that the GitHub API does not support downloading assets from GitHub Proxy services.
if useGithubProxy {
// Determine download url based on asset id.
var downloadUrl string
if rel.AssetID == assetID {
downloadUrl = rel.AssetURL
} else if rel.ValidationAssetID == assetID {
downloadUrl = rel.ValidationAssetURL
}
if downloadUrl == "" {
return nil, fmt.Errorf("asset ID %d: %w", assetID, ErrAssetNotFound)
}
// Download the asset directly from the AssetURL
req, err := http.NewRequestWithContext(ctx, http.MethodGet, downloadUrl, http.NoBody)
if err != nil {
return nil, fmt.Errorf("failed to create download request:%w", err)
}

resp, err := http.DefaultClient.Do(req)
if err != nil {
return nil, fmt.Errorf("download failed:%w", err)
}

// The caller is responsible for closing resp.Body
if resp.StatusCode != http.StatusOK {
defer resp.Body.Close()
return nil, fmt.Errorf("download failed, status code:%d", resp.StatusCode)
}

return resp.Body, nil
}
// continue with the normal GitHub API download
owner, repo, err := rel.repository.GetSlug()
if err != nil {
return nil, err
Expand Down