From 036a2e6aa103f759f29bce5cd742a1c17704d5c8 Mon Sep 17 00:00:00 2001 From: Alex Ross Date: Wed, 4 Dec 2024 10:28:22 +0100 Subject: [PATCH] Chat participant wrongly claims there are not GitHub remotes, when not logged in (#6505) Fixes #6502 --- src/common/authentication.ts | 6 ++++-- src/github/githubRepository.ts | 2 +- src/lm/tools/toolsUtils.ts | 6 +++++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/common/authentication.ts b/src/common/authentication.ts index 1335fec005..8255b83e7d 100644 --- a/src/common/authentication.ts +++ b/src/common/authentication.ts @@ -3,6 +3,8 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ +import * as vscode from 'vscode'; + export enum GitHubServerType { None, GitHubDotCom, @@ -15,8 +17,8 @@ export enum AuthProvider { } export class AuthenticationError extends Error { - constructor(message: string) { - super(message); + constructor() { + super(vscode.l10n.t('Not authenticated')); } } diff --git a/src/github/githubRepository.ts b/src/github/githubRepository.ts index ec27c6771e..82d50a9af3 100644 --- a/src/github/githubRepository.ts +++ b/src/github/githubRepository.ts @@ -157,7 +157,7 @@ export class GitHubRepository extends Disposable { if (!this._initialized) { throw new Error('Call ensure() before accessing this property.'); } else { - throw new AuthenticationError('Not authenticated.'); + throw new AuthenticationError(); } } return this._hub; diff --git a/src/lm/tools/toolsUtils.ts b/src/lm/tools/toolsUtils.ts index 31ffa4487e..87f00fd422 100644 --- a/src/lm/tools/toolsUtils.ts +++ b/src/lm/tools/toolsUtils.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import * as vscode from 'vscode'; -import { AuthProvider } from '../../common/authentication'; +import { AuthenticationError, AuthProvider } from '../../common/authentication'; import { CredentialStore, GitHub } from '../../github/credentials'; import { FolderRepositoryManager } from '../../github/folderRepositoryManager'; import { RepositoriesManager } from '../../github/repositoriesManager'; @@ -55,6 +55,10 @@ export abstract class RepoToolBase extends ToolBase { } protected async getRepoInfo(options: { owner?: string, name?: string }): Promise<{ owner: string; name: string; folderManager: FolderRepositoryManager }> { + if (!this.credentialStore.isAnyAuthenticated()) { + throw new AuthenticationError(); + } + let owner: string | undefined; let name: string | undefined; let folderManager: FolderRepositoryManager | undefined;