$ show github/gh-stack
gh-stack is a GitHub CLI extension for managing stacked pull requests. It allows developers to create a stack of branches, each building on the previous one, and submit them as a chain of PRs. The tool handles rebasing, syncing, pushing, and merging the stack atomically, with both interactive TUI and non-interactive CLI modes. The architecture is a Go CLI built with Cobra, using Bubble Tea for interactive TUI components and lipgloss for styling. Git operations are abstracted behind an interface (internal/git/gitops.go) with mock support for testing. GitHub API integration is handled via go-gh, supporting GraphQL and REST endpoints for PR creation, stack management, and async merge. Local stack state is persisted as a JSON file in the git directory with optimistic concurrency and file locking. Key entry points include main.go calling cmd.Execute(), which registers all subcommands (init, add, submit, sync, rebase, push, merge, checkout, etc.). External dependencies include the GitHub CLI (gh), git, and the GitHub API. The codebase demonstrates strong engineering practices with extensive test coverage, interface-based mocking, and a modular internal package structure.
The LLM identified 4 files worth highlighting for reuse:
Provides platform-specific file locking (flock on Unix, LockFileEx on Windows) with retry logic and stale detection via checksum. This is a self-contained, reusable pattern for any Go application that needs safe concurrent access to a local state file.
Implements a background-aware color theme using lipgloss.AdaptiveColor, with an environment variable override (GH_STACK_THEME). This is a clean, self-contained module that can be extracted and reused in any terminal application needing light/dark theme support.
Provides a reusable scroll helper for Bubble Tea TUI views, handling scroll position, content height, and viewport clipping. This is a common pattern in terminal UIs and is implemented cleanly without tight coupling to the rest of the codebase.
Discovers PR templates from the repository using the cli/cli githubtemplate package. This is a self-contained utility that can be reused in any GitHub CLI extension or tool that needs to locate and parse PR templates.