Skip to content
This repository was archived by the owner on Dec 11, 2025. It is now read-only.

Repository files navigation

Conduit UI - Commits

Latest Version on Packagist Total Downloads

A beautiful, expressive GitHub commits management package built on top of conduit-ui/github-connector. Built with Taylor Otwell's design philosophy in mind - clean DTOs, fluent APIs, and minimal dependencies.

Installation

You can install the package via composer:

composer require conduit-ui/commits

Usage

Quick Start

use ConduitUI\Commits\Facades\Commits;

// Get all commits for a repository
$commits = Commits::for('laravel/framework')->get();

// Get a single commit
$commit = Commits::find('laravel/framework', 'abc123');

// Compare two branches
$comparison = Commits::compare('laravel/framework', 'main', 'feature-branch');

// Compare between two commits
$comparison = Commits::between('laravel/framework', 'sha1', 'sha2');

Query Builder

The package includes a powerful query builder for filtering commits:

use ConduitUI\Commits\Facades\Commits;

$commits = Commits::query()
    ->repository('laravel/framework')
    ->branch('main')
    ->author('taylorotwell')
    ->since('2025-01-01')
    ->until('2025-12-01')
    ->take(50)
    ->get();

Available Query Methods

  • repository(string $repository) - Set the repository (required)
  • branch(string $sha) - Filter by branch or SHA
  • sha(string $sha) - Alias for branch()
  • path(string $path) - Filter by file path
  • author(string $author) - Filter by commit author
  • committer(string $committer) - Filter by committer
  • since(string $since) - Get commits after this date
  • until(string $until) - Get commits before this date
  • perPage(int $perPage) - Number of results per page
  • take(int $count) - Alias for perPage()
  • page(int $page) - Page number for pagination
  • get() - Execute the query and return commits
  • first() - Get the first commit

Working with Commits

$commit = Commits::find('laravel/framework', 'abc123');

// Access commit properties
$commit->sha;              // Full SHA
$commit->shortSha();       // Short SHA (7 characters by default)
$commit->shortSha(10);     // Custom length
$commit->message;          // Commit message
$commit->author;           // CommitAuthor DTO
$commit->committer;        // CommitAuthor DTO
$commit->parents;          // Array of parent SHAs
$commit->stats;            // CommitStats DTO (if available)
$commit->files;            // Collection of CommitFile DTOs
$commit->htmlUrl;          // GitHub URL
$commit->commentsUrl;      // Comments API URL

// Helper methods
$commit->hasFiles();       // Check if commit has file changes
$commit->hasStats();       // Check if commit has stats
$commit->isParent('sha');  // Check if SHA is a parent

Working with Authors

$author = $commit->author;

$author->name;             // Author name
$author->email;            // Author email
$author->date;             // DateTimeImmutable object

Working with Files

foreach ($commit->files as $file) {
    $file->filename;       // File path
    $file->status;         // added, modified, removed, renamed
    $file->additions;      // Lines added
    $file->deletions;      // Lines deleted
    $file->changes;        // Total changes
    $file->patch;          // Git patch (if available)
    $file->blobUrl;        // Blob URL
    $file->rawUrl;         // Raw file URL
    $file->contentsUrl;    // Contents API URL

    // Helper methods
    $file->isAdded();      // Check if file was added
    $file->isModified();   // Check if file was modified
    $file->isRemoved();    // Check if file was removed
    $file->isRenamed();    // Check if file was renamed
}

Working with Commit Stats

$stats = $commit->stats;

$stats->additions;         // Total lines added
$stats->deletions;         // Total lines deleted
$stats->total;             // Total changes

Comparing Commits

$comparison = Commits::compare('laravel/framework', 'main', 'feature-branch');

// Access comparison properties
$comparison->aheadBy;           // Commits ahead
$comparison->behindBy;          // Commits behind
$comparison->status;            // ahead, behind, diverged, identical
$comparison->commits;           // Collection of Commit DTOs
$comparison->files;             // Collection of CommitFile DTOs
$comparison->baseCommitSha;     // Base commit SHA
$comparison->mergeBaseCommitSha;// Merge base commit SHA
$comparison->htmlUrl;           // GitHub comparison URL
$comparison->permalinkUrl;      // Permalink URL
$comparison->diffUrl;           // Diff URL
$comparison->patchUrl;          // Patch URL

// Helper methods
$comparison->isAhead();         // Check if ahead
$comparison->isBehind();        // Check if behind
$comparison->isDiverged();      // Check if diverged
$comparison->isIdentical();     // Check if identical
$comparison->totalChangedFiles(); // Count of changed files
$comparison->totalCommits();    // Count of commits

Advanced Examples

Get commits by a specific author in a date range

$commits = Commits::query()
    ->repository('laravel/framework')
    ->author('taylorotwell')
    ->since('2025-01-01')
    ->until('2025-01-31')
    ->perPage(100)
    ->get();

Get commits that changed a specific file

$commits = Commits::query()
    ->repository('laravel/framework')
    ->path('src/Illuminate/Database/Eloquent/Model.php')
    ->get();

Get the latest commit on a branch

$commit = Commits::query()
    ->repository('laravel/framework')
    ->branch('11.x')
    ->first();

Analyze commit statistics

$commits = Commits::for('laravel/framework')->get();

$totalAdditions = $commits->sum(fn ($commit) => $commit->stats?->additions ?? 0);
$totalDeletions = $commits->sum(fn ($commit) => $commit->stats?->deletions ?? 0);

echo "Total additions: {$totalAdditions}\n";
echo "Total deletions: {$totalDeletions}\n";

Data Transfer Objects (DTOs)

The package uses readonly DTOs for all data structures:

  • Commit - Represents a Git commit
  • CommitAuthor - Represents a commit author/committer
  • CommitFile - Represents a file changed in a commit
  • CommitStats - Represents commit statistics
  • CommitComparison - Represents a comparison between commits

All DTOs include:

  • fromArray(array $data): self - Create from array
  • toArray(): array - Convert to array

Configuration

Publish the configuration file:

php artisan vendor:publish --tag=commits-config

This will create a config/commits.php file:

return [
    'default_repository' => env('COMMITS_DEFAULT_REPOSITORY'),
    'default_per_page' => env('COMMITS_DEFAULT_PER_PAGE', 30),
];

Testing

composer test

Code Style

composer format

Static Analysis

composer analyse

Credits

License

The MIT License (MIT). Please see License File for more information.

About

Commits interface for the conduit-ui ecosystem

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages