(endpoint: string)
| 2280 | * http://github.mycompany.com/api -> http://github.mycompany.com/ |
| 2281 | */ |
| 2282 | export function getHTMLURL(endpoint: string): string { |
| 2283 | if (envHTMLURL !== undefined) { |
| 2284 | return envHTMLURL |
| 2285 | } |
| 2286 | |
| 2287 | // In the case of GitHub.com, the HTML site lives on the parent domain. |
| 2288 | // E.g., https://api.github.com -> https://github.com |
| 2289 | // |
| 2290 | // Whereas with Enterprise, it lives on the same domain but without the |
| 2291 | // API path: |
| 2292 | // E.g., https://github.mycompany.com/api/v3 -> https://github.mycompany.com |
| 2293 | // |
| 2294 | // We need to normalize them. |
| 2295 | if (endpoint === getDotComAPIEndpoint() && !envEndpoint) { |
| 2296 | return 'https://github.com' |
| 2297 | } else { |
| 2298 | if (isGHE(endpoint)) { |
| 2299 | const url = new window.URL(endpoint) |
| 2300 | |
| 2301 | url.pathname = '/' |
| 2302 | |
| 2303 | if (url.hostname.startsWith('api.')) { |
| 2304 | url.hostname = url.hostname.replace(/^api\./, '') |
| 2305 | } |
| 2306 | |
| 2307 | return url.toString() |
| 2308 | } |
| 2309 | |
| 2310 | const parsed = URL.parse(endpoint) |
| 2311 | return `${parsed.protocol}//${parsed.hostname}` |
| 2312 | } |
| 2313 | } |
| 2314 | |
| 2315 | /** |
| 2316 | * Get the API URL for an HTML URL. For example: |
no test coverage detected