diff options
| author | Allen Hutchison <[email protected]> | 2025-06-14 00:00:24 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-06-14 07:00:24 +0000 |
| commit | 643bdf31d50868e5644a1257afabed612ba317c7 (patch) | |
| tree | 987d7e3600987c32c21a017d1ee1b3b7f14dae6c /packages/cli/src | |
| parent | d5c6bb9740a52d87b71d812e698d0e88abf10caa (diff) | |
feat: Add custom URL support for the /bug command (#1017)
Diffstat (limited to 'packages/cli/src')
| -rw-r--r-- | packages/cli/src/config/config.ts | 1 | ||||
| -rw-r--r-- | packages/cli/src/config/settings.ts | 7 | ||||
| -rw-r--r-- | packages/cli/src/ui/hooks/slashCommandProcessor.test.ts | 42 | ||||
| -rw-r--r-- | packages/cli/src/ui/hooks/slashCommandProcessor.ts | 13 |
4 files changed, 56 insertions, 7 deletions
diff --git a/packages/cli/src/config/config.ts b/packages/cli/src/config/config.ts index 099d91d9..c1e51b16 100644 --- a/packages/cli/src/config/config.ts +++ b/packages/cli/src/config/config.ts @@ -211,6 +211,7 @@ export async function loadCliConfig( telemetryOtlpEndpoint: process.env.OTEL_EXPORTER_OTLP_ENDPOINT ?? settings.telemetryOtlpEndpoint, fileDiscoveryService: fileService, + bugCommand: settings.bugCommand, }); } diff --git a/packages/cli/src/config/settings.ts b/packages/cli/src/config/settings.ts index bf9adb45..a0030a05 100644 --- a/packages/cli/src/config/settings.ts +++ b/packages/cli/src/config/settings.ts @@ -7,7 +7,11 @@ import * as fs from 'fs'; import * as path from 'path'; import { homedir } from 'os'; -import { MCPServerConfig, getErrorMessage } from '@gemini-cli/core'; +import { + MCPServerConfig, + getErrorMessage, + BugCommandSettings, +} from '@gemini-cli/core'; import stripJsonComments from 'strip-json-comments'; import { DefaultLight } from '../ui/themes/default-light.js'; import { DefaultDark } from '../ui/themes/default.js'; @@ -40,6 +44,7 @@ export interface Settings { telemetry?: boolean; telemetryOtlpEndpoint?: string; preferredEditor?: string; + bugCommand?: BugCommandSettings; // Git-aware file filtering settings fileFiltering?: { diff --git a/packages/cli/src/ui/hooks/slashCommandProcessor.test.ts b/packages/cli/src/ui/hooks/slashCommandProcessor.test.ts index 73669651..3e0a768c 100644 --- a/packages/cli/src/ui/hooks/slashCommandProcessor.test.ts +++ b/packages/cli/src/ui/hooks/slashCommandProcessor.test.ts @@ -129,6 +129,7 @@ describe('useSlashCommandProcessor', () => { getModel: vi.fn(() => 'test-model'), getProjectRoot: vi.fn(() => '/test/dir'), getCheckpointEnabled: vi.fn(() => true), + getBugCommand: vi.fn(() => undefined), } as unknown as Config; mockCorgiMode = vi.fn(); mockUseSessionStats.mockReturnValue({ @@ -418,6 +419,47 @@ Add any other context about the problem here. expect(open).toHaveBeenCalledWith(expectedUrl); expect(commandResult).toBe(true); }); + + it('should use the custom bug command URL from config if available', async () => { + const bugCommand = { + urlTemplate: + 'https://custom-bug-tracker.com/new?title={title}&body={body}', + }; + mockConfig = { + ...mockConfig, + getBugCommand: vi.fn(() => bugCommand), + } as unknown as Config; + + const { handleSlashCommand } = getProcessor(); + const bugDescription = 'This is a custom bug'; + const diagnosticInfo = ` +## Describe the bug +A clear and concise description of what the bug is. + +## Additional context +Add any other context about the problem here. + +## Diagnostic Information +* **CLI Version:** unknown +* **Git Commit:** ${GIT_COMMIT_INFO} +* **Operating System:** test-platform test-node-version +* **Sandbox Environment:** no sandbox +* **Model Version:** test-model +* **Memory Usage:** 11.8 MB +`; + const expectedUrl = bugCommand.urlTemplate + .replace('{title}', encodeURIComponent(bugDescription)) + .replace('{body}', encodeURIComponent(diagnosticInfo)); + + let commandResult: SlashCommandActionReturn | boolean = false; + await act(async () => { + commandResult = await handleSlashCommand(`/bug ${bugDescription}`); + }); + + expect(mockAddItem).toHaveBeenCalledTimes(2); + expect(open).toHaveBeenCalledWith(expectedUrl); + expect(commandResult).toBe(true); + }); }); describe('/quit and /exit commands', () => { diff --git a/packages/cli/src/ui/hooks/slashCommandProcessor.ts b/packages/cli/src/ui/hooks/slashCommandProcessor.ts index 97374e4f..9a9b7596 100644 --- a/packages/cli/src/ui/hooks/slashCommandProcessor.ts +++ b/packages/cli/src/ui/hooks/slashCommandProcessor.ts @@ -512,13 +512,14 @@ Add any other context about the problem here. `; let bugReportUrl = - 'https://github.com/google-gemini/gemini-cli/issues/new?template=bug_report.md'; - if (bugDescription) { - const encodedArgs = encodeURIComponent(bugDescription); - bugReportUrl += `&title=${encodedArgs}`; + 'https://github.com/google-gemini/gemini-cli/issues/new?template=bug_report.md&title={title}&body={body}'; + const bugCommand = config?.getBugCommand(); + if (bugCommand?.urlTemplate) { + bugReportUrl = bugCommand.urlTemplate; } - const encodedBody = encodeURIComponent(diagnosticInfo); - bugReportUrl += `&body=${encodedBody}`; + bugReportUrl = bugReportUrl + .replace('{title}', encodeURIComponent(bugDescription)) + .replace('{body}', encodeURIComponent(diagnosticInfo)); addMessage({ type: MessageType.INFO, |
