Skip to content

Commit

Permalink
Include checking for github-enterprise (#237993)
Browse files Browse the repository at this point in the history
* Include checking for `github-enterprise`

So that we hide the setup view for GHE.com users after they install Copilot & sign in.

Note: this behavior still isn't great if they haven't yet installed Copilot, but to keep this candidate small, we're just focused on fixing the case for when they have Copilot installed already.

* Check setting
  • Loading branch information
TylerLeonhardt authored Jan 15, 2025
1 parent 91fbddd commit 7f37b1e
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions src/vs/workbench/contrib/chat/browser/chatSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const defaultChat = {
skusDocumentationUrl: product.defaultChatAgent?.skusDocumentationUrl ?? '',
publicCodeMatchesUrl: product.defaultChatAgent?.publicCodeMatchesUrl ?? '',
upgradePlanUrl: product.defaultChatAgent?.upgradePlanUrl ?? '',
providerId: product.defaultChatAgent?.providerId ?? '',
providerIds: [product.defaultChatAgent?.providerId ?? '', 'github-enterprise'],
providerName: product.defaultChatAgent?.providerName ?? '',
providerScopes: product.defaultChatAgent?.providerScopes ?? [[]],
entitlementUrl: product.defaultChatAgent?.entitlementUrl ?? '',
Expand Down Expand Up @@ -366,7 +366,8 @@ class ChatSetupRequests extends Disposable {
@IRequestService private readonly requestService: IRequestService,
@IChatQuotasService private readonly chatQuotasService: IChatQuotasService,
@IDialogService private readonly dialogService: IDialogService,
@IOpenerService private readonly openerService: IOpenerService
@IOpenerService private readonly openerService: IOpenerService,
@IConfigurationService private readonly configurationService: IConfigurationService
) {
super();

Expand All @@ -379,19 +380,19 @@ class ChatSetupRequests extends Disposable {
this._register(this.authenticationService.onDidChangeDeclaredProviders(() => this.resolve()));

this._register(this.authenticationService.onDidChangeSessions(e => {
if (e.providerId === defaultChat.providerId) {
if (defaultChat.providerIds.includes(e.providerId)) {
this.resolve();
}
}));

this._register(this.authenticationService.onDidRegisterAuthenticationProvider(e => {
if (e.id === defaultChat.providerId) {
if (defaultChat.providerIds.includes(e.id)) {
this.resolve();
}
}));

this._register(this.authenticationService.onDidUnregisterAuthenticationProvider(e => {
if (e.id === defaultChat.providerId) {
if (defaultChat.providerIds.includes(e.id)) {
this.resolve();
}
}));
Expand Down Expand Up @@ -438,9 +439,20 @@ class ChatSetupRequests extends Disposable {
}

private async findMatchingProviderSession(token: CancellationToken): Promise<AuthenticationSession | undefined> {
const sessions = await this.authenticationService.getSessions(defaultChat.providerId);
if (token.isCancellationRequested) {
return undefined;
let sessions: ReadonlyArray<AuthenticationSession> = [];
const authProviderConfigValue = this.configurationService.getValue<string | undefined>('github.copilot.advanced.authProvider');
if (authProviderConfigValue) {
sessions = await this.authenticationService.getSessions(authProviderConfigValue);
} else {
for (const providerId of defaultChat.providerIds) {
if (token.isCancellationRequested) {
return undefined;
}
sessions = await this.authenticationService.getSessions(providerId);
if (sessions.length) {
break;
}
}
}

for (const session of sessions) {
Expand Down Expand Up @@ -787,7 +799,7 @@ class ChatSetupController extends Disposable {
}

if (!session) {
session = (await this.authenticationService.getSessions(defaultChat.providerId)).at(0);
session = (await this.authenticationService.getSessions(defaultChat.providerIds[0])).at(0);
if (!session) {
return; // unexpected
}
Expand Down Expand Up @@ -817,7 +829,7 @@ class ChatSetupController extends Disposable {
try {
showCopilotView(this.viewsService, this.layoutService);

session = await this.authenticationService.createSession(defaultChat.providerId, defaultChat.providerScopes[0]);
session = await this.authenticationService.createSession(defaultChat.providerIds[0], defaultChat.providerScopes[0]);
entitlement = await this.requests.forceResolveEntitlement(session);
} catch (error) {
// noop
Expand Down

0 comments on commit 7f37b1e

Please sign in to comment.