fix(issue): treat view id as issue number
Support --id as alias for --number in issue +view command. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
a91d553130
commit
18975162a1
|
|
@ -93,13 +93,14 @@ func Shortcuts() []*common.Shortcut {
|
|||
Name: "view",
|
||||
Description: "View issue details",
|
||||
Flags: []common.Flag{
|
||||
{Name: "number", Short: "n", Usage: "Issue number (as shown in the web URL)", Required: true},
|
||||
{Name: "number", Short: "n", Usage: "Issue number (as shown in the web URL)"},
|
||||
{Name: "id", Usage: "Alias for --number; uses the issue number from the web URL"},
|
||||
},
|
||||
Run: func(ctx *common.RuntimeContext) error {
|
||||
if err := ctx.ResolveOwnerRepo(); err != nil {
|
||||
return err
|
||||
}
|
||||
number, err := ctx.RequireArg("number")
|
||||
number, err := issueNumberArg(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -331,3 +332,13 @@ func normalizeIssueStatus(state string) (interface{}, error) {
|
|||
return nil, fmt.Errorf("invalid --state %q: use open, closed, or a numeric status_id", state)
|
||||
}
|
||||
}
|
||||
|
||||
func issueNumberArg(ctx *common.RuntimeContext) (string, error) {
|
||||
if number := strings.TrimSpace(ctx.Arg("number")); number != "" {
|
||||
return number, nil
|
||||
}
|
||||
if id := strings.TrimSpace(ctx.Arg("id")); id != "" {
|
||||
return id, nil
|
||||
}
|
||||
return "", fmt.Errorf("required flag --number (or --id alias) not set")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -153,6 +153,28 @@ func TestIssueViewMissingNumber(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestIssueViewAcceptsIDAsNumberAlias(t *testing.T) {
|
||||
var requestedPath string
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
requestedPath = r.URL.Path
|
||||
if r.Method != "GET" || r.URL.Path != "/v1/owner/repo/issues/29.json" {
|
||||
t.Fatalf("unexpected request: %s %s", r.Method, r.URL.Path)
|
||||
}
|
||||
writeJSON(w, map[string]interface{}{
|
||||
"project_issues_index": 29,
|
||||
"subject": "Issue from web URL",
|
||||
})
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
err := runShortcut(t, server, "view", map[string]string{"id": "29"})
|
||||
if err != nil {
|
||||
t.Fatalf("view shortcut failed: %v", err)
|
||||
}
|
||||
|
||||
assertEqual(t, requestedPath, "/v1/owner/repo/issues/29.json")
|
||||
}
|
||||
|
||||
// --- close ---
|
||||
|
||||
func TestIssueClose(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue