|
| 1 | +# #!/usr/bin/env bash |
| 2 | +# set -euo pipefail |
| 3 | + |
| 4 | +# # Create commitlint config if it doesn't exist |
| 5 | +# if [ ! -f "$(git rev-parse --show-toplevel)/commitlint.config.js" ]; then |
| 6 | +# cat << 'CONFIG_EOF' > "$(git rev-parse --show-toplevel)/commitlint.config.js" |
| 7 | +# module.exports = { |
| 8 | +# extends: ['@commitlint/config-conventional'], |
| 9 | +# rules: { |
| 10 | +# 'type-enum': [2, 'always', [ |
| 11 | +# 'feat', // A new feature |
| 12 | +# 'fix', // A bug fix |
| 13 | +# 'docs', // Documentation only changes |
| 14 | +# 'style', // Changes that do not affect code meaning |
| 15 | +# 'refactor', // A code change that neither fixes a bug nor adds a feature |
| 16 | +# 'perf', // A code change that improves performance |
| 17 | +# 'test', // Adding missing tests or correcting existing tests |
| 18 | +# 'build', // Build system or external dependencies |
| 19 | +# 'ci', // CI configuration changes |
| 20 | +# 'chore', // Other changes that don't modify src or test files |
| 21 | +# 'revert', // Reverts a previous commit |
| 22 | +# ]], |
| 23 | +# 'type-case': [2, 'always', 'lowerCase'], |
| 24 | +# 'type-empty': [2, 'never'], |
| 25 | +# 'scope-case': [2, 'always', 'lowerCase'], |
| 26 | +# 'subject-empty': [2, 'never'], |
| 27 | +# 'subject-full-stop': [2, 'never', '.'], |
| 28 | +# 'header-max-length': [2, 'always', 72], |
| 29 | +# }, |
| 30 | +# }; |
| 31 | +# CONFIG_EOF |
| 32 | +# echo "✅ Created commitlint.config.js in repository root" |
| 33 | +# fi |
| 34 | + |
| 35 | +# # Ensure commitlint is available |
| 36 | +# if ! command -v commitlint >/dev/null 2>&1; then |
| 37 | +# echo "⚙️ Installing commitlint globally..." |
| 38 | +# npm install -g @commitlint/cli @commitlint/config-conventional >/dev/null 2>&1 |
| 39 | +# fi |
| 40 | + |
| 41 | +# # Read commit message |
| 42 | +# commit_msg_file="$1" |
| 43 | +# commit_msg=$(cat "$commit_msg_file") |
| 44 | + |
| 45 | +# # Run commitlint and capture output (important!) |
| 46 | +# lint_output=$(echo "$commit_msg" | commitlint 2>&1) || lint_status=$? |
| 47 | + |
| 48 | +# if [ "${lint_status:-0}" -ne 0 ]; then |
| 49 | +# RED='\033[0;31m' |
| 50 | +# YELLOW='\033[1;33m' |
| 51 | +# NC='\033[0m' |
| 52 | + |
| 53 | +# echo -e "${RED}\n❌ Commit message format error detected.${NC}" |
| 54 | +# echo -e "${YELLOW}\nCommit message must follow the Conventional Commit format:\n${NC}" |
| 55 | +# echo -e "${YELLOW} type(scope): subject${NC}" |
| 56 | +# echo -e "\n${YELLOW}Types:${NC}" |
| 57 | +# echo " feat : A new feature" |
| 58 | +# echo " fix : A bug fix" |
| 59 | +# echo " docs : Documentation only changes" |
| 60 | +# echo " style : Changes that do not affect code meaning" |
| 61 | +# echo " refactor : Code change that neither fixes a bug nor adds a feature" |
| 62 | +# echo " perf : Code change that improves performance" |
| 63 | +# echo " test : Adding or correcting tests" |
| 64 | +# echo " build : Changes to the build system or external dependencies" |
| 65 | +# echo " ci : CI configuration or scripts" |
| 66 | +# echo " chore : Other changes that don't modify src or test files" |
| 67 | +# echo " revert : Reverts a previous commit" |
| 68 | +# echo -e "\n${YELLOW}Examples:${NC}" |
| 69 | +# echo " feat(auth): add password reset functionality" |
| 70 | +# echo " fix(api): handle null server response" |
| 71 | +# echo " docs(readme): update installation instructions" |
| 72 | + |
| 73 | +# echo -e "\n${RED}Commitlint output:${NC}" |
| 74 | +# echo "$lint_output" |
| 75 | + |
| 76 | +# echo -e "\n${RED}❗ Please fix your commit message and try again.${NC}" |
| 77 | +# exit 1 |
| 78 | +# else |
| 79 | +# echo -e "\033[0;32m✅ Commit message passed Conventional Commit check.\033[0m" |
| 80 | +# fi |
| 81 | + |
| 82 | + |
| 83 | +#!/usr/bin/env bash |
| 84 | +set -euo pipefail |
| 85 | + |
| 86 | +# Create commitlint config if it doesn't exist |
| 87 | +if [ ! -f "$(git rev-parse --show-toplevel)/commitlint.config.cjs" ]; then |
| 88 | + cat << 'CONFIG_EOF' > "$(git rev-parse --show-toplevel)/commitlint.config.cjs" |
| 89 | +module.exports = { |
| 90 | + extends: ['@commitlint/config-conventional'], |
| 91 | + rules: { |
| 92 | + 'type-enum': [2, 'always', [ |
| 93 | + 'feat', // A new feature |
| 94 | + 'fix', // A bug fix |
| 95 | + 'docs', // Documentation only changes |
| 96 | + 'style', // Changes that do not affect code meaning |
| 97 | + 'refactor', // A code change that neither fixes a bug nor adds a feature |
| 98 | + 'perf', // A code change that improves performance |
| 99 | + 'test', // Adding missing tests or correcting existing tests |
| 100 | + 'build', // Build system or external dependencies |
| 101 | + 'ci', // CI configuration changes |
| 102 | + 'chore', // Other changes that don't modify src or test files |
| 103 | + 'revert', // Reverts a previous commit |
| 104 | + ]], |
| 105 | + 'type-case': [2, 'always', 'lowerCase'], |
| 106 | + 'type-empty': [2, 'never'], |
| 107 | + 'scope-case': [2, 'always', 'lowerCase'], |
| 108 | + 'subject-empty': [2, 'never'], |
| 109 | + 'subject-full-stop': [2, 'never', '.'], |
| 110 | + 'header-max-length': [2, 'always', 72], |
| 111 | + }, |
| 112 | +}; |
| 113 | +CONFIG_EOF |
| 114 | + echo "✅ Created commitlint.config.cjs in repository root" |
| 115 | +fi |
| 116 | + |
| 117 | +# Ensure commitlint is available |
| 118 | +if ! command -v commitlint >/dev/null 2>&1; then |
| 119 | + echo "⚙️ Installing commitlint globally..." |
| 120 | + npm install -g @commitlint/cli @commitlint/config-conventional >/dev/null 2>&1 |
| 121 | +fi |
| 122 | + |
| 123 | +# Read commit message |
| 124 | +commit_msg_file="$1" |
| 125 | +commit_msg=$(cat "$commit_msg_file") |
| 126 | + |
| 127 | +# Run commitlint and capture output (important!) |
| 128 | +lint_output=$(echo "$commit_msg" | commitlint 2>&1) || lint_status=$? |
| 129 | + |
| 130 | +if [ "${lint_status:-0}" -ne 0 ]; then |
| 131 | + RED='\033[0;31m' |
| 132 | + YELLOW='\033[1;33m' |
| 133 | + NC='\033[0m' |
| 134 | + |
| 135 | + echo -e "${RED}\n❌ Commit message format error detected.${NC}" |
| 136 | + echo -e "${YELLOW}\nCommit message must follow the Conventional Commit format:\n${NC}" |
| 137 | + echo -e "${YELLOW} type(scope): subject${NC}" |
| 138 | + echo -e "\n${YELLOW}Types:${NC}" |
| 139 | + echo " feat : A new feature" |
| 140 | + echo " fix : A bug fix" |
| 141 | + echo " docs : Documentation only changes" |
| 142 | + echo " style : Changes that do not affect code meaning" |
| 143 | + echo " refactor : Code change that neither fixes a bug nor adds a feature" |
| 144 | + echo " perf : Code change that improves performance" |
| 145 | + echo " test : Adding or correcting tests" |
| 146 | + echo " build : Changes to the build system or external dependencies" |
| 147 | + echo " ci : CI configuration or scripts" |
| 148 | + echo " chore : Other changes that don't modify src or test files" |
| 149 | + echo " revert : Reverts a previous commit" |
| 150 | + echo -e "\n${YELLOW}Examples:${NC}" |
| 151 | + echo " feat(auth): add password reset functionality" |
| 152 | + echo " fix(api): handle null server response" |
| 153 | + echo " docs(readme): update installation instructions" |
| 154 | + |
| 155 | + echo -e "\n${RED}Commitlint output:${NC}" |
| 156 | + echo "$lint_output" |
| 157 | + |
| 158 | + echo -e "\n${RED}❗ Please fix your commit message and try again.${NC}" |
| 159 | + exit 1 |
| 160 | +else |
| 161 | + echo -e "\033[0;32m✅ Commit message passed Conventional Commit check.\033[0m" |
| 162 | +fi |
0 commit comments