GetGitHubHost returns the GitHub host URL from environment variables. Environment variables are checked in priority order for GitHub Enterprise support: 1. GITHUB_SERVER_URL - GitHub Actions standard (e.g., https://MYORG.ghe.com) 2. GITHUB_ENTERPRISE_HOST - GitHub Enterprise standard (e.g., MYORG.gh
()
| 26 | // |
| 27 | // The function normalizes the URL by adding https:// if missing and removing trailing slashes. |
| 28 | func GetGitHubHost() string { |
| 29 | envVars := []string{"GITHUB_SERVER_URL", "GITHUB_ENTERPRISE_HOST", "GITHUB_HOST", "GH_HOST"} |
| 30 | |
| 31 | for _, envVar := range envVars { |
| 32 | if value := os.Getenv(envVar); value != "" { //nolint:osgetenvlibrary |
| 33 | githubLog.Printf("Resolved GitHub host from %s: %s", envVar, value) |
| 34 | return stringutil.NormalizeGitHubHostURL(value) |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | defaultHost := string(constants.PublicGitHubHost) |
| 39 | githubLog.Printf("No GitHub host environment variable set, using default: %s", defaultHost) |
| 40 | return defaultHost |
| 41 | } |
| 42 | |
| 43 | // GetGitHubHostForRepo returns the GitHub host URL for a specific repository. |
| 44 | // Repositories under the github, githubnext, and microsoft organizations are |
no test coverage detected