$ show ezyang/ghstack
ghstack is a Python CLI tool that enables developers to work with stacked pull requests on GitHub. It manages a stack of diffs as separate PRs using a specific branch naming convention (gh/username/N/{base,head,orig}). The tool provides subcommands for submitting, landing, checking out, pulling, cherry-picking, logging, syncing, unlinking, and managing stacked PRs. It interacts with GitHub via both GraphQL and REST APIs asynchronously (aiohttp) and relies heavily on git operations for branch and commit management. The codebase is modular with abstract endpoint classes for testability, a fake GitHub endpoint for offline testing, and a comprehensive test suite using custom pytest collection of .py.test files. Its primary value is enabling the 'stacked diff' workflow on GitHub, which is common in large engineering organizations but poorly supported natively.
The LLM identified 3 files worth highlighting for reuse:
Provides robust parsing and manipulation of Git commit message trailers (subject, body, and key-value trailers). Uses a finite-state machine approach rather than fragile regex, correctly handling continuation lines and multiple trailers. The module is self-contained (no ghstack-specific imports) and can be extracted as a reusable library for any tool that needs to parse or modify git commit message trailers.
Implements a simple, durable key-value cache backed by SQLite with time-based eviction. The cache is parameterized by a table name, making it suitable for caching different types of data (e.g., CircleCI build results). It handles concurrent access with a single global connection (not thread-safe but adequate for synchronous usage). The pattern is straightforward and could be extracted for any project needing a persistent disk cache with minimal dependencies.
Defines the abstract `GitHubEndpoint` class that declares the async interface for all GitHub API interactions (PR creation/update, querying, etc.). This pattern enables the testing infrastructure with `FakeGitHubEndpoint` without requiring network calls. The interface is clean, with each method returning typed dataclasses. While the method signatures are specific to ghstack's domain, the abstract-interface pattern itself is reusable for any project needing mockable API clients.