Skip to content

Conversation

@luqven
Copy link
Owner

@luqven luqven commented Dec 29, 2025

Summary

Add stack discovery API for finding PR stacks by walking base/head branch chains.

This enables gh-stack to find related PRs without requiring identifier patterns in titles - a key foundation for making the log command's identifier optional.

Changes

  • New file: src/api/stack.rs - Stack discovery module with:

    • fetch_pr_by_head() - Find PR by head branch name
    • fetch_prs_by_base() - Find all PRs targeting a base branch
    • fetch_all_open_prs() - Get all open PRs in a repo
    • discover_stack() - Walk up/down to find full connected stack
    • discover_all_stacks() - Group all PRs into separate stacks
  • Modified: src/api/mod.rs - Export new stack module

Algorithm

discover_stack works by:

  1. Starting from a given PR
  2. Walking UP: following base branches until hitting trunk
  3. Walking DOWN: finding PRs whose base is in our visited set
  4. Sorting results from bottom (closest to trunk) to top

Tests

9 new tests including mockito-based API tests:

  • test_fetch_pr_by_head_found/not_found/rate_limited
  • test_fetch_prs_by_base_multiple/empty
  • test_fetch_all_open_prs
  • test_sort_stack_linear/single/empty

Stacked PR Chain: smart-log

PR Title Merges Into
#35 👉feat: add stack discovery API -
#36 feat: add rate limit retry logic #35
#37 feat: add identifier detection and prompts #36
#38 feat: add gh CLI helpers #37
#39 feat: make log and status identifier optional with branch inference #38
#40 docs: update log and status documentation for smart defaults #39
#41 perf: optimize stack discovery with batch fetch #40
#42 perf: parallelize status check fetches #41

Add src/api/stack.rs module for discovering PR stacks by walking
the base/head branch chain. This enables gh-stack to find related
PRs without requiring identifier patterns in titles.

New functions:
- fetch_pr_by_head: Find PR by head branch name
- fetch_prs_by_base: Find all PRs targeting a base branch
- fetch_all_open_prs: Get all open PRs in a repo
- discover_stack: Walk up/down to find full connected stack
- discover_all_stacks: Group all PRs into separate stacks

Includes 9 unit tests with mockito for API calls.
@luqven
Copy link
Owner Author

luqven commented Dec 30, 2025

Landed via #42

@luqven luqven closed this Dec 30, 2025
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