Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ GO_LDFLAGS += -X '$(DTM_ROOT)/internal/pkg/version.Version=$(VERSION)' \
-X '$(DTM_ROOT)/cmd/devstream/list.PluginsName=$(PLUGINS)'

FIND := find . -path './cmd/**/*.go' -o -path './test/**/*.go' -o -path './pkg/**/*.go' -o -path './internal/**/*.go'

GITHOOK := $(shell cp -f hack/githooks/* .git/hooks/)

# COLORS
RED = $(shell printf "\33[31m")
Expand Down
51 changes: 51 additions & 0 deletions hack/githooks/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/sh

# ignore merge commits
MERGE_MSG=`cat $1 | egrep '^Merge branch*'`

if [ "$MERGE_MSG" != "" ]; then
exit 0
fi


# check for a valid commit message
COMMIT_MSG=`cat $1 | egrep "^(feat|fix|doc|docs|chore|build|ci|perf|style|revert|test)(\(\w+\))?!?:\s(\S|\w)+"`

if [ "$COMMIT_MSG" = "" ]; then
echo -e "
\033[31mError!\033[0m The commit message should be structured as follows:
\033[31m
<type>[optional scope]: <description>
[optional body]
[optional footer(s)]
\033[0m
where \"type\" can be: \033[32m feat fix doc docs chore ci build perf style revert test \033[0m
For details, please refer to \033[34m https://www.conventionalcommits.org/en/v1.0.0/#summary \033[0m
"
exit 1
fi

NAME=$(git config user.name)
EMAIL=$(git config user.email)

if [ -z "$NAME" ]; then
echo "please config user.name"
exit 1
fi

if [ -z "$EMAIL" ]; then
echo "please config user.email"
exit 1
fi

# add sign off
git interpret-trailers --if-exists doNothing --trailer \
"Signed-off-by: $NAME <$EMAIL>" \
--in-place "$1"

# check duplicate sign off
test "" = "$(grep '^Signed-off-by: ' "$1" |
sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || {
echo >&2 Duplicate Signed-off-by lines.
exit 1
}