feat: Enable /setup-github to always run, and error appropriately (#5653)
Co-authored-by: Jacob Richman <jacob314@gmail.com>
This commit is contained in:
parent
aab850668c
commit
b38f377c9a
|
@ -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);
|
||||||
|
|
|
@ -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.',
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -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';
|
||||||
|
|
Loading…
Reference in New Issue