Skip to content

Add branch comparison (ahead_by/behind_by) support #40

@jordanpartridge

Description

@jordanpartridge

Use Case

For PR management automation, we need to detect when PR branches are behind their base branch to:

  • Monitor branch sync status
  • Alert authors when branches need rebasing
  • Track how many commits behind/ahead a branch is

Current State

The package provides PullRequest::query(), ->head->ref, ->base->ref, but lacks branch comparison.

Proposed API

// Option 1: On PullRequest instance
 = PullRequest::find('owner/repo', 123);
 = ->compare(); // returns Comparison DTO

->aheadBy;  // int - commits ahead of base
->behindBy; // int - commits behind base
->status;   // 'ahead' | 'behind' | 'diverged' | 'identical'

// Option 2: Static method for arbitrary branches
 = PullRequest::compareBranches('owner/repo', 'main', 'feature-branch');

GitHub API Endpoint

Uses: GET /repos/{owner}/{repo}/compare/{basehead}

Response includes:

  • ahead_by (int)
  • behind_by (int)
  • status (string)
  • commits (array)
  • files (array)

Additional Context

This would enable building sync-monitoring agents that can:

  1. Check all open PRs for branches behind base
  2. Alert/nudge authors to rebase
  3. Scheduled checks for branch hygiene

Happy to contribute a PR if this aligns with the package direction.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions