forked from lua/lua
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchangelog.sh
60 lines (45 loc) · 1.15 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
#!/usr/bin/env bash
###########################
# Git Changelog Generator #
# By: HorusHe4rt #
###########################
file=CHANGELOG.md
header="# CHANGELOG
> This changelog is automaticaly generated.
> If you find any issue with this file, please report to the devs.
## [Unreleased]
"
echo "$header" > $file
function log_by_tag() {
if [[ $2 == "HEAD" ]]; then
git log $1..$2 --pretty=" - [%h] %s (%an)" >> $file
elif [[ -z $2 ]]; then
echo "## [$1]" >> $file
git log $1 --pretty=" - [%h] %s (%an)" >> $file
else
echo "## [$2]" >> $file
git log $1..$2 --pretty=" - [%h] %s (%an)" >> $file
fi
echo "" >> $file
}
tags=$(git tag --sort=-v:refname)
if [[ -z ${tags[*]} ]]; then
echo -e "\e[33;1m[⚠️] Your repo does not have any git tags!\e[39;21m"
echo ""
echo "Generating a plain changelog..."
git log "HEAD" --pretty=" - [%h] %s (%an)" >> $file
exit 0
else
echo -e "\e[32;1m[✔️] Your repo does have git tags!\e[39;21m"
echo ""
echo "Generating a pretty changelog..."
tag=("HEAD")
prev=""
for p in ${tags[@]}; do
prev=$p
log_by_tag $prev $tag
tag=$prev
done
log_by_tag $prev
exit 0
fi