deriveWebBaseURL converts a GitHub API base URL to the corresponding web base URL. github.com: https://api.github.com → https://github.com GHE: https://ghes.corp.com/api/v3 → https://ghes.corp.com
(apiBaseURL string)
| 75 | // github.com: https://api.github.com → https://github.com |
| 76 | // GHE: https://ghes.corp.com/api/v3 → https://ghes.corp.com |
| 77 | func deriveWebBaseURL(apiBaseURL string) string { |
| 78 | u, err := url.Parse(apiBaseURL) |
| 79 | if err != nil { |
| 80 | return "https://github.com" |
| 81 | } |
| 82 | |
| 83 | // Standard github.com: API host is api.github.com. |
| 84 | if strings.EqualFold(u.Host, "api.github.com") { |
| 85 | return "https://github.com" |
| 86 | } |
| 87 | |
| 88 | // GHE: strip /api/v3 path suffix. |
| 89 | u.Path = strings.TrimSuffix(u.Path, "/api/v3") |
| 90 | u.Path = strings.TrimSuffix(u.Path, "/") |
| 91 | return u.String() |
| 92 | } |
| 93 | |
| 94 | // extractHost returns the host portion of a URL. |
| 95 | func extractHost(rawURL string) string { |