Path: blob/main/extensions/copilot/src/platform/remoteCodeSearch/vscode-node/codeSearchRepoAuth.ts
13401 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { t } from '@vscode/l10n';6import * as vscode from 'vscode';7import { IAuthenticationService } from '../../authentication/common/authentication';8import { IAuthenticationChatUpgradeService } from '../../authentication/common/authenticationUpgrade';9import { ResolvedRepoRemoteInfo } from '../../git/common/gitService';10import { ICodeSearchAuthenticationService } from '../node/codeSearchRepoAuth';111213export class VsCodeCodeSearchAuthenticationService implements ICodeSearchAuthenticationService {1415declare readonly _serviceBrand: undefined;1617constructor(18@IAuthenticationService private readonly _authService: IAuthenticationService,19@IAuthenticationChatUpgradeService private readonly _authUpgradeService: IAuthenticationChatUpgradeService,20) { }2122async tryAuthenticating(repo: ResolvedRepoRemoteInfo | undefined): Promise<void> {23const fetchUrl = repo?.fetchUrl;2425const signInButton: vscode.MessageItem = {26title: t`Sign In`,27};28const cancelButton: vscode.MessageItem = {29title: t`Cancel`,30isCloseAffordance: true31};3233if (repo?.repoId.type === 'ado') {34const result = await vscode.window.showWarningMessage(t`Sign in to use remote index`, {35modal: true,36detail: fetchUrl37? t`Sign in to Azure DevOps to use remote workspace index for: ${fetchUrl.toString()}`38: t`Sign in to Azure DevOps to use remote workspace index for a repo in this workspace`39}, signInButton, cancelButton);4041if (result === signInButton) {42await this._authService.getAdoAccessTokenBase64({ createIfNone: true });43return;44}45} else {46const result = await vscode.window.showWarningMessage(t`Sign in to use remote index`, {47modal: true,48detail: fetchUrl49? t`Sign in to GitHub to use remote workspace index for: ${fetchUrl.toString()}`50: t`Sign in to GitHub to use remote workspace index for a repo in this workspace`51}, signInButton, cancelButton);5253if (result === signInButton) {54await this._authService.getGitHubSession('any', { createIfNone: { detail: t('Sign in to GitHub to use remote workspace index.') } });55return;56}57}58}5960async tryReauthenticating(repo: ResolvedRepoRemoteInfo | undefined): Promise<void> {61const fetchUrl = repo?.fetchUrl;6263const signInButton: vscode.MessageItem = {64title: t`Sign In`,65};66const cancelButton: vscode.MessageItem = {67title: t`Cancel`,68isCloseAffordance: true69};7071if (repo?.repoId.type === 'ado') {72const result = await vscode.window.showWarningMessage(t`Reauthenticate to use remote workspace index`, {73modal: true,74detail: fetchUrl75? t`Sign in to Azure DevOps again to use remote workspace index for: ${fetchUrl}`76: t`Sign in to Azure DevOps again to use remote workspace index for a repo in this workspace`77}, signInButton, cancelButton);7879if (result === signInButton) {80await this._authService.getAdoAccessTokenBase64({ createIfNone: true });81return;82}83} else {84const result = await vscode.window.showWarningMessage(t`Reauthenticate to use remote workspace index`, {85modal: true,86detail: fetchUrl87? t`Sign in to GitHub again to use remote workspace index for: ${fetchUrl}`88: t`Sign in to GitHub again to use remote workspace index for a repo in this workspace`89}, signInButton, cancelButton);9091if (result === signInButton) {92await this._authUpgradeService.showPermissiveSessionModal();93return;94}95}96}9798async promptForExpandedLocalIndexing(fileCount: number): Promise<boolean> {99const confirmButton: vscode.MessageItem = {100title: t`Enable`,101};102const cancelButton: vscode.MessageItem = {103title: t`Cancel`,104isCloseAffordance: true105};106107const result = await vscode.window.showWarningMessage(108t`Build local index for this workspace?`,109{110modal: true,111detail: t`This workspace contains ${fileCount} files. Building a local index may take a while but will improve search performance.`,112},113confirmButton,114cancelButton115);116117return result === confirmButton;118}119}120121