diff --git a/gitea/hooks/deny-html-tags b/gitea/hooks/deny-html-tags new file mode 100644 index 0000000..ce6a433 --- /dev/null +++ b/gitea/hooks/deny-html-tags @@ -0,0 +1,48 @@ +#!/bin/bash -eu + +# Reject commits that contain HTML tags in their commit messages. +# Allow override with a special key phrase in the message. + +set -o pipefail + +nullsha="0000000000000000000000000000000000000000" +status=0 +override_msg="override html check" + +while read oldref newref refname; do + # Skip branch deletions + if [ "$newref" = "$nullsha" ]; then + continue + fi + + # Handle new branches + if [ "$oldref" = "$nullsha" ]; then + oldref="HEAD" + fi + + # Loop through each new commit + for commit in $(git rev-list ${oldref}..${newref}); do + # Get full commit message + msg=$(git log --format=%B -n 1 "$commit") + + # Check for override + if echo "$msg" | grep -qi "$override_msg"; then + echo "Commit $commit allowed due to override message." + continue + fi + + # Check for HTML tags + if echo "$msg" | grep -qE ']*>'; then + echo "ERROR: Commit $commit contains HTML tags in the message." + echo "Message:" + echo "----------------------------------------" + echo "$msg" + echo "----------------------------------------" + echo "Please remove the HTML tags or use the override phrase:" + echo "\"$override_msg\"" + status=1 + fi + done +done + +exit $status