gh-stack icon indicating copy to clipboard operation
gh-stack copied to clipboard

`gh stack view --json` omits the stack number that the text output prints

Open xn opened this issue 3 months ago • 1 comments

Summary

gh stack view prints the stack number in its human-readable output, but gh stack view --json omits it:

$ gh stack view --short
Stack #6
» stack-b-one ○ #4 (current)
...

$ gh stack view --json | jq 'keys'
[
  "branches",
  "currentBranch",
  "trunk"
]

The per-branch objects carry pr.number, pr.url and pr.state, but the stack's own identifier is nowhere in the payload.

Why this matters

The stack number is the identifier gh stack checkout and gh stack link take, and the one shown in the GitHub stack UI — so it is the natural key for any automation. Because it is missing from the machine-readable output, scripts have to scrape it from gh stack submit's human-readable text (✓ Stack created on GitHub with 2 PRs (stack #6)) or from the UI.

Expected

Include the stack number as a top-level field in --json output, e.g. "number": 6, so --json is sufficient on its own.

Environment

  • gh 2.97.0
  • gh-stack v0.1.0
  • git 2.50.1
  • macOS 26.4.1, darwin/arm64

xn avatar Aug 07 '26 15:08 xn

I implemented and validated a focused fix for this issue, but the repository currently restricts opening pull requests to collaborators.

The patch is available here:

Daniele-Cangi/gh-stack:fix/view-json-stack-number

Commit:

28ddb979b3bf1e721aed073d35a7f0fa4598235e

The change is intentionally limited to #416:

  • adds the repo-scoped stack number as a top-level field in gh stack view --json;
  • preserves all existing JSON fields and behavior;
  • explicitly emits "number": 0 for local-only stacks;
  • adds coverage verifying that the zero-valued key is actually present;
  • updates the agent skill documentation accordingly.

Validation completed successfully:

  • focused view tests;
  • go vet ./...;
  • go test -race -count=1 ./...;
  • git diff --check.

Only cmd/view.go, cmd/view_test.go, and skills/gh-stack/SKILL.md are changed.

I also checked for an existing implementation or competing PR before starting and did not find one.

Since I can't open the PR under the current repository policy, I'm leaving the tested branch here in case a maintainer would like to review/cherry-pick it or suggest the preferred contribution path.

Daniele-Cangi avatar Aug 10 '26 11:08 Daniele-Cangi