Add ->showGitInfo() for displaying git tag and short hash #40

Closed
SujalRatnaTamrakar wants to merge 0 commits from feature/git-tag-hash into main
SujalRatnaTamrakar commented 2026-08-05 02:51:25 +00:00 (Migrated from github.com)

Closes #27

What

Adds a general ->showGitInfo(Closure) method so the badge can display the git tag and/or short commit hash — not only the branch. This implements the API shape you proposed in #27.

The closure receives a GitInfo instance (also injectable by type-hint) exposing branch(), tag() and hash(), and returns the string to render:

use pxlrbt\FilamentEnvironmentIndicator\GitInfo;

EnvironmentIndicatorPlugin::make()
    ->showGitInfo(fn (GitInfo $git) => match (app()->environment()) {
        'production' => $git->tag().' - '.$git->hash(),   // 2.2.0 - 12345678
        'staging'    => ($git->tag() ?? $git->branch()).' - '.$git->hash(),
        default      => $git->hash(),                      // 12345678
    })

How

  • New GitInfo value object resolves branch() / tag() / hash() lazily via exec() (git branch --show-current, git describe --tags --abbrev=0, git rev-parse --short HEAD), caching each lookup. Every lookup degrades to null when exec() is disabled or the command fails.
  • ->showGitBranch() is now a thin wrapper over the same mechanism — no behavior change, so existing users are unaffected.
  • ->showGitInfo() takes precedence when both are set; because the closure composes any of branch/tag/hash, both can effectively be shown at once.
  • Kept the badge compact: long tags/hashes are truncated with CSS ellipsis and the full value is shown via a title tooltip on hover, addressing the long-version-number edge case.
  • View variable contract is unchanged ($branch is still the slot rendered), so published/overridden views keep working.
Closes #27 ## What Adds a general `->showGitInfo(Closure)` method so the badge can display the git **tag** and/or **short commit hash** — not only the branch. This implements the API shape you proposed in #27. The closure receives a `GitInfo` instance (also injectable by type-hint) exposing `branch()`, `tag()` and `hash()`, and returns the string to render: ```php use pxlrbt\FilamentEnvironmentIndicator\GitInfo; EnvironmentIndicatorPlugin::make() ->showGitInfo(fn (GitInfo $git) => match (app()->environment()) { 'production' => $git->tag().' - '.$git->hash(), // 2.2.0 - 12345678 'staging' => ($git->tag() ?? $git->branch()).' - '.$git->hash(), default => $git->hash(), // 12345678 }) ``` ## How - New `GitInfo` value object resolves `branch()` / `tag()` / `hash()` lazily via `exec()` (`git branch --show-current`, `git describe --tags --abbrev=0`, `git rev-parse --short HEAD`), caching each lookup. Every lookup degrades to `null` when `exec()` is disabled or the command fails. - `->showGitBranch()` is now a thin wrapper over the same mechanism — **no behavior change**, so existing users are unaffected. - `->showGitInfo()` takes precedence when both are set; because the closure composes any of branch/tag/hash, both can effectively be shown at once. - Kept the badge **compact**: long tags/hashes are truncated with CSS ellipsis and the full value is shown via a `title` tooltip on hover, addressing the long-version-number edge case. - View variable contract is unchanged (`$branch` is still the slot rendered), so published/overridden views keep working.

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
pxlrbt/filament-environment-indicator!40
No description provided.