[TikiWiki-commits] [Git][tikiwiki/tiki][30.x] [FIX][REF] Husky: simplified, less restrictive commit-msg validation
"luci \(@luciash\) via TikiWiki-cvs" <[email protected]> Tue, 14 Jul 2026 14:52:22 +0000
| Newsgroups | gmane.comp.cms.tiki.cvs |
|---|---|
| Message-ID | <6a564d26b7629_3819c06c79573@gitlab-sidekiq-low-urgency-cpu-bound-v2-85d5db4876-5px5p.mail> |
luci pushed to branch 30.x at Tiki Wiki CMS Groupware / Tiki Commits: 3f0e500f by luci at 2026-07-14T14:42:28+00:00 [FIX][REF] Husky: simplified, less restrictive commit-msg validation --- * [FIX][REF] Husky: simplified, less restrictive commit-msg validation to support multi-line messages and static class method call mentions (partial revert of !8669) !8669 was too restrictive and complicated rules (partially not working) were introduced. Since the original author is not available anymore we need to partially revert and come up with better solution. Also improved the error message a bit and provides printing the author's commit msg back in case of validation failure. See merge request tikiwiki/tiki!9872 (cherry picked from commit c8a092eb625224bd7d2e11fac855cb65e262dd9f) b5356492 [FIX][REF] Husky: simplified, less restrictive commit-msg validation to... Co-authored-by: luci <gitlab-TfYQc8/[email protected]> - - - - - 1 changed file: - .husky/commit-msg Changes: ===================================== .husky/commit-msg ===================================== @@ -1,137 +1,47 @@ #!/bin/sh +# commit message file path msg_file="$1" # Remove Windows CRLF endings msg=$(tr -d '\r' < "$msg_file") -# ------------------------------ -# Revert commit validation (must have non-empty quoted message) -# ------------------------------ -if echo "$msg" | grep -Eq "^Revert:?"; then - if ! echo "$msg" | grep -Eq '^Revert:?[[:space:]]*".+"$'; then - echo "❌ Error: Revert commits must use quotes and include a message." - echo "For details see: https://dev.tiki.org/Commit-Tags" - exit 1 - fi +print_msg="Your commit message: +-------------------- +$msg +-------------------- +" - inner_msg=$(echo "$msg" | sed -E 's/^Revert:?[[:space:]]*"(.+)"$/\1/') - trimmed_inner=$(echo "$inner_msg" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') +# regex Tiki tags +regex='^(((\[(BP|DB|DOC|ENH|FIX|KIL|MOD|MRG|NEW|REF|REL|REM|SEC|TRA|UI|UPD|UX)\]){1,5}(( [^ ][^][]+[^ ]:{1,2} )|( [^]:[ ]+[^:]+$))|[^]:[:space:][]{3,})).*' - if [ -z "$trimmed_inner" ]; then - echo "❌ Error: Revert commit message inside quotes cannot be empty." - echo "For details see: https://dev.tiki.org/Commit-Tags" - exit 1 - fi - - exit 0 -fi - -# Valid Tiki tags -valid_tags="BP DB DOC ENH FIX KIL MOD MRG NEW REF REL REM SEC TRA UI UPD UX" - -check_tags() { - tags_part="$1" - invalid_found=0 - - for tag in $(echo "$tags_part" | grep -Eo '\[[A-Z]+\]' | tr -d '[]'); do - echo "$valid_tags" | grep -qw "$tag" || { - echo "❌ Error: Invalid tag '[${tag}]'. Allowed tags: $valid_tags" - invalid_found=1 - } - done - return $invalid_found -} - -# Check if commit starts with a tag -if echo "$msg" | grep -Eq "^(\[[A-Z]+\]){1,5}"; then - # Tagged commit — normal validation later - : -else - # Not a tagged commit — reject if starts with space or special char - if echo "$msg" | grep -Eq "^[^a-zA-Z0-9]"; then - echo "❌ Error: Commit must start with alphanumeric character if not tagged." - echo "For details see: https://dev.tiki.org/Commit-Tags" - exit 1 - fi -fi - -# Reject tag-only commits -if echo "$msg" | grep -Eq "^(\[[A-Z]+\]){1,5}[[:space:]]*$"; then - echo "❌ Error: Commit must have a message after tag(s)." - echo "For details see: https://dev.tiki.org/Commit-Tags" - exit 1 -fi - -# Allow plain text commits (no tags or revert) -if echo "$msg" | grep -q "^\["; then - : -elif echo "$msg" | grep -Eq "^Revert:? "; then - : +if echo "$msg" | grep -Eq "$regex"; then + exit 0 else - exit 0 -fi - -# ------------------------------ -# tagged commit validation -# ------------------------------ -if echo "$msg" | grep -Eq "^(\[[A-Z]+\]){1,5}[[:space:]]+.+$"; then - tags_part=$(echo "$msg" | grep -Eo "^(\[[A-Z]+\]){1,5}" || echo "") - body_part=$(echo "$msg" | sed -E "s/^(\[[A-Z]+\]){1,5}[[:space:]]+//") - # Remove Git comment lines from body - body_part=$(echo "$body_part" | sed '/^[[:space:]]*#/d') - - if [ -z "$body_part" ] || echo "$body_part" | grep -Eq "^[[:space:]]*$"; then - echo "❌ Error: Commit body is empty after tags." - echo "For details see: https://dev.tiki.org/Commit-Tags" - exit 1 - fi - - if echo "$body_part" | grep -q ":"; then - # Space before colon → ❌ - if echo "$body_part" | grep -Eq "[[:space:]]+:" - then - echo "❌ Error: No space allowed before a colon in commit body." - echo "For details see: https://dev.tiki.org/Commit-Tags" - exit 1 - fi - - # Colon at start → ❌ - if echo "$body_part" | grep -Eq "^:" - then - echo "❌ Error: Commit body cannot start with a colon." - echo "For details see: https://dev.tiki.org/Commit-Tags" - exit 1 - fi - - # Colon at end → ❌ - if echo "$body_part" | grep -Eq ":[[:space:]]*$" - then - echo "❌ Error: Colon must be followed by a non-empty description." - echo "For details see: https://dev.tiki.org/Commit-Tags" - exit 1 - fi - - # Double colons → ❌ - if echo "$body_part" | grep -Eq ":[[:space:]]*:" - then - echo "❌ Error: No double colons allowed in commit body." - echo "For details see: https://dev.tiki.org/Commit-Tags" - exit 1 - fi - - # Colon not followed by a space → ❌ - if ! echo "$body_part" | grep -Eq ":[[:space:]]" - then - echo "❌ Error: Colon must always be followed by a space." - echo "For details see: https://dev.tiki.org/Commit-Tags" - exit 1 - fi - fi - - check_tags "$tags_part" && exit 0 || exit 1 + echo "$print_msg" + echo "❌ Error: Your commit message is not properly formatted." + echo "" + echo "To be included in the release changelog the message (its first line)" + echo "should start with at least one of the valid Tiki commit tags:" + echo "BP|DB|DOC|ENH|FIX|KIL|MOD|MRG|NEW|REF|REL|REM|SEC|TRA|UI|UPD|UX" + echo "(use max. 5 tags without any spaces between them, e.g., [ENH][FIX], [NEW], [TRA], [REF][UI][UX], …)." + echo "The tags must be followed by:" + echo "- exactly one space," + echo "- name of the affected feature, lib or a function, (optional but recommended)" + echo "- a colon and one space as a separator, (optional)" + echo "- a short description of the changes you have made. (ideally)" + echo "Please use English language with colons and spaces as appropriate (at least on the first line" + echo "in case of multi-line commit message) to ensure it is nicely readable.)" + echo "" + echo "Keep in mind it should be simple and clear when read by Tiki users and/or merge request reviewers!" + echo "" + echo "Correct: \"[FIX] Blog posts: blog titles were broken by a regression\"" + echo "Invalid: \"[FIX]Blog posts : blog titles were broken by a regression\"" + echo "" + echo "To omit the message from the list of major changes entirely, simply use a plain text message" + echo "without using any tags instead. For example: just a quick typo fix" + echo "" + echo "For the correct formatting and details see: https://dev.tiki.org/Commit-Tags" + echo "" + exit 1 fi -# No match — invalid commit -echo "❌ Error: your commit message is not properly formatted. " -echo "For details see: https://dev.tiki.org/Commit-Tags" -exit 1 View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/3f0e500f1e6eb18425e0664059041b5a667467aa -- View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/3f0e500f1e6eb18425e0664059041b5a667467aa You're receiving this email because of your account on gitlab.com. Manage all notifications: https://gitlab.com/-/profile/notifications | Help: https://gitlab.com/help _______________________________________________ TikiWiki-cvs mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs