diff --git a/script/githooks/commit-msg.sh b/script/githooks/commit-msg.sh new file mode 100644 index 000000000..255a60e97 --- /dev/null +++ b/script/githooks/commit-msg.sh @@ -0,0 +1,25 @@ + +#!/usr/bin/env bash + +# Copyright © 2023 OpenIMSDK. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ============================================================================== +# +# Store this file as .git/hooks/commit-msg in your repository in order to +# enforce checking for proper commit message format before actual commits. +# You may need to make the script executable by 'chmod +x .git/hooks/commit-msg'. + +# commit-msg use go-gitlint tool, install go-gitlint via `go get github.com/llorllale/go-gitlint/cmd/go-gitlint` +go-gitlint --msg-file="$1" diff --git a/script/githooks/pre-commit.sh b/script/githooks/pre-commit.sh index a0c60d14a..752e97568 100644 --- a/script/githooks/pre-commit.sh +++ b/script/githooks/pre-commit.sh @@ -1,4 +1,20 @@ #!/usr/bin/env bash + +# Copyright © 2023 OpenIMSDK. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + LC_ALL=C local_branch="$(git rev-parse --abbrev-ref HEAD)" @@ -7,10 +23,14 @@ valid_branch_regex="^(master|develop)$|(feature|release|hotfix)\/[a-z0-9._-]+$|^ message="There is something wrong with your branch name. Branch names in this project must adhere to this contract: $valid_branch_regex. Your commit will be rejected. You should rename your branch to a valid name and try again." +message2="If you're not familiar with the contribution process, please read our contributor documentation again +-> https://github.com/OpenIMSDK/Open-IM-Server/blob/main/CONTRIBUTING.md" + if [[ ! $local_branch =~ $valid_branch_regex ]] then echo "$message" + echo "$message2" exit 1 fi diff --git a/script/make-rules/common.mk b/script/make-rules/common.mk index 1c0a28f15..ac9e6f605 100644 --- a/script/make-rules/common.mk +++ b/script/make-rules/common.mk @@ -120,7 +120,7 @@ MAKEFLAGS += --no-print-directory endif # Copy githook scripts when execute makefile -COPY_GITHOOK:=$(shell cp -f script/githooks/* .git/hooks/) +COPY_GITHOOK:=$(shell cp -f script/githooks/* .git/hooks/; chmod +x .git/hooks/commit-msg') # COMMA: Concatenate multiple strings to form a list of strings COMMA := ,