1
>
/*---------------------------------------------------------------------------------------------
githubEndpoints.ts
2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
6
>
import { URI } from '../../../base/common/uri.js';
7
>
import { ProtectedResourceMetadata } from './state/protocol/state.js';
8
>
9
>
/**
10
>
* The GitHub endpoints an agent host talks to, derived from an optional
11
>
* GitHub Enterprise base URI. All values are string URIs with no trailing slash.
12
>
*/
13
>
export interface IGitHubEndpoints {
14
>
/** REST API base (e.g. `https://api.github.com`), used as the resource identifier and the REST host. */
15
>
readonly apiBaseUri: string;
16
>
/** GraphQL endpoint (distinct from `apiBaseUri` for on-prem: `/api/graphql`, not `/api/v3/graphql`). */
17
>
readonly graphQlUri: string;
18
>
/** OAuth authorization server URI, advertised in `authorization_servers`. */
19
>
readonly oauthServer: string;
20
>
/**
21
>
* The configured GitHub Enterprise host (authority only, e.g. `acme.ghe.com`),
22
>
* or `undefined` for github.com. Used to point the Copilot CLI at an enterprise
23
>
* host via `COPILOT_GH_HOST`.
24
>
*/
25
>
readonly enterpriseHost: string | undefined;
26
>
}
27
>
28
>
const GITHUB_DOT_COM_COPILOT_API_BASE_URI = 'https://api.githubcopilot.com';
29
>
30
>
/** Canonical github.com endpoints, used when no enterprise URI is configured. */
31
>
const GITHUB_DOT_COM_ENDPOINTS: IGitHubEndpoints = {
32
>
apiBaseUri: 'https://api.github.com',
33
>
graphQlUri: 'https://api.github.com/graphql',
34
>
oauthServer: 'https://github.com/login/oauth',
35
>
enterpriseHost: undefined,
36
>
};
37
>
38
>
/**
39
>
* Derives the {@link IGitHubEndpoints} for a GitHub Enterprise base URI, mirroring
40
>
* the URL derivation in the built-in `github-authentication` extension
41
>
* (`githubServer.ts` / `common/env.ts`):
42
>
*
43
>
* - unset / empty / unparseable → github.com defaults (byte-for-byte, preserving
44
>
* the resource identifiers used by every non-enterprise install).
45
>
* - GitHub Enterprise **Cloud** (authority ends in `.ghe.com`) → API on an `api.`
46
>
* subdomain: `https://api.<authority>`.
47
>
* - GitHub Enterprise **Server** (on-prem) → API under `/api/v3`, GraphQL under
48
>
* `/api/graphql`.
49
>
*
50
>
* The OAuth server is always `<scheme>://<authority>/login/oauth` for enterprise.
51
>
*/
52
>
export function deriveGitHubEndpoints(enterpriseUri: string | undefined): IGitHubEndpoints {
53
if (!enterpriseUri) {
54
return GITHUB_DOT_COM_ENDPOINTS;