From b38f377c9a2672e88dd15119b38d908c0f00b54a Mon Sep 17 00:00:00 2001 From: Lee James <40045512+leehagoodjames@users.noreply.github.com> Date: Wed, 6 Aug 2025 09:06:37 -0400 Subject: [PATCH] feat: Enable /setup-github to always run, and error appropriately (#5653) Co-authored-by: Jacob Richman --- .../cli/src/services/BuiltinCommandLoader.ts | 3 +-- .../ui/commands/setupGithubCommand.test.ts | 4 +++- .../cli/src/ui/commands/setupGithubCommand.ts | 19 ++++++++++++++----- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/packages/cli/src/services/BuiltinCommandLoader.ts b/packages/cli/src/services/BuiltinCommandLoader.ts index 46ecb37c..c09f7c61 100644 --- a/packages/cli/src/services/BuiltinCommandLoader.ts +++ b/packages/cli/src/services/BuiltinCommandLoader.ts @@ -32,7 +32,6 @@ import { themeCommand } from '../ui/commands/themeCommand.js'; import { toolsCommand } from '../ui/commands/toolsCommand.js'; import { vimCommand } from '../ui/commands/vimCommand.js'; import { setupGithubCommand } from '../ui/commands/setupGithubCommand.js'; -import { isGitHubRepository } from '../utils/gitUtils.js'; /** * Loads the core, hard-coded slash commands that are an integral part @@ -74,7 +73,7 @@ export class BuiltinCommandLoader implements ICommandLoader { themeCommand, toolsCommand, vimCommand, - ...(isGitHubRepository() ? [setupGithubCommand] : []), + setupGithubCommand, ]; return allDefinitions.filter((cmd): cmd is SlashCommand => cmd !== null); diff --git a/packages/cli/src/ui/commands/setupGithubCommand.test.ts b/packages/cli/src/ui/commands/setupGithubCommand.test.ts index 891c84e7..ae6378c7 100644 --- a/packages/cli/src/ui/commands/setupGithubCommand.test.ts +++ b/packages/cli/src/ui/commands/setupGithubCommand.test.ts @@ -61,6 +61,8 @@ describe('setupGithubCommand', () => { vi.mocked(child_process.execSync).mockReturnValue(''); expect(() => { setupGithubCommand.action?.({} as CommandContext, ''); - }).toThrow('Unable to determine the Git root directory.'); + }).toThrow( + 'Unable to determine the GitHub repository. /setup-github must be run from a git repository.', + ); }); }); diff --git a/packages/cli/src/ui/commands/setupGithubCommand.ts b/packages/cli/src/ui/commands/setupGithubCommand.ts index 445c0e76..047e11eb 100644 --- a/packages/cli/src/ui/commands/setupGithubCommand.ts +++ b/packages/cli/src/ui/commands/setupGithubCommand.ts @@ -19,12 +19,21 @@ export const setupGithubCommand: SlashCommand = { description: 'Set up GitHub Actions', kind: CommandKind.BUILT_IN, action: (): SlashCommandActionReturn => { - const gitRootRepo = execSync('git rev-parse --show-toplevel', { - encoding: 'utf-8', - }).trim(); - if (!isGitHubRepository()) { - throw new Error('Unable to determine the Git root directory.'); + throw new Error( + 'Unable to determine the GitHub repository. /setup-github must be run from a git repository.', + ); + } + + let gitRootRepo: string; + try { + gitRootRepo = execSync('git rev-parse --show-toplevel', { + encoding: 'utf-8', + }).trim(); + } catch { + throw new Error( + 'Unable to determine the GitHub repository. /setup-github must be run from a git repository.', + ); } const version = 'v0';