<?php require_once __DIR__ . '/BasePage.php'; require_once __DIR__ . '/../UrlBuilder.php'; class CommitsPage extends BasePage { private $currentRepo; private $git; private $hash; public function __construct( array $repositories, array $currentRepo, Git $git, string $hash ) { parent::__construct( $repositories ); $this->currentRepo = $currentRepo; $this->git = $git; $this->hash = $hash; $this->title = $currentRepo['name']; } public function render() { $this->renderLayout( function() { $main = $this->git->getMainBranch(); if( !$main ) { echo '<div class="empty-state"><h3>No branches</h3>' . '<p>Empty repository.</p></div>'; return; } $this->renderBreadcrumbs( $this->currentRepo, ['Commits'] ); echo '<h2>Commit History <span class="branch-badge">' . htmlspecialchars( $main['name'] ) . '</span></h2>'; echo '<div class="commit-list">'; $start = $this->hash ?: $main['hash']; $this->git->history( $start, 100, function( $commit ) { $msg = htmlspecialchars( explode( "\n", $commit->message )[0] ); $url = (new UrlBuilder()) ->withRepo( $this->currentRepo['safe_name'] ) ->withAction( 'commit' ) ->withHash( $commit->sha ) ->build(); echo '<div class="commit-row">'; echo '<a href="' . $url . '" class="sha">' . substr( $commit->sha, 0, 7 ) . '</a>'; echo '<span class="message">' . $msg . '</span>'; echo '<span class="meta">' . htmlspecialchars( $commit->author ) . ' • ' . date( 'Y-m-d', $commit->date ) . '</span>'; echo '</div>'; } ); echo '</div>'; }, $this->currentRepo ); } }