Skip to content

Commit

Permalink
ci(test): local conventional commit check
Browse files Browse the repository at this point in the history
Co-authored-by: Soha Alboghdady <[email protected]>
  • Loading branch information
raghunathd8 and Soha-Albaghdady committed Jul 11, 2023
1 parent a63b124 commit afc67fa
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .hooks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Git Hooks

Run conventional commit checks locally without any tool installation

## Usage

Execute the below command in the root directory of the project:

```sh
ln -s -f ../../.hooks/commit-msg ./.git/hooks/commit-msg
```

Make the file executable:

```sh
chmod +x ./.hooks/commit-msg
```
16 changes: 16 additions & 0 deletions .hooks/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

first_line=$(head -n1 "$1")
echo "commit message: $first_line"

conv_commit_msg="^(fix|feat|build|chore|ci|docs|style|refactor|perf|test)(\(.{1,50}\))?: (.{1,100})\$"
flag=0
if ! [[ "$first_line" =~ (${conv_commit_msg}) ]]; then
flag=1
echo "ERROR: Conventional commit message formatting error" >&2
echo "$first_line" >&2
fi

if [ "$flag" -ne 0 ]; then
exit 1
fi

0 comments on commit afc67fa

Please sign in to comment.