Path: blob/main/extensions/copilot/src/platform/remoteCodeSearch/node/codeSearchRepoAuth.ts
13400 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 * as l10n from '@vscode/l10n';6import { createDecorator as createServiceIdentifier } from '../../../util/vs/platform/instantiation/common/instantiation';7import { IAuthenticationService } from '../../authentication/common/authentication';8import { ResolvedRepoRemoteInfo } from '../../git/common/gitService';910export const ICodeSearchAuthenticationService = createServiceIdentifier<ICodeSearchAuthenticationService>('ICodeSearchAuthentication');1112export interface ICodeSearchAuthenticationService {13readonly _serviceBrand: undefined;1415tryAuthenticating(repo: ResolvedRepoRemoteInfo | undefined): Promise<void>;16tryReauthenticating(repo: ResolvedRepoRemoteInfo | undefined): Promise<void>;1718promptForExpandedLocalIndexing(fileCount: number): Promise<boolean>;19}2021export class BasicCodeSearchAuthenticationService implements ICodeSearchAuthenticationService {2223declare readonly _serviceBrand: undefined;2425constructor(26@IAuthenticationService private readonly _authenticationService: IAuthenticationService,27) { }2829async tryAuthenticating(remoteInfo: ResolvedRepoRemoteInfo | undefined): Promise<void> {30if (remoteInfo?.repoId?.type === 'ado') {31await this._authenticationService.getAdoAccessTokenBase64({ createIfNone: true });32return;33}3435await this._authenticationService.getGitHubSession('any', { createIfNone: { detail: l10n.t('Sign in to GitHub to use remote code search.') } });36}3738async tryReauthenticating(remoteInfo: ResolvedRepoRemoteInfo | undefined): Promise<void> {39if (remoteInfo?.repoId?.type === 'ado') {40await this._authenticationService.getAdoAccessTokenBase64({ createIfNone: true });41return;42}4344await this._authenticationService.getGitHubSession('permissive', { createIfNone: { detail: l10n.t('Sign in to GitHub with additional permissions for remote code search.') } });45}4647async promptForExpandedLocalIndexing(fileCount: number): Promise<boolean> {48// Can't show prompt here49return false;50}51}5253