Skip to content

Commit bc6c5fc

Browse files
authored
fix: avoid double-prefixing in buildCommandHint for slashed args (CLI-8C) (#527)
## Summary Fixes `buildCommandHint()` producing nonsensical error hints when the user-provided issue arg already contains a slash. ### Bug (CLI-8C — 50 events, 8 users) When a user passes `saber-ut/103103195` to `sentry issue view`, the error path calls `buildCommandHint("view", "saber-ut/103103195")`. Since the input contains a dash, it fell through to the final branch and produced: ``` sentry issue view <org>/saber-ut/103103195 ``` This is wrong — the user already provided the org prefix `saber-ut`. ### Fix Add an early check: if the input already contains a `/`, it has org context embedded — show it as-is without adding another `<org>/` prefix. ### Test cases added - `saber-ut/103103195` → `sentry issue view saber-ut/103103195` - `sentry/cli-G` → `sentry issue view sentry/cli-G` - `sentry/cli/CLI-A1` → `sentry issue explain sentry/cli/CLI-A1`
1 parent 5e5a4e6 commit bc6c5fc

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

src/commands/issue/utils.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export const issueIdPositional = {
6363
* Build a command hint string for error messages.
6464
*
6565
* Returns context-aware hints based on the issue ID format:
66+
* - Already contains `/` (e.g., "saber-ut/103103195") → show as-is (already has context)
6667
* - Numeric ID (e.g., "123456789") → suggest `<org>/123456789`
6768
* - Suffix only (e.g., "G") → suggest `<project>-G`
6869
* - Has dash (e.g., "cli-G") → suggest `<org>/cli-G`
@@ -75,6 +76,10 @@ export function buildCommandHint(command: string, issueId: string): string {
7576
if (issueId.startsWith("@")) {
7677
return `sentry issue ${command} <org>/${issueId}`;
7778
}
79+
// Input already contains org/project context — show as-is to avoid double-prefixing
80+
if (issueId.includes("/")) {
81+
return `sentry issue ${command} ${issueId}`;
82+
}
7883
// Numeric IDs always need org context - can't be combined with project
7984
if (isAllDigits(issueId)) {
8085
return `sentry issue ${command} <org>/${issueId}`;

test/commands/issue/utils.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,21 @@ describe("buildCommandHint", () => {
5656
"sentry issue explain <org>/@most_frequent"
5757
);
5858
});
59+
60+
test("shows as-is when input already contains a slash (CLI-8C)", () => {
61+
// org/numeric — don't add another <org>/ prefix
62+
expect(buildCommandHint("view", "saber-ut/103103195")).toBe(
63+
"sentry issue view saber-ut/103103195"
64+
);
65+
// org/project-suffix — already has full context
66+
expect(buildCommandHint("view", "sentry/cli-G")).toBe(
67+
"sentry issue view sentry/cli-G"
68+
);
69+
// org/project/suffix — three-level path, show as-is
70+
expect(buildCommandHint("explain", "sentry/cli/CLI-A1")).toBe(
71+
"sentry issue explain sentry/cli/CLI-A1"
72+
);
73+
});
5974
});
6075

6176
const getConfigDir = useTestConfigDir("test-issue-utils-", {

0 commit comments

Comments
 (0)