Normalize issue +list output to use project-level issue numbers

The API returns both "id" (global database PK) and "project_issues_index"
(per-project sequential number). The +list JSON output was a raw API
pass-through, making the database ID the most prominent identifier.

This change normalizes each issue in the list:
- Add "number" field from project_issues_index (matches the web URL)
- Rename "id" to "database_id" to prevent confusion

The "number" field now matches the --number flag used by +view, +close,
+update, and +comment commands.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Tiger 2026-05-24 01:00:31 +08:00
parent cbe9186c5c
commit 64c0ff3cb5
1 changed files with 32 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import (
"strconv"
"strings"
"github.com/gitlink-org/gitlink-cli/internal/output"
"github.com/gitlink-org/gitlink-cli/shortcuts/common"
)
@ -44,6 +45,7 @@ func Shortcuts() []*common.Shortcut {
if err != nil {
return err
}
normalizeIssueListIDs(env)
return ctx.Output(env)
},
},
@ -224,6 +226,36 @@ func Shortcuts() []*common.Shortcut {
}
}
// normalizeIssueListIDs adds "number" (project_issues_index) and renames
// "id" to "database_id" so the user-facing output uses the project-level
// issue number, not the global database primary key.
func normalizeIssueListIDs(env *output.Envelope) {
data, ok := env.Data.(map[string]interface{})
if !ok {
return
}
issues, ok := data["issues"].([]interface{})
if !ok {
return
}
for i, item := range issues {
issue, ok := item.(map[string]interface{})
if !ok {
continue
}
// Copy project_issues_index to top-level "number"
if num, ok := issue["project_issues_index"]; ok {
issue["number"] = num
}
// Rename "id" (global database PK) to "database_id"
if id, ok := issue["id"]; ok {
issue["database_id"] = id
delete(issue, "id")
}
issues[i] = issue
}
}
func fetchExistingIssue(ctx *common.RuntimeContext, number string) (*existingIssue, error) {
getEnv, err := ctx.CallAPI("GET", fmt.Sprintf("%s/issues/%s", v1RepoPath(ctx), number), nil)
if err != nil {