Last active
October 21, 2025 20:54
-
-
Save xpepper/3624388861aee0645d2f9c6a699df84e to your computer and use it in GitHub Desktop.
This script enhances git log by automatically fetching and displaying the GitHub Actions (CI) status for your most recent commits.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # Requirements: GitHub CLI (gh) configured with access to the repository | |
| set -euo pipefail | |
| # Default branch is 'master' if not provided | |
| BRANCH=${1:-master} | |
| # Detect remote URL for origin or fallback to first remote | |
| REMOTE_URL=$(git remote get-url origin 2>/dev/null || git remote get-url "$(git remote | head -n1)" 2>/dev/null || true) | |
| if [[ -z "${REMOTE_URL:-}" ]]; then | |
| echo "Error: Could not detect Git remote URL." >&2 | |
| exit 1 | |
| fi | |
| # Parse OWNER and REPO from GitHub remote URL (optional .git suffix) | |
| if [[ "$REMOTE_URL" =~ github.com[:/]([^/]+)/([^/]+)(\.git)?$ ]]; then | |
| OWNER="${BASH_REMATCH[1]}" | |
| REPO="${BASH_REMATCH[2]}" | |
| REPO="${REPO%.git}" | |
| else | |
| echo "Error: Remote URL is not a recognized GitHub URL." >&2 | |
| exit 1 | |
| fi | |
| # Fetch latest commits from remote branch | |
| git fetch origin "$BRANCH" --quiet | |
| echo "$REPO" | |
| # Build a format with: <plain SHA><TAB><colored pretty message> | |
| # Use %x09 for a literal TAB (portable) so we can split safely. | |
| FORMAT='%H%x09%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset' | |
| echo | |
| echo "Commit status for $OWNER/$REPO ($BRANCH):" | |
| echo "-----------------------------------------" | |
| git log "origin/$BRANCH" --color=always --pretty="$FORMAT" -n 15 | | |
| while IFS=$'\t' read -r SHA MESSAGE; do | |
| # Query GitHub check runs for this commit | |
| CHECK_CONCLUSIONS=$(gh api "/repos/$OWNER/$REPO/commits/$SHA/check-runs" --jq '.check_runs[].conclusion' 2>/dev/null || true) | |
| ICON="β" | |
| if [[ -z "$CHECK_CONCLUSIONS" ]]; then | |
| ICON="π" | |
| elif echo "$CHECK_CONCLUSIONS" | grep -qE 'failure|timed_out|action_required'; then | |
| ICON="β" | |
| elif echo "$CHECK_CONCLUSIONS" | grep -q 'cancelled'; then | |
| ICON="π«" | |
| elif echo "$CHECK_CONCLUSIONS" | grep -q 'success'; then | |
| ICON="β " | |
| else | |
| ICON="π" | |
| fi | |
| echo "$ICON $MESSAGE" | |
| done | |
| echo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment