refactor(ho-ok): simplify commit message validation output
This commit is contained in:
parent
e92a559e95
commit
cf6a51a7f2
1 changed files with 19 additions and 29 deletions
|
@ -1,7 +1,6 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Semantic commit pattern - fixed to properly handle hyphens in scope
|
# Semantic commit pattern
|
||||||
# Moved the hyphen to the end of the character class to avoid interpretation issues
|
|
||||||
PATTERN='^(feat|fix|docs|style|refactor|test|perf|build|ci|chore|revert)(\([a-zA-Z0-9\._-]+\))?: .{1,}$'
|
PATTERN='^(feat|fix|docs|style|refactor|test|perf|build|ci|chore|revert)(\([a-zA-Z0-9\._-]+\))?: .{1,}$'
|
||||||
|
|
||||||
# Pattern for merge commits from pull requests - simplified to catch all formats
|
# Pattern for merge commits from pull requests - simplified to catch all formats
|
||||||
|
@ -84,33 +83,28 @@ while read -r OLD_REV NEW_REV REF_NAME; do
|
||||||
OLD_REV=$(git rev-list --max-parents=0 "$NEW_REV")
|
OLD_REV=$(git rev-list --max-parents=0 "$NEW_REV")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo -e "${YELLOW}Checking commits in $REF_NAME${NC}"
|
echo -e "${YELLOW}Validating commits in $REF_NAME${NC}"
|
||||||
|
|
||||||
# Get branch stats from git
|
# Get branch stats from git (quietly)
|
||||||
BRANCH_COMMITS=$(git rev-list --count "$REF_NAME")
|
BRANCH_COMMITS=$(git rev-list --count "$REF_NAME" 2>/dev/null || echo "?")
|
||||||
BRANCH_AGE=$(git log -1 --format="%cr" "$REF_NAME")
|
BRANCH_AGE=$(git log -1 --format="%cr" "$REF_NAME" 2>/dev/null || echo "unknown time ago")
|
||||||
|
|
||||||
echo -e "${CYAN}→ Branch has $BRANCH_COMMITS total commits (created $BRANCH_AGE)${NC}"
|
|
||||||
echo ""
|
|
||||||
|
|
||||||
# Get all commit hashes between old and new revision
|
# Get all commit hashes between old and new revision
|
||||||
COMMITS=$(git rev-list "$OLD_REV".."$NEW_REV")
|
COMMITS=$(git rev-list "$OLD_REV".."$NEW_REV")
|
||||||
|
|
||||||
# Check each commit message
|
# Process each commit message, but with minimal output
|
||||||
for COMMIT in $COMMITS; do
|
for COMMIT in $COMMITS; do
|
||||||
TOTAL_COMMITS=$((TOTAL_COMMITS + 1))
|
TOTAL_COMMITS=$((TOTAL_COMMITS + 1))
|
||||||
COMMIT_MSG=$(git log --format=%B -n 1 "$COMMIT")
|
COMMIT_MSG=$(git log --format=%B -n 1 "$COMMIT")
|
||||||
COMMIT_SUBJECT=$(echo "$COMMIT_MSG" | head -n 1)
|
COMMIT_SUBJECT=$(echo "$COMMIT_MSG" | head -n 1)
|
||||||
PARENT_COUNT=$(git rev-list --parents -n 1 "$COMMIT" | awk '{print NF - 1}')
|
PARENT_COUNT=$(git rev-list --parents -n 1 "$COMMIT" | awk '{print NF - 1}')
|
||||||
AUTHOR=$(git log -1 --format="%an" "$COMMIT")
|
AUTHOR=$(git log -1 --format="%an" "$COMMIT")
|
||||||
COMMIT_DATE=$(git log -1 --format="%cd" --date=relative "$COMMIT")
|
|
||||||
SHORT_HASH=${COMMIT:0:8}
|
|
||||||
|
|
||||||
# Get commit stats
|
# Get commit stats silently
|
||||||
STATS=$(git show --stat --format="" "$COMMIT")
|
STATS=$(git show --stat --format="" "$COMMIT" 2>/dev/null)
|
||||||
FILES_CHANGED=$(echo "$STATS" | grep -c "^[ ]*")
|
FILES_CHANGED=$(echo "$STATS" | grep -c "^[ ]*" 2>/dev/null || echo 0)
|
||||||
INSERTIONS=$(echo "$STATS" | grep -o '[0-9]* insertion' | cut -d' ' -f1 | awk '{sum+=$1} END {print sum+0}')
|
INSERTIONS=$(echo "$STATS" | grep -o '[0-9]* insertion' | cut -d' ' -f1 | awk '{sum+=$1} END {print sum+0}' 2>/dev/null || echo 0)
|
||||||
DELETIONS=$(echo "$STATS" | grep -o '[0-9]* deletion' | cut -d' ' -f1 | awk '{sum+=$1} END {print sum+0}')
|
DELETIONS=$(echo "$STATS" | grep -o '[0-9]* deletion' | cut -d' ' -f1 | awk '{sum+=$1} END {print sum+0}' 2>/dev/null || echo 0)
|
||||||
|
|
||||||
# Update stats
|
# Update stats
|
||||||
TOTAL_FILES_CHANGED=$((TOTAL_FILES_CHANGED + FILES_CHANGED))
|
TOTAL_FILES_CHANGED=$((TOTAL_FILES_CHANGED + FILES_CHANGED))
|
||||||
|
@ -124,23 +118,16 @@ while read -r OLD_REV NEW_REV REF_NAME; do
|
||||||
AUTHORS[$AUTHOR]=1
|
AUTHORS[$AUTHOR]=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo -e "${MAGENTA}Commit #$TOTAL_COMMITS:${NC} ${BOLD}$SHORT_HASH${NC} (by $AUTHOR, $COMMIT_DATE)"
|
# Process merge commits or regular commits (minimal output)
|
||||||
echo -e " Changed: ${CYAN}$FILES_CHANGED files${NC} ${GREEN}+$INSERTIONS${NC}/${RED}-$DELETIONS${NC} lines"
|
|
||||||
echo " $COMMIT_SUBJECT"
|
|
||||||
|
|
||||||
# Skip validation for merge commits (both PR merges and standard Git merges)
|
|
||||||
if [[ $PARENT_COUNT -gt 1 ]] && ([[ "$COMMIT_SUBJECT" =~ $PR_MERGE_PATTERN ]] || [[ "$COMMIT_SUBJECT" =~ $GIT_MERGE_PATTERN ]]); then
|
if [[ $PARENT_COUNT -gt 1 ]] && ([[ "$COMMIT_SUBJECT" =~ $PR_MERGE_PATTERN ]] || [[ "$COMMIT_SUBJECT" =~ $GIT_MERGE_PATTERN ]]); then
|
||||||
echo -e " ${BLUE}➜ Skipping merge commit validation${NC}"
|
|
||||||
MERGE_COMMITS=$((MERGE_COMMITS + 1))
|
MERGE_COMMITS=$((MERGE_COMMITS + 1))
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Validate commit message (no detailed output)
|
||||||
if ! [[ "$COMMIT_SUBJECT" =~ $PATTERN ]]; then
|
if ! [[ "$COMMIT_SUBJECT" =~ $PATTERN ]]; then
|
||||||
echo -e " ${RED}✗ Invalid commit message${NC}"
|
|
||||||
echo -e " ${YELLOW} Should follow pattern:${NC} type(scope): message"
|
|
||||||
INVALID_COMMITS=$((INVALID_COMMITS + 1))
|
INVALID_COMMITS=$((INVALID_COMMITS + 1))
|
||||||
else
|
else
|
||||||
echo -e " ${GREEN}✓ Valid semantic commit${NC}"
|
|
||||||
VALID_COMMITS=$((VALID_COMMITS + 1))
|
VALID_COMMITS=$((VALID_COMMITS + 1))
|
||||||
|
|
||||||
# Count commit type
|
# Count commit type
|
||||||
|
@ -149,13 +136,16 @@ while read -r OLD_REV NEW_REV REF_NAME; do
|
||||||
COMMIT_TYPES[$COMMIT_TYPE]=$((COMMIT_TYPES[$COMMIT_TYPE] + 1))
|
COMMIT_TYPES[$COMMIT_TYPE]=$((COMMIT_TYPES[$COMMIT_TYPE] + 1))
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo ""
|
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# Show processing finished
|
||||||
|
echo -e "${GREEN}✓${NC} Processed $TOTAL_COMMITS commits"
|
||||||
|
echo
|
||||||
|
|
||||||
# Add push summary
|
# Add push summary
|
||||||
draw_box "COMMIT STATISTICS"
|
draw_box "COMMIT STATISTICS"
|
||||||
echo -e "${BOLD}Total commits in this push:${NC} $TOTAL_COMMITS"
|
echo -e "${BOLD}Branch information:${NC} $BRANCH_COMMITS total commits (created $BRANCH_AGE)"
|
||||||
|
echo -e "${BOLD}Commits in this push:${NC} $TOTAL_COMMITS"
|
||||||
echo -e "${GREEN}Valid semantic commits: ${NC} $VALID_COMMITS"
|
echo -e "${GREEN}Valid semantic commits: ${NC} $VALID_COMMITS"
|
||||||
echo -e "${BLUE}Merge commits: ${NC} $MERGE_COMMITS"
|
echo -e "${BLUE}Merge commits: ${NC} $MERGE_COMMITS"
|
||||||
echo -e "${RED}Invalid commits: ${NC} $INVALID_COMMITS"
|
echo -e "${RED}Invalid commits: ${NC} $INVALID_COMMITS"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue