feat: Enable /setup-github to always run, and error appropriately (#5653)

Co-authored-by: Jacob Richman <jacob314@gmail.com>
This commit is contained in:
Lee James 2025-08-06 09:06:37 -04:00 committed by GitHub
parent aab850668c
commit b38f377c9a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 8 deletions

View File

@ -32,7 +32,6 @@ import { themeCommand } from '../ui/commands/themeCommand.js';
import { toolsCommand } from '../ui/commands/toolsCommand.js'; import { toolsCommand } from '../ui/commands/toolsCommand.js';
import { vimCommand } from '../ui/commands/vimCommand.js'; import { vimCommand } from '../ui/commands/vimCommand.js';
import { setupGithubCommand } from '../ui/commands/setupGithubCommand.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 * Loads the core, hard-coded slash commands that are an integral part
@ -74,7 +73,7 @@ export class BuiltinCommandLoader implements ICommandLoader {
themeCommand, themeCommand,
toolsCommand, toolsCommand,
vimCommand, vimCommand,
...(isGitHubRepository() ? [setupGithubCommand] : []), setupGithubCommand,
]; ];
return allDefinitions.filter((cmd): cmd is SlashCommand => cmd !== null); return allDefinitions.filter((cmd): cmd is SlashCommand => cmd !== null);

View File

@ -61,6 +61,8 @@ describe('setupGithubCommand', () => {
vi.mocked(child_process.execSync).mockReturnValue(''); vi.mocked(child_process.execSync).mockReturnValue('');
expect(() => { expect(() => {
setupGithubCommand.action?.({} as CommandContext, ''); 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.',
);
}); });
}); });

View File

@ -19,12 +19,21 @@ export const setupGithubCommand: SlashCommand = {
description: 'Set up GitHub Actions', description: 'Set up GitHub Actions',
kind: CommandKind.BUILT_IN, kind: CommandKind.BUILT_IN,
action: (): SlashCommandActionReturn => { action: (): SlashCommandActionReturn => {
const gitRootRepo = execSync('git rev-parse --show-toplevel', {
encoding: 'utf-8',
}).trim();
if (!isGitHubRepository()) { 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'; const version = 'v0';