-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(git-hook):
{signed,conventional}-commits.sh
- `signed-commits.sh` hook (a `pre-push` hook) will not allow the user to push to remote if the last commit is not signed. This is a good sanity test,if the last commit is signed then there is a high chance of any other previous are also signed. - `conventional-commits.sh` hook (a `commit-msg` hook) will not allow the user to commit if the commit message does not satisfy the Conventional Commits template.
- Loading branch information
1 parent
0e43429
commit 883e571
Showing
3 changed files
with
61 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Conventional commit regex pattern | ||
# bash repex do not support \w \d \s | ||
pattern="^(build|ci|docs|feat|fix|perf|refactor|style|test|chore|revert)(\([[:alnum:]\-]+\))?:[[:space:]].*" | ||
|
||
# Read the commit message from the file | ||
commit_file="$1" | ||
commit_head_message=$(head -n1 "$commit_file") | ||
|
||
# Check if the commit message matches the pattern | ||
if ! [[ "$commit_head_message" =~ $pattern ]]; then | ||
echo "Error: Invalid commit message format. Please use a conventional commit message." | ||
echo "Commit message should match the pattern: $pattern." | ||
echo "Please refer to https://www.conventionalcommits.org/en/v1.0.0/ for more details." | ||
exit 1 | ||
fi | ||
|
||
# If the commit message matches the pattern, the hook exits successfully | ||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Function to verify the signature of the last commit | ||
verify_signature() { | ||
local commit_hash=$(git rev-parse HEAD) | ||
if ! git verify-commit "$commit_hash"; then | ||
echo "Error: Last commit ($commit_hash) is not signed." | ||
exit 1 | ||
fi | ||
} | ||
|
||
# Verify the signature of the last commit | ||
verify_signature | ||
|
||
# Allow the push to proceed if the signature is valid | ||
exit 0 |