Something went wrong. Try again.
A static site generator for git repositories that integrates with git-bug to track issues. This is it.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465#!/bin/bash# pgit post-commit hook# Automatically closes issues referenced in commit messages using the bug CLI## Usage: Install as .git/hooks/post-commit
set -e
# Check if bug is availableif ! command -v bug &> /dev/null; then echo "Warning: bug not found in PATH, skipping issue updates" >&2 exit 0fi
# Get the commit hash (now correct - post-commit runs after commit)COMMIT_HASH=$(git rev-parse HEAD)if [ -z "$COMMIT_HASH" ]; then echo "Warning: Could not determine commit hash, skipping issue updates" >&2 exit 0fi
# Get the commit message from the just-created commitCOMMIT_MSG=$(git log -1 --pretty=%B)
# Extract issue references using regex# Matches: fixes #872a52d, close #abc1234, resolved #def5678, etc.# Case insensitive, captures the 7-char hex IDISSUE_REFS=$(echo "$COMMIT_MSG" | grep -oEi '\b(fix|fixes|fixed|close|closes|closed|resolve|resolves|resolved)\b[[:space:]]*#[a-f0-9]{7}\b' || true)
if [ -z "$ISSUE_REFS" ]; then # No issue references found exit 0fi
# Process each referenceecho "$ISSUE_REFS" | while read -r ref; do # Extract the issue ID (the hex part after #) issue_id=$(echo "$ref" | grep -oE '#[a-f0-9]{7}\b' | sed 's/^#//i' | tr '[:upper:]' '[:lower:]')
if [ -z "$issue_id" ]; then continue fi
echo "Processing issue #$issue_id..." >&2
# Add comment with commit reference comment="Fixed in commit $COMMIT_HASH"
# Try to add comment - don't fail the commit if this fails if bug agent comment "$issue_id" --message "$comment" 2>/dev/null; then echo " Added comment to issue #$issue_id" >&2 else echo " Warning: Failed to add comment to issue #$issue_id" >&2 fi
# Try to close the issue - don't fail the commit if this fails if bug agent close "$issue_id" 2>/dev/null; then echo " Closed issue #$issue_id" >&2 else echo " Warning: Failed to close issue #$issue_id" >&2 fidone
exit 0