From eec9e7fae02e1515d223db7d26fd8557348c58f8 Mon Sep 17 00:00:00 2001 From: Jim Huang Date: Sun, 23 Feb 2025 20:10:52 +0800 Subject: [PATCH 1/2] Avoid the pattern verb 'of' something The git hook is expected to assist students in writing effective commit messages in English. Change-Id: Ib61ee932c433d1b8ee5f18720a0b4ecb21fa1768 --- scripts/commit-msg.hook | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts/commit-msg.hook b/scripts/commit-msg.hook index da6be14d3..0f807b2e5 100755 --- a/scripts/commit-msg.hook +++ b/scripts/commit-msg.hook @@ -300,6 +300,11 @@ done add_warning 1 "Commit subject should use imperative mood" fi + # 7d. Alert if the commit subject uses the pattern "Implement of ..." + if [[ "${COMMIT_SUBJECT_TO_PROCESS}" =~ ^(Implement|Realize|Update|Finish|Code)[[:space:]]+of[[:space:]]+ ]]; then + add_warning 1 "Avoid using 'of' immediately after the verb" + fi + # 8. Use the body to explain what and why vs. how # ------------------------------------------------------------------------------ From d043c4158540faf0cbd140bdd6dd316e0a0be8db Mon Sep 17 00:00:00 2001 From: Jim Huang Date: Sun, 23 Feb 2025 20:38:18 +0800 Subject: [PATCH 2/2] Validate email of git configuration This regex matches a basic email pattern. Change-Id: I7196a97db325c73f3b88462b69edc2ddc7d0fbce --- scripts/check-repo.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/scripts/check-repo.sh b/scripts/check-repo.sh index b6bfed3c5..28d40f995 100755 --- a/scripts/check-repo.sh +++ b/scripts/check-repo.sh @@ -20,6 +20,20 @@ if ! command -v git &>/dev/null; then throw "git not installed." fi +# Retrieve git email. +GIT_EMAIL=$(git config user.email) + +# Check if email is set. +if [ -z "$GIT_EMAIL" ]; then + throw "Git email is not set." +fi + +# Validate email using a regex. +# This regex matches a basic email pattern. +if ! [[ "$GIT_EMAIL" =~ ^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$ ]]; then + throw "Git email '$GIT_EMAIL' is not valid." +fi + # 1. Sleep for a random number of milliseconds # The time interval is important to reduce unintended network traffic. ((CURRENT_STEP++))