Skip to content

Improve PR stacking with better branch naming and enqueue logic#44

Open
EliSchleifer wants to merge 4 commits intomainfrom
claude/stack-trunk-comment
Open

Improve PR stacking with better branch naming and enqueue logic#44
EliSchleifer wants to merge 4 commits intomainfrom
claude/stack-trunk-comment

Conversation

@EliSchleifer
Copy link
Copy Markdown
Member

Summary

This PR enhances the PR stacking workflow by improving branch naming conventions, refining the enqueue logic for stacked PRs, and adding better tracking of PR numbers across stack operations.

Key Changes

  • Branch naming: Changed from change/pr{number}-{words} to change/{first-word}-{HHMM} format using local wall time, making branch names more readable and independent of PR numbers

    • Added head_branch_from_first_word() and slug_for_branch_segment() helper functions with comprehensive slug normalization
    • Added unit tests for branch slug generation
  • Improved enqueue logic for stacks:

    • Modified enqueue() to accept optional stack_prs parameter
    • When enqueueing the tip of a multi-PR stack, posts /trunk stack --title "Stack of #A, #B, ..." instead of the default merge comment
    • Only enqueues the top PR in a stack (lower PRs skip enqueue since they can't merge independently)
  • Better PR number tracking:

    • Enhanced get_last_pr() to fetch up to 5000 PRs and find the maximum number, rather than just taking the first result
    • Improved PR number tracking across stack operations by parsing actual GitHub-assigned numbers
  • PR title formatting:

    • Solo PRs: Keep merge target in title (e.g., [main] words)
    • Stacked PRs: Use stack position format (e.g., [stack 1/3] words) without the generated branch name, reducing noise
  • Stack management improvements:

    • Added defensive check to ensure first PR in each stack targets the correct protected branch
    • Added checkout back to protected branch after each stack completes, ensuring clean state for next stack
    • Added informative logging for stack progress and enqueue decisions
  • Import addition: Added Local to chrono imports for local time formatting

Implementation Details

  • The stack_prs vector tracks PRs created in bottom-to-top order within each stack
  • Branch names now use Local::now().format("%H%M") for timestamp, making them human-readable and time-based rather than number-based
  • Slug normalization handles special characters, consecutive dashes, and empty results gracefully
  • The enqueue logic distinguishes between solo PRs (no stack_ref) and stacked PRs (with stack_ref containing multiple PRs)

https://claude.ai/code/session_01MJFJjPjFSY9H4MsvDLU6hY

claude and others added 4 commits April 18, 2026 00:31
Lower PRs in a stack target another PR's branch, so they can't merge on
their own until the tip is resolved. Skip enqueuing them to avoid
churning the merge queue with PRs that have no path to main.
When merge.trigger = comment and a generated stack has depth > 1, the tip
PR now receives `/trunk stack --title "Stack of #A, #B, ..."` instead of
the default merge comment. The title lists every PR in the stack in
bottom-to-top order so reviewers and tooling can see the whole chain.

Solo PRs (depth == 1) and non-Comment triggers are unaffected.
@trunk-staging-io
Copy link
Copy Markdown

trunk-staging-io Bot commented Apr 20, 2026

🚫 This pull request was requested to be canceled by Eli Schleifer (a GitHub user), so it was removed from the merge queue. See more details here.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants