Andrey Kalmykov
01/07/2025, 7:21 PMAndriy Knysh (Cloud Posse)
01/07/2025, 7:25 PMAndriy Knysh (Cloud Posse)
01/07/2025, 7:25 PMAndrey Kalmykov
01/07/2025, 7:33 PMErik Osterman (Cloud Posse)
01/07/2025, 7:39 PMErik Osterman (Cloud Posse)
01/07/2025, 7:40 PMAndrey Kalmykov
01/07/2025, 7:49 PMAndriy Knysh (Cloud Posse)
01/07/2025, 8:10 PMErik Osterman (Cloud Posse)
01/07/2025, 8:19 PMErik Osterman (Cloud Posse)
01/07/2025, 8:19 PMmy current understanding is that with git clone approach of v1My observation is that it downloads a tarball archive and decompresses it, and that it's not actually doing a git clone
Erik Osterman (Cloud Posse)
01/07/2025, 8:20 PMAndrey Kalmykov
01/07/2025, 8:30 PMErik Osterman (Cloud Posse)
01/07/2025, 8:40 PMErik Osterman (Cloud Posse)
01/07/2025, 8:40 PMErik Osterman (Cloud Posse)
01/07/2025, 8:40 PMgit::Erik Osterman (Cloud Posse)
01/07/2025, 8:43 PMpackage main
import (
"fmt"
"net/url"
"strings"
"github.com/hashicorp/go-getter"
)
// Custom GitHub detector
func CustomGitHubDetector(u *url.URL) (string, map[string]string, error) {
if u.Host != "github.com" {
return "", nil, nil // Not a GitHub URL, skip this detector
}
parts := strings.SplitN(u.Path, "/", 4)
if len(parts) < 3 {
return "", nil, fmt.Errorf("invalid GitHub URL %q", u)
}
// Extract GitHub token from the environment
githubToken := os.Getenv("GITHUB_TOKEN")
if githubToken != "" {
// Add the token to the URL
u.User = url.User(githubToken)
}
// Convert to a git:: URL
if len(parts) == 4 {
return "git::" + u.String(), map[string]string{}, nil
}
return "git::" + fmt.Sprintf("https://%s/%s/%s.git", u.Host, parts[1], parts[2]), map[string]string{}, nil
}Erik Osterman (Cloud Posse)
01/07/2025, 8:43 PM// Register custom detectors
getter.Detectors = []getter.Detector{
// Add the custom GitHub detector first
getter.DetectorFunc(CustomGitHubDetector),
// Add other default detectors as fallback
getter.DetectGitHub, // Original GitHub detector (optional)
getter.DetectGzip, // Detect .gz files
getter.DetectGit, // Detect git:: URLs
getter.DetectHTTP, // Detect HTTP(S) URLs
}
// Use the getter.Client with the modified detectors
client := &getter.Client{
Src: "https://github.com/user/repo.git",
Dst: "./repo",
Mode: getter.ClientModeAny,
}
if err := client.Get(); err != nil {
fmt.Printf("Error: %s\n", err)
}Andrey Kalmykov
01/07/2025, 9:08 PMgit::https://<token>@github.com/... and it still does git clone not using github token at all, or does not if repo is private. If the token doesn’t have the exact right Git credentials/scopes, git clone won’t accept it. So the v1 would not use token.Erik Osterman (Cloud Posse)
01/07/2025, 9:50 PMor does not if repo is private.Do you mean then it doesn't work with a private repo even when you have a hardcoded token (just for testing)?
Erik Osterman (Cloud Posse)
01/07/2025, 9:50 PMAndrey Kalmykov
01/08/2025, 11:56 AMErik Osterman (Cloud Posse)
01/08/2025, 1:25 PM