From 0731d28398a13c1bbfa0bf70c8f04496e3625241 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=93lafur=20P=C3=A1ll=20Geirsson?= Date: Thu, 18 Jul 2024 14:37:47 +0200 Subject: [PATCH] CLI: fail fast if `--context-repo` does not have a matching name (#4919) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes CODY-2947 Previously, the CLI would silently continue even if `--context-repo` had a spelling or referenced a repo that doesn't exist on the instance. Now, the CLI fails fast with a helpful error message. ## Test plan Manually tested. ``` ❯ pnpm agent chat --context-repo sourcegraph/cody --context-repo github.com/sourcegraph/jetbrains -m 'what is the agent' ... ✖ The repository sourcegraph/cody does not exist on the instance. The name needs to match exactly the name of the repo as it appears on your Sourcegraph instance. Please check the spelling and try again. ``` --- agent/CHANGELOG.md | 7 +++++++ agent/package.json | 2 +- agent/src/cli/command-chat.ts | 22 ++++++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/agent/CHANGELOG.md b/agent/CHANGELOG.md index 42a226ee5a67..522646056510 100644 --- a/agent/CHANGELOG.md +++ b/agent/CHANGELOG.md @@ -10,6 +10,13 @@ This is a log of all notable changes to the Cody command-line tool. [Unreleased] ### Changed +## 5.5.10 + +### Fixed + +- Running `cody chat` should no longer report errors related to autocomplete +- Running `cody chat --context-repo REPO` now reports a helpful error if the provided repo does not exist on the instance. + ## 5.5.9 ### Added diff --git a/agent/package.json b/agent/package.json index e022b50f70fa..ecc71cdc14ec 100644 --- a/agent/package.json +++ b/agent/package.json @@ -1,6 +1,6 @@ { "name": "@sourcegraph/cody", - "version": "5.5.9", + "version": "5.5.10", "description": "Cody JSON-RPC agent for consistent cross-editor support", "license": "Apache-2.0", "repository": { diff --git a/agent/src/cli/command-chat.ts b/agent/src/cli/command-chat.ts index 0082f6ee8782..ddd55222cf16 100644 --- a/agent/src/cli/command-chat.ts +++ b/agent/src/cli/command-chat.ts @@ -192,6 +192,28 @@ export async function chatAction(options: ChatOptions): Promise { names: options.contextRepo, first: options.contextRepo.length, }) + + const invalidRepos: string[] = [] + for (const repo of options.contextRepo) { + if (!repos.some(r => r.name === repo)) { + invalidRepos.push(repo) + } + } + + if (invalidRepos.length > 0) { + const reposString = invalidRepos.join(', ') + const errorMessage = + invalidRepos.length > 1 + ? `The repositories ${invalidRepos} do not exist on the instance. ` + : `The repository '${reposString}' does not exist on the instance. ` + spinner.fail( + errorMessage + + 'The name needs to match exactly the name of the repo as it appears on your Sourcegraph instance. ' + + 'Please check the spelling and try again.' + ) + return 1 + } + await client.request('webview/receiveMessage', { id, message: {