(hostname: Hostname, type: APIClientType)
| 6 | import { getPlatformFromHostname } from '../auth/platform'; |
| 7 | |
| 8 | export function getGitHubAPIBaseUrl(hostname: Hostname, type: APIClientType) { |
| 9 | const platform = getPlatformFromHostname(hostname); |
| 10 | const url = new URL(Constants.GITHUB_API_BASE_URL); |
| 11 | |
| 12 | switch (platform) { |
| 13 | case 'GitHub Enterprise Server': |
| 14 | url.hostname = hostname; |
| 15 | url.pathname = type === 'rest' ? '/api/v3/' : '/api/'; |
| 16 | break; |
| 17 | case 'GitHub Enterprise Cloud with Data Residency': |
| 18 | url.hostname = `api.${hostname}`; |
| 19 | url.pathname = '/'; |
| 20 | break; |
| 21 | default: |
| 22 | url.pathname = '/'; |
| 23 | break; |
| 24 | } |
| 25 | |
| 26 | return url; |
| 27 | } |
| 28 | |
| 29 | export function getNumberFromUrl(url: string): number { |
| 30 | return Number.parseInt(url.split('/').pop()!, 10); |
no test coverage detected