feat: auto detect hostname

This commit is contained in:
Romain Bertrand 2026-01-05 12:47:28 +01:00
parent 2c27823e18
commit c0baf4fa3b
13 changed files with 300 additions and 125 deletions

View file

@ -87,7 +87,14 @@ func (c *Config) SaveToPath(path string) error {
return os.WriteFile(path, data, 0600)
}
func (c *Config) GetHost(hostname string) (HostConfig, error) {
// GetHost resolves the hostname to use for API client creation.
// Priority order:
// 1. Explicitly provided hostname parameter
// 2. CLI flag (--hostname)
// 3. Environment variable (FGJ_HOST)
// 4. Auto-detected hostname from git remote
// 5. Default to codeberg.org
func (c *Config) GetHost(hostname string, detectedHost string) (HostConfig, error) {
if hostname == "" {
hostname = viper.GetString("hostname")
}
@ -96,6 +103,10 @@ func (c *Config) GetHost(hostname string) (HostConfig, error) {
hostname = os.Getenv("FGJ_HOST")
}
if hostname == "" {
hostname = detectedHost
}
if hostname == "" {
hostname = "codeberg.org"
}