forked from PhenomDevel/BlizzHUDTweaks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
changelog.sh
executable file
·79 lines (59 loc) · 2.27 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
#!/bin/bash
GITHUB_COMMIT_URL="https://github.com/PhenomDevel/BlizzHUDTweaks/commit"
LATEST_TAG=$(git describe --tags --abbrev=0)
PREVIOUS_TAG=$(git describe --tags --exclude '*beta*' --abbrev=0 `git rev-list --tags --skip=1 --max-count=1 --abbrev=0`)
COMMITS=$(git log $PREVIOUS_TAG..$LATEST_TAG --pretty=format:"%h")
echo "Processing all commits between tags $LATEST_TAG and $PREVIOUS_TAG"
NOW=$(date +'%d.%m.%Y - %H:%M:%S')
# Store our changelog in a variable to be saved to a file at the end
MARKDOWN="# Release $LATEST_TAG ~ $NOW"
MARKDOWN+='\n'
BUG_PATTERN="\[bug\]|\[fix\]"
FEATURE_PATTERN="\[feature\]|\[feat\]"
MARKDOWN_BUGS=""
MARKDOWN_FEATURES=""
MARKDOWN_MISC=""
BUG_COUNT=0
FEATURE_COUNT=0
MISC_COUNT=0
# Loop over each commit and look for merged pull requests
for COMMIT in $COMMITS; do
# Get the subject of the current commit
SUBJECT=$(git log -1 ${COMMIT} --pretty=format:"%s")
BODY=$(git log -1 ${COMMIT} --pretty=format:"%b")
CLEAN_SUBJECT="${SUBJECT/\[bug\]/}"
CLEAN_SUBJECT="${CLEAN_SUBJECT/\[fix\]/}"
CLEAN_SUBJECT="${CLEAN_SUBJECT/\[feature\]/}"
CLEAN_SUBJECT="${CLEAN_SUBJECT/\[feat\]/}"
IS_BUG=$( grep -Eo $BUG_PATTERN <<< "$SUBJECT")
IS_FEATURE=$( grep -Eo $FEATURE_PATTERN <<< "$SUBJECT")
if [[ ! -z $IS_BUG ]]; then
BUG_COUNT=$((BUG_COUNT + 1))
MARKDOWN_BUGS+=" - ([${COMMIT}](${GITHUB_COMMIT_URL}/${COMMIT})) $CLEAN_SUBJECT"
MARKDOWN_BUGS+="\n"
fi
if [[ ! -z $IS_FEATURE ]]; then
FEATURE_COUNT=$((FEATURE_COUNT + 1))
MARKDOWN_FEATURES+=" - ([${COMMIT}](${GITHUB_COMMIT_URL}/${COMMIT})) $CLEAN_SUBJECT"
MARKDOWN_FEATURES+="\n"
fi
if [ ! $IS_BUG ] && [ ! $IS_FEATURE ]; then
MISC_COUNT=$((MISC_COUNT + 1))
MARKDOWN_MISC+=" - ([${COMMIT}](${GITHUB_COMMIT_URL}/${COMMIT})) $CLEAN_SUBJECT"
MARKDOWN_MISC+="\n"
fi
done
echo "Found $BUG_COUNT bug commit(s)"
echo "Found $FEATURE_COUNT feature commit(s)"
echo "Found $MISC_COUNT misc commit(s)"
if [[ "$BUG_COUNT" -gt 0 ]]; then
MARKDOWN+="## Bugfixes (${BUG_COUNT})\n$MARKDOWN_BUGS\n"
fi
if [[ "$FEATURE_COUNT" -gt 0 ]]; then
MARKDOWN+="## Features (${FEATURE_COUNT})\n$MARKDOWN_FEATURES\n"
fi
if [[ "$MISC_COUNT" -gt 0 ]]; then
MARKDOWN+="## Misc (${MISC_COUNT})\n$MARKDOWN_MISC\n"
fi
# Save our markdown to a file
echo -e $MARKDOWN > CHANGELOG.md