-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.sh
executable file
·101 lines (83 loc) · 2.26 KB
/
script.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/bash
# Color codes
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BOLD='\033[1m'
NC='\033[0m' # No Color
# Function to display an error message
function error() {
echo -e "${RED}${BOLD}ERROR: $1${NC}" >&2
exit 1
}
# Asks for the commit type and checks if the type is valid
for i in {1..3}
do
echo -e "${GREEN}${BOLD}What type is it? (feat, fix, docs...)${NC}"
echo -e "${YELLOW}Options are: feat, fix, docs, chore, style, refactor, test, perf, ci, build${NC}"
read type
if [[ "$type" =~ ^(feat|fix|docs|chore|style|refactor|test|perf|ci|build)$ ]]; then
break
else
echo -e "${RED}The commit type must be one of the following: feat, bug, doc, chore, style, refactor, test, perf, ci, build.${NC}"
if [[ $i -eq 3 ]]; then
exit 1
fi
fi
done
# Asks for the commit scope
echo -e "${GREEN}${BOLD}In which scope? (auth, api, db...)${NC}"
read scope
# Asks for a description of the commit
echo -e "${GREEN}${BOLD}A description?${NC}"
read description
# Asks if there are breaking changes
for i in {1..3}
do
echo -e "${GREEN}${BOLD}Are there any breaking changes? (y/n)${NC}"
read breaking_changes
if [[ "$breaking_changes" =~ ^(y|Y|n|N)$ ]]; then
break
else
echo -e "${RED}Please answer with y or n.${NC}"
if [[ $i -eq 3 ]]; then
exit 1
fi
fi
done
# Asks for a body for the commit (optional)
echo -e "${GREEN}${BOLD}A body?${NC}"
read body
# Asks for a footer for the commit (optional)
echo -e "${GREEN}${BOLD}Reference to a PR or an issue? (123)${NC}"
read pr
# Génère le message de commit
if [ -z "$scope" ]; then
message="$type"
else
message="$type($scope)"
fi
if [[ "$breaking_changes" =~ ^(y|Y)$ ]]; then
message="$message!"
fi
message="$message: $description"
if [ ! -z "$body" ]; then
message="$message"$'\n\n'"$body"
fi
if [ ! -z "$pr" ]; then
footer="Close #$pr"
message="$message"$'\n\n'"$footer"
fi
# Shows the commit message
echo -e "${YELLOW}${BOLD}Commit message:${NC}"
echo -e "$message"
# Asks for confirmation
echo -e "${GREEN}${BOLD}Do you want to commit this? (y/n)${NC}"
read confirm
# Commits the changes
if [[ "$confirm" =~ ^(y|Y)$ ]]; then
git commit -m "$message"
echo -e "${GREEN}${BOLD}Changes committed!${NC}"
else
echo -e "${RED}${BOLD}Changes not committed!${NC}"
fi