Merge branch 'fix/skip-checking-auto-commits' into 'dev'

Automated commit detection

See merge request ics/sp/2025/n25b/pepperplus-cb!20
This commit was merged in pull request #20.
This commit is contained in:
Björn Otgaar
2025-11-03 14:35:40 +00:00
2 changed files with 56 additions and 14 deletions

View File

@@ -1,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
# This script checks if the current branch name follows the specified format. # This script checks if the current branch name follows the specified format.
# It's designed to be used as a 'pre-commit' git hook. # It's designed to be used as a 'pre-commit' git hook.

View File

@@ -1,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
# This script checks if a commit message follows the specified format. # This script checks if a commit message follows the specified format.
# It's designed to be used as a 'commit-msg' git hook. # It's designed to be used as a 'commit-msg' git hook.
@@ -23,6 +23,44 @@ NC='\033[0m' # No Color
# The first argument to the hook is the path to the file containing the commit message # The first argument to the hook is the path to the file containing the commit message
COMMIT_MSG_FILE=$1 COMMIT_MSG_FILE=$1
# --- Automated Commit Detection ---
# Read the first line (header) for initial checks
HEADER=$(head -n 1 "$COMMIT_MSG_FILE")
# Check for Merge commits (covers 'git merge' and PR merges from GitHub/GitLab)
# Examples: "Merge branch 'main' into ...", "Merge pull request #123 from ..."
MERGE_PATTERN="^Merge (branch|pull request|tag) .*"
if [[ "$HEADER" =~ $MERGE_PATTERN ]]; then
echo -e "${GREEN}Merge commit detected by message content. Skipping validation.${NC}"
exit 0
fi
# Check for Revert commits
# Example: "Revert "feat: add new feature""
REVERT_PATTERN="^Revert \".*\""
if [[ "$HEADER" =~ $REVERT_PATTERN ]]; then
echo -e "${GREEN}Revert commit detected by message content. Skipping validation.${NC}"
exit 0
fi
# Check for Cherry-pick commits (this pattern appears at the end of the message)
# Example: "(cherry picked from commit deadbeef...)"
# We use grep -q to search the whole file quietly.
CHERRY_PICK_PATTERN="\(cherry picked from commit [a-f0-9]{7,40}\)"
if grep -qE "$CHERRY_PICK_PATTERN" "$COMMIT_MSG_FILE"; then
echo -e "${GREEN}Cherry-pick detected by message content. Skipping validation.${NC}"
exit 0
fi
# Check for Squash
# Example: "Squash commits ..."
SQUASH_PATTERN="^Squash .+"
if [[ "$HEADER" =~ $SQUASH_PATTERN ]]; then
echo -e "${GREEN}Squash commit detected by message content. Skipping validation.${NC}"
exit 0
fi
# --- Validation Functions --- # --- Validation Functions ---
# Function to print an error message and exit # Function to print an error message and exit
@@ -56,6 +94,9 @@ if ! [[ "$HEADER" =~ $HEADER_REGEX ]]; then
error_exit "Invalid header format.\n\nHeader must be in the format: <type>: <short description>\nAllowed types: ${ALLOWED_TYPES[*]}\nExample: feat: add new user authentication feature" error_exit "Invalid header format.\n\nHeader must be in the format: <type>: <short description>\nAllowed types: ${ALLOWED_TYPES[*]}\nExample: feat: add new user authentication feature"
fi fi
# Only validate footer if commit type is not chore
TYPE=$(echo "$HEADER" | cut -d':' -f1)
if [ "$TYPE" != "chore" ]; then
# 3. Validate the footer (last line) of the commit message # 3. Validate the footer (last line) of the commit message
FOOTER=$(tail -n 1 "$COMMIT_MSG_FILE") FOOTER=$(tail -n 1 "$COMMIT_MSG_FILE")
@@ -71,6 +112,7 @@ FOOTER_REGEX="^(ref|close): N25B-[0-9]+$"
if ! [[ "$FOOTER" =~ $FOOTER_REGEX ]]; then if ! [[ "$FOOTER" =~ $FOOTER_REGEX ]]; then
error_exit "Invalid footer format.\n\nFooter must be in the format: [ref/close]: <issue identifier>\nExample: ref: N25B-123" error_exit "Invalid footer format.\n\nFooter must be in the format: [ref/close]: <issue identifier>\nExample: ref: N25B-123"
fi fi
fi
# 4. If the message has more than 2 lines, validate the separator # 4. If the message has more than 2 lines, validate the separator
# A blank line must exist between the header and the body. # A blank line must exist between the header and the body.