forked from synfig/synfig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ChangeLog-generate.sh
executable file
·62 lines (53 loc) · 1.95 KB
/
ChangeLog-generate.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
#!/bin/bash
# https://stackoverflow.com/questions/59895/how-to-get-the-source-directory-of-a-bash-script-from-within-the-script-itself
SOURCE="${BASH_SOURCE[0]}"
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
CHANGELOG="${DIR}/ChangeLog-development.md"
if [ -z "$1" ]; then
# Read starting commit ID from ChangeLog.last_id
if [ -f "${DIR}/ChangeLog.last_id" ]; then
START=`cat "${DIR}/ChangeLog.last_id" | head -n1 | awk '{print $1;}'`
else
echo "ERROR: Please specify starting commit id as first argument."
exit 1
fi
else
START="$1"
fi
#START="upstream/changelog"
# Get list of all commits
COMMITS=`git log ${START}...upstream/master --first-parent --pretty=format:'%H' --reverse`
if [ -f "${CHANGELOG}" ]; then
tac "${CHANGELOG}" > "${CHANGELOG}.new"
fi
if [ ! -z "${COMMITS}" ]; then
while IFS= read -r CMT; do
TAGS=""
# Get list of changed files
MESSAGE=`git log --format=%B -n 1 ${CMT} | head -n 1`
FILES=`git log -m -1 --name-only --pretty="format:" ${CMT}`
while IFS= read -r FILENAME; do
# check if filename starts with "ETL" "synfig-core" or "synfig-studio"
if [[ $FILENAME == ETL/* ]]; then
if [[ $TAGS != *"[ETL]"* ]]; then
TAGS="$TAGS [ETL]"
fi
elif [[ $FILENAME == synfig-core/* ]]; then
if [[ $TAGS != *"[core]"* ]]; then
TAGS="$TAGS [core]"
fi
elif [[ $FILENAME == synfig-studio/* ]]; then
if [[ $TAGS != *"[studio]"* ]]; then
TAGS="$TAGS [studio]"
fi
fi
#echo "... ${FILENAME}"
done <<< "$FILES"
MESSAGE=`echo "$MESSAGE" | sed -e "s/#\([0-9]\+\)/\[\\\#\1\]\(https\:\/\/github\.com\/synfig\/synfig\/issues\/\1\)/g" | sed -e "s/\*/\\\*/g" | sed -e "s/\_/\\\_/g"`
echo "- [\`${CMT:0:7}\`](https://github.com/synfig/synfig/commit/${CMT}) ${MESSAGE}${TAGS}" >> "${CHANGELOG}.new"
done <<< "$COMMITS"
fi
#Save last commit ID
git rev-parse upstream/master > "${DIR}/ChangeLog.last_id"
tac "${CHANGELOG}.new" > "${CHANGELOG}"
rm "${CHANGELOG}.new" || true