Skip to content

refactor to use more go-gh#16

Merged
boneskull merged 6 commits intomainfrom
go-gh-refactor
Feb 3, 2026
Merged

refactor to use more go-gh#16
boneskull merged 6 commits intomainfrom
go-gh-refactor

Conversation

@boneskull
Copy link
Copy Markdown
Owner

refactor(log): use go-gh pkg/tableprinter for porcelain output

Replace manual tab-separated output with go-gh tableprinter for the
--porcelain flag. The tableprinter automatically adapts to the output:

  • TTY mode: Nicely formatted columns with headers, current branch
    marked with '*' prefix, column widths fit to terminal
  • Non-TTY mode: Clean TSV output for scripting (unchanged behavior)

This ensures consistent output formatting with other gh CLI commands.

feat(submit): add --web flag to open PRs in browser

Add -w/--web flag to the submit command that opens created or updated
PRs in the default web browser after submission completes.

Uses github.com/cli/go-gh/v2/pkg/browser which respects:

  • GH_BROWSER environment variable
  • browser setting in gh config
  • BROWSER environment variable

The browser package also includes security validation for URLs.

refactor(prompt): use go-gh pkg/prompter for interactive prompts

Replace custom Input, Confirm, and Select implementations with
github.com/cli/go-gh/v2/pkg/prompter (survey-based prompts).

Benefits:

  • Arrow key navigation for Select instead of typing numbers
  • Type-to-filter in long option lists
  • Better handling of terminal edge cases (resizing, interrupts)
  • Consistent UX with gh CLI extensions

The survey library is added as a transitive dependency through go-gh.

refactor(prompt): use go-gh pkg/term for terminal detection

Replace github.com/mattn/go-isatty with github.com/cli/go-gh/v2/pkg/term
for terminal detection. This ensures gh-stack respects the same environment
variables as the gh CLI:

  • GH_FORCE_TTY: Force TTY mode (useful for CI testing)
  • NO_COLOR: Disable color output
  • CLICOLOR / CLICOLOR_FORCE: Control color behavior

The direct go-isatty dependency is removed (now transitive via go-gh).

Replace github.com/mattn/go-isatty with github.com/cli/go-gh/v2/pkg/term
for terminal detection. This ensures gh-stack respects the same environment
variables as the gh CLI:

- GH_FORCE_TTY: Force TTY mode (useful for CI testing)
- NO_COLOR: Disable color output
- CLICOLOR / CLICOLOR_FORCE: Control color behavior

The direct go-isatty dependency is removed (now transitive via go-gh).
Replace custom Input, Confirm, and Select implementations with
github.com/cli/go-gh/v2/pkg/prompter (survey-based prompts).

Benefits:
- Arrow key navigation for Select instead of typing numbers
- Type-to-filter in long option lists
- Better handling of terminal edge cases (resizing, interrupts)
- Consistent UX with gh CLI extensions

The survey library is added as a transitive dependency through go-gh.
Add -w/--web flag to the submit command that opens created or updated
PRs in the default web browser after submission completes.

Uses github.com/cli/go-gh/v2/pkg/browser which respects:
- GH_BROWSER environment variable
- browser setting in gh config
- BROWSER environment variable

The browser package also includes security validation for URLs.
Replace manual tab-separated output with go-gh tableprinter for the
--porcelain flag. The tableprinter automatically adapts to the output:

- TTY mode: Nicely formatted columns with headers, current branch
  marked with '*' prefix, column widths fit to terminal
- Non-TTY mode: Clean TSV output for scripting (unchanged behavior)

This ensures consistent output formatting with other gh CLI commands.
@boneskull
Copy link
Copy Markdown
Owner Author

Stack


Managed by gh-stack

Copilot AI review requested due to automatic review settings February 3, 2026 22:57
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors gh-stack to use standardized packages from go-gh for terminal detection, interactive prompts, table printing, and browser launching. It also adds a new --web flag to the submit command that opens PRs in the browser after creation/update.

Changes:

  • Replaced custom prompt implementations with go-gh/v2/pkg/prompter (survey-based) for better UX with arrow key navigation and type-to-filter
  • Replaced go-isatty with go-gh/v2/pkg/term for terminal detection with environment variable support (GH_FORCE_TTY, NO_COLOR, etc.)
  • Replaced manual TSV output with go-gh/v2/pkg/tableprinter for consistent formatting in the log command
  • Added --web/-w flag to submit command using go-gh/v2/pkg/browser for opening PRs in the default browser

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
internal/prompt/prompt.go Refactored to use go-gh prompter and term packages, replacing custom implementations with survey-based prompts
cmd/log.go Replaced manual tab-separated output with tableprinter for consistent formatting between TTY and non-TTY modes
cmd/submit.go Added --web flag to open PRs in browser after creation/update, with proper flag propagation through helper functions
cmd/continue.go Updated function signatures to match submit.go changes for the new openWeb parameter
go.mod Added new dependencies for survey, tableprinter, browser, and related transitive dependencies
go.sum Updated checksums for all new and updated dependencies

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Running `gh stack submit` while on the trunk branch would incorrectly
attempt to force-push trunk and create a PR for it. Now the command:

- On trunk: only submits descendant stack branches
- On trunk with `--current-only`: errors with clear guidance
- On trunk with no descendants: errors indicating empty stack
- log: Use large terminal width (4096) for non-TTY mode since
  tableprinter outputs TSV format where width is irrelevant

- submit/continue: Preserve `--web` flag in cascade state so it
  works correctly when continuing after conflict resolution
Copilot AI review requested due to automatic review settings February 3, 2026 23:12
@boneskull boneskull merged commit 3b0843c into main Feb 3, 2026
10 checks passed
@boneskull boneskull deleted the go-gh-refactor branch February 3, 2026 23:15
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 9 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@boneskull boneskull mentioned this pull request Feb 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants