@@ -13,7 +13,9 @@ CYAN="\033[0;36m"
1313RESET=" \033[0m"
1414
1515# Valid types
16- TYPES=(" feat" " fix" " docs" " style" " refactor" " pref" " test" " build" " ci" " chore" " revert" )
16+ TYPES=(" feat" " fix" " docs" " style" " refactor"
17+ " pref" " test" " build" " ci" " chore" " revert" )
18+
1719NUMBERS=(" 1" " 2" " 3" " 4" " 5" " 6" " 7" " 8" " 9" " 10" " 11" )
1820
1921# Type section
@@ -22,24 +24,30 @@ printf "${BLUE}>>> Type of change (name or number)?${RESET}\n\n"
2224printf " ${CYAN} 1. feat${RESET} - A new feature.\n"
2325printf " ${CYAN} 2. fix${RESET} - A bug fix.\n"
2426printf " ${CYAN} 3. docs${RESET} - Documentation only changes.\n"
25- printf " ${CYAN} 4. style${RESET} - Changes that do notaffect the meaning of the code (white-space, formatting, missing semi-colons, etc).\n"
26- printf " ${CYAN} 5. refactor${RESET} - A Code change that neither fixes a bug nor adds a feature.\n"
27+ printf " ${CYAN} 4. style${RESET} - Changes that do notaffect the meaning of \
28+ the code (white-space, formatting, missing semi-colons, etc).\n"
29+ printf " ${CYAN} 5. refactor${RESET} - A Code change that neither fixes a bug \
30+ nor adds a feature.\n"
2731printf " ${CYAN} 6. pref${RESET} - A code change that improves performance.\n"
28- printf " ${CYAN} 7. test${RESET} - Adding missing tests or correcting existing tests.\n"
29- printf " ${CYAN} 8. build${RESET} - Changes that effect the build system or external dependencies (example scopes: glup, broccoli, npm).\n"
30- printf " ${CYAN} 9. ci${RESET} - Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs).\n"
31- printf " ${CYAN} 10. chore${RESET} - Other changes that don't modify src or test files.\n"
32+ printf " ${CYAN} 7. test${RESET} - Adding missing tests or correcting existing \
33+ tests.\n"
34+ printf " ${CYAN} 8. build${RESET} - Changes that effect the build system or \
35+ external dependencies (example scopes: glup, broccoli, npm).\n"
36+ printf " ${CYAN} 9. ci${RESET} - Changes to our CI configuration files and \
37+ scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs).\n"
38+ printf " ${CYAN} 10. chore${RESET} - Other changes that don't modify src or test \
39+ files.\n"
3240printf " ${CYAN} 11. revert${RESET} - Reverts a previous commit.\n\n"
3341
3442while : ; do
35- read -e TYPE
43+ read -e type_var
3644 # To lower case
37- TYPE =${TYPE ,,}
45+ type_var =${type_var ,,}
3846 # When input type is valid loop break
39- if [[ " ${NUMBERS[*]} " =~ " ${TYPE } " ]]; then
40- TYPE =" ${TYPES[TYPE - 1]} "
47+ if [[ " ${NUMBERS[*]} " =~ " ${type_var } " ]]; then
48+ type_var =" ${TYPES[type_var - 1]} "
4149 break
42- elif [[ " ${TYPES[*]} " =~ " ${TYPE } " ]]; then
50+ elif [[ " ${TYPES[*]} " =~ " ${type_var } " ]]; then
4351 break
4452 else
4553 printf " ${RED} ❌ Please select a valid type.${RESET} \n"
4856
4957# Scppe section
5058printf " \n${BLUE} >>> Scope of this change (optional)?${RESET} \n"
51- printf " The scope could be anything specifying place of the commit change e.g a file name, function name, class name, component name etc.\n\n"
52- read -e SCOPE
59+ printf " The scope could be anything specifying place of the commit change e.g \
60+ a file name, function name, class name, component name etc.\n\n"
61+ read -e scope
5362
5463# Subject section
5564printf " \n${BLUE} >>> Short description?${RESET} \n"
5665printf " The short description contains succinct description of the change:\n"
57- printf ' • use the imperative, present tense: "change" not "changed" nor "changes"\n'
66+ printf " • use the imperative, present tense: 'change' not 'changed' nor \
67+ 'changes'\n"
5868printf " • don't capitalize first letter\n"
5969printf " • no dot (.) at the end\n\n"
6070
6171while : ; do
62- read -e SHORT_DESC
63- if [ -z " $SHORT_DESC " ]; then
72+ read -e short_desc
73+ if [ -z " $short_desc " ]; then
6474 printf " ${RED} ❌ Short description can not be empty.${RESET} \n"
6575 else
6676 break
6979
7080# Description section
7181printf " \n${BLUE} >>> Long description (optional)?${RESET} \n"
72- printf " The body should include the motivation for the change and contrast this with previous behavior.\n\n"
73- read -e LONG_DESC
82+ printf " The body should include the motivation for the change and contrast \
83+ this with previous behavior.\n\n"
84+ read -e long_desc
7485
7586# Breaking changes section
7687printf " \n${BLUE} >>> Breaking changes (optional)?${RESET} \n"
7788printf " note the reason for a breaking change within the commit.\n\n"
78- read -e BREAKING_CHANGES
89+ read -e breaking_changes
7990
8091# Closed issues section
8192printf " \n${BLUE} >>> Closed issues (optional)?${RESET} \n"
82- printf " The syntax for closing keywords depends on whether the issue is in the same repository as the pull request.\n"
93+ printf " The syntax for closing keywords depends on whether the issue is in \
94+ the same repository as the pull request.\n"
8395printf " • Issue in the same repository -> Closes #10\n"
8496printf " • Issue in a different repository -> Fixes octo-org/octo-repo#100\n"
85- printf " • Multiple issues -> Resolves #10, resolves #123, resolves octo-org/octo-repo#100\n\n"
86- read -e CLOSED_ISSUES
97+ printf " • Multiple issues -> Resolves #10, resolves #123, resolves \
98+ octo-org/octo-repo#100\n\n"
99+ read -e closed_issues
87100
88101# Result section
89- if [ ! -z " $SCOPE " ]; then
90- SCOPE =" (${SCOPE } )"
102+ if [ ! -z " $scope " ]; then
103+ scope =" (${scope } )"
91104fi
92105
93- if [ ! -z " $BREAKING_CHANGES " ]; then
94- BREAKING_CHANGES =" BREAKING CHANGE: ${BREAKING_CHANGES } "
106+ if [ ! -z " $breaking_changes " ]; then
107+ breaking_changes =" BREAKING CHANGE: ${breaking_changes } "
95108fi
96109
97- printf " \n ${GREEN}${TYPE }${SCOPE } : ${SHORT_DESC }
98- ${LONG_DESC }
99- ${BREAKING_CHANGES }
100- ${CLOSED_ISSUES }${RESET} \n\n"
110+ printf " \n ${GREEN}${type_var }${scope } : ${short_desc }
111+ ${long_desc }
112+ ${breaking_changes }
113+ ${closed_issues }${RESET} \n\n"
101114
102115# Git commit
103- RESULT_CODE =$?
104- if [ " $RESULT_CODE " = 0 ]; then
105- git commit -m " ${TYPE }${SCOPE } : ${SHORT_DESC }
106- ${LONG_DESC }
107- ${BREAKING_CHANGES }
108- ${CLOSED_ISSUES } "
116+ result_code =$?
117+ if [ " $result_code " = 0 ]; then
118+ git commit -m " ${type_var }${scope } : ${short_desc }
119+ ${long_desc }
120+ ${breaking_changes }
121+ ${closed_issues } "
109122else
110123 printf " \n${RED} ❌ An error occurred. Please try again.${RESET} \n"
124+ exit 1
111125fi
0 commit comments