@@ -23,9 +23,13 @@ const IGNORE_COMMAND = "Don't show again";
23
23
const PROMPT_FOR_SIGN_IN_SCOPE = 'prompt for sign in' ;
24
24
const PROMPT_FOR_SIGN_IN_STORAGE_KEY = 'login' ;
25
25
26
- const AUTH_PROVIDER_ID = 'github' ;
27
26
const SCOPES = [ 'read:user' , 'user:email' , 'repo' ] ;
28
27
28
+ export enum AuthProvider {
29
+ github = 'github' ,
30
+ 'github-enterprise' = 'github-enterprise'
31
+ }
32
+
29
33
export interface GitHub {
30
34
octokit : Octokit ;
31
35
graphql : ApolloClient < NormalizedCacheObject > | null ;
@@ -51,7 +55,17 @@ export class CredentialStore implements vscode.Disposable {
51
55
}
52
56
53
57
public async initialize ( ) : Promise < void > {
54
- const session = await vscode . authentication . getSession ( AUTH_PROVIDER_ID , SCOPES , { createIfNone : false } ) ;
58
+ const authProviderId = vscode . workspace . getConfiguration ( 'githubPullRequests' ) . get < AuthProvider > ( 'authenticationProvider' ) || AuthProvider . github ;
59
+ const session = await vscode . authentication . getSession ( authProviderId , SCOPES , { createIfNone : false } ) ;
60
+
61
+ if ( authProviderId === AuthProvider [ 'github-enterprise' ] ) {
62
+ try {
63
+ vscode . Uri . parse ( vscode . workspace . getConfiguration ( 'github-enterprise' ) . get < string > ( 'uri' ) || '' , true ) ;
64
+ } catch {
65
+ Logger . debug ( `GitHub Enterprise provider selected without Uri.` , 'Authentication' ) ;
66
+ return ;
67
+ }
68
+ }
55
69
56
70
if ( session ) {
57
71
const token = session . accessToken ;
@@ -175,22 +189,37 @@ export class CredentialStore implements vscode.Disposable {
175
189
}
176
190
177
191
private async getSessionOrLogin ( ) : Promise < string > {
178
- const session = await vscode . authentication . getSession ( AUTH_PROVIDER_ID , SCOPES , { createIfNone : true } ) ;
192
+ const authProviderId = vscode . workspace . getConfiguration ( 'githubPullRequests' ) . get < AuthProvider > ( 'authenticationProvider' ) || AuthProvider . github ;
193
+ const session = await vscode . authentication . getSession ( authProviderId , SCOPES , { createIfNone : true } ) ;
179
194
this . _sessionId = session . id ;
180
195
return session . accessToken ;
181
196
}
182
197
183
198
private async createHub ( token : string ) : Promise < GitHub > {
199
+ const authProviderId = vscode . workspace . getConfiguration ( 'githubPullRequests' ) . get < AuthProvider > ( 'authenticationProvider' ) || AuthProvider . github ;
200
+ let baseUrl = 'https://api.github.com' ;
201
+ if ( authProviderId === AuthProvider [ 'github-enterprise' ] ) {
202
+ const server = vscode . workspace . getConfiguration ( 'github-enterprise' ) . get < string > ( 'uri' ) || '' ;
203
+ const serverUri = vscode . Uri . parse ( server , true ) ;
204
+ baseUrl = `${ serverUri . scheme } ://${ serverUri . authority } /api/v3` ;
205
+ }
206
+
184
207
const octokit = new Octokit ( {
185
208
request : { agent } ,
186
209
userAgent : 'GitHub VSCode Pull Requests' ,
187
210
// `shadow-cat-preview` is required for Draft PR API access -- https://developer.github.com/v3/previews/#draft-pull-requests
188
211
previews : [ 'shadow-cat-preview' ] ,
189
212
auth : `${ token || '' } ` ,
213
+ baseUrl : baseUrl ,
190
214
} ) ;
191
215
216
+ if ( authProviderId === AuthProvider [ 'github-enterprise' ] ) {
217
+ const server = vscode . workspace . getConfiguration ( 'github-enterprise' ) . get < string > ( 'uri' ) || '' ;
218
+ const serverUri = vscode . Uri . parse ( server , true ) ;
219
+ baseUrl = `${ serverUri . scheme } ://${ serverUri . authority } /api` ;
220
+ }
192
221
const graphql = new ApolloClient ( {
193
- link : link ( 'https://api.github.com' , token || '' ) ,
222
+ link : link ( baseUrl , token || '' ) ,
194
223
cache : new InMemoryCache ( ) ,
195
224
defaultOptions : {
196
225
query : {
0 commit comments