-
Notifications
You must be signed in to change notification settings - Fork 12
/
CHANGELOG.sh
112 lines (91 loc) · 1.72 KB
/
CHANGELOG.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
102
103
104
105
106
107
108
109
110
111
#!/bin/bash
## Author LinkinStar
# solve the space by IFS
IFS=`echo -en "\n\b"`
echo -en $IFS
if [ -f "CHANGELOG.md" ];then
rm -f CHANGELOG.md
touch CHANGELOG.md
else
touch CHANGELOG.md
fi
function printFeat(){
for i in ${feat[@]}
do
echo "- "$i >> CHANGELOG.md
done
echo >> CHANGELOG.md
}
function printFix(){
for i in ${fix[@]}
do
echo "- "$i >> CHANGELOG.md
done
echo >> CHANGELOG.md
}
function printOther(){
for i in ${other[@]}
do
echo "- "$i >> CHANGELOG.md
done
echo >> CHANGELOG.md
}
function checkLog(){
if [[ $1 == "feat"* ]]
then
feat[featIndex]=$1
let featIndex++
elif [[ $1 == "fix"* ]]
then
fix[fixIndex]=$1
let fixIndex++
else
other[otherIndex]=$1
let otherIndex++
fi
}
function printLog(){
if [[ $featIndex -ne 0 ]]; then
echo "### Features" >> CHANGELOG.md
printFeat
fi
if [[ $fixIndex -ne 0 ]]; then
echo "### Bug Fixes" >> CHANGELOG.md
printFix
fi
if [[ $otherIndex -ne 0 ]]; then
echo "### Other Changes" >> CHANGELOG.md
printOther
fi
feat=()
featIndex=0
fix=()
fixIndex=0
other=()
otherIndex=0
}
curDate=""
function checkDate()
{
if [[ $curDate = $1 ]]; then
return
fi
curDate=$1
printLog
echo >> CHANGELOG.md
echo "## "$curDate >> CHANGELOG.md
}
commitMessageList=`git log --date=format:'%Y-%m-%d' --pretty=format:'%cd%n%s'`
index=0
for i in ${commitMessageList[@]}
do
if [[ $index%2 -eq 0 ]]
then
checkDate $i
else
#echo "- "$i >> CHANGELOG.md
checkLog $i
fi
let index++
done
printLog