Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/treetrek.git
<?php
class HomePage extends BasePage {
  public function render() {
    $this->renderLayout(function() {
      echo '<h2>Repositories</h2>';
      if (empty($this->repositories)) {
        echo '<div class="empty-state">No repositories found in ' . htmlspecialchars(Config::getReposPath()) . '</div>';
        return;
      }
      echo '<div class="repo-grid">';
      foreach ($this->repositories as $repo) {
        $this->renderRepoCard($repo);
      }
      echo '</div>';
    });
  }

  private function renderRepoCard($repo) {
    $git = new Git($repo['path']);
    $main = $git->getMainBranch();

    $stats = ['branches' => 0, 'tags' => 0];
    $git->eachBranch(function() use (&$stats) { $stats['branches']++; });
    $git->eachTag(function() use (&$stats) { $stats['tags']++; });

    echo '<a href="?repo=' . urlencode($repo['safe_name']) . '" class="repo-card">';
    echo '<h3>' . htmlspecialchars($repo['name']) . '</h3>';
    if ($main) echo '<p>Branch: ' . htmlspecialchars($main['name']) . '</p>';
    echo '<p>' . $stats['branches'] . ' branches, ' . $stats['tags'] . ' tags</p>';

    if ($main) {
      $git->history('HEAD', 1, function($c) use ($repo) {
        $renderer = new HtmlFileRenderer($repo['safe_name']);
        echo '<p class="repo-card-time">';
        $renderer->renderTime($c->date);
        echo '</p>';
      });
    }

    echo '</a>';
  }
}