-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from LerianStudio/feature/implement-githooks
insert githooks
- Loading branch information
Showing
4 changed files
with
141 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/bin/sh | ||
# | ||
# Add a specific emoji to the end of the first line in every commit message | ||
# based on the conventional commits keyword. | ||
|
||
if [ ! -f "$1" ] || grep -q "fixup!" "$1"; then | ||
# Exit if we didn't get a target file for some reason | ||
# or we have a fixup commit | ||
exit 0 | ||
fi | ||
|
||
KEYWORD=$(head -n 1 "$1" | awk '{print $1}' | sed -e 's/://') | ||
|
||
case $KEYWORD in | ||
"feat"|"feat("*) | ||
EMOJI=":sparkles:" | ||
;; | ||
"fix"|"fix("*) | ||
EMOJI=":bug:" | ||
;; | ||
"docs"|"docs("*) | ||
EMOJI=":books:" | ||
;; | ||
"style"|"style("*) | ||
EMOJI=":gem:" | ||
;; | ||
"refactor"|"refactor("*) | ||
EMOJI=":hammer:" | ||
;; | ||
"perf"|"perf("*) | ||
EMOJI=":rocket:" | ||
;; | ||
"test"|"test("*) | ||
EMOJI=":rotating_light:" | ||
;; | ||
"build"|"build("*) | ||
EMOJI=":package:" | ||
;; | ||
"ci"|"ci("*) | ||
EMOJI=":construction_worker:" | ||
;; | ||
"chore"|"chore("*) | ||
EMOJI=":wrench:" | ||
;; | ||
*) | ||
EMOJI="" | ||
;; | ||
esac | ||
|
||
MESSAGE=$(sed -E "1s/(.*)/\\1 $EMOJI/" <"$1") | ||
|
||
echo "$MESSAGE" >"$1" |
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,51 @@ | ||
#!/bin/bash | ||
|
||
source "$PWD"/common/shell/colors.sh | ||
source "$PWD"/common/shell/ascii.sh | ||
|
||
branch=$(git rev-parse --abbrev-ref HEAD) | ||
|
||
if [[ $branch == "main" || $branch == "develop" || $branch == release/* ]]; then | ||
echo "${bold}You can't commit directly to protected branches" | ||
exit 1 | ||
fi | ||
|
||
commit_msg_type_regex='feature|fix|refactor|style|test|docs|build' | ||
commit_msg_scope_regex='.{1,20}' | ||
commit_msg_description_regex='.{1,100}' | ||
commit_msg_regex="^(${commit_msg_type_regex})(\(${commit_msg_scope_regex}\))?: (${commit_msg_description_regex})\$" | ||
merge_msg_regex="^Merge branch '.+'\$" | ||
|
||
zero_commit="0000000000000000000000000000000000000000" | ||
|
||
# Do not traverse over commits that are already in the repository | ||
excludeExisting="--not --all" | ||
|
||
error="" | ||
while read oldrev newrev refname; do | ||
# branch or tag get deleted | ||
if [ "$newrev" = "$zero_commit" ]; then | ||
continue | ||
fi | ||
|
||
# Check for new branch or tag | ||
if [ "$oldrev" = "$zero_commit" ]; then | ||
rev_span=$(git rev-list $newrev $excludeExisting) | ||
else | ||
rev_span=$(git rev-list $oldrev..$newrev $excludeExisting) | ||
fi | ||
|
||
for commit in $rev_span; do | ||
commit_msg_header=$(git show -s --format=%s $commit) | ||
if ! [[ "$commit_msg_header" =~ (${commit_msg_regex})|(${merge_msg_regex}) ]]; then | ||
echo "$commit" >&2 | ||
echo "ERROR: Invalid commit message format" >&2 | ||
echo "$commit_msg_header" >&2 | ||
error="true" | ||
fi | ||
done | ||
done | ||
|
||
if [ -n "$error" ]; then | ||
exit 1 | ||
fi |
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,17 @@ | ||
#!/bin/bash | ||
|
||
source "$PWD"/common/shell/colors.sh | ||
source "$PWD"/common/shell/ascii.sh | ||
|
||
while read local_ref local_sha remote_ref remote_sha; do | ||
if [[ "$local_ref" =~ ^refs/heads/ ]]; then | ||
branch_name=$(echo "$local_ref" | sed 's|^refs/heads/||') | ||
|
||
if [[ ! "$branch_name" =~ ^(feature|fix|hotfix|docs|refactor|build|test)/.*$ ]]; then | ||
echo "${bold}Branch names must start with 'feature/', 'fix/', 'refactor/', 'docs/', 'test/' or 'hotfix/' followed by either a task id or feature name." | ||
exit 1 | ||
fi | ||
fi | ||
done | ||
|
||
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,21 @@ | ||
#!/usr/bin/env bash | ||
|
||
zero_commit="0000000000000000000000000000000000000000" | ||
|
||
while read oldrev newrev refname; do | ||
|
||
if [[ $oldrev == $zero_commit ]]; then | ||
continue | ||
fi | ||
|
||
if [[ $refname == "refs/heads/main" && $newrev != $zero_commit ]]; then | ||
branch_name=$(basename $refname) | ||
|
||
if [[ $branch_name == release/* ]]; then | ||
continue | ||
else | ||
echo "Error: You can only merge branches that start with 'release/' into the main branch." | ||
exit 1 | ||
fi | ||
fi | ||
done |