-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathgen_changelog
executable file
·82 lines (69 loc) · 2.61 KB
/
gen_changelog
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
#!/bin/bash -e
parse_newstyle() {
while IFS= read -r line; do
if printf '%s' "$line" | \
grep -qE '^[A-z0-9\.]+-\d+ \(\d{4}-\d{2}-\d{2}\)'; then
version=$(printf '%s' "$line" | cut -d' ' -f1)
logline=''
elif printf '%s' "$line" | grep -qE '^\t[A-z]+'; then
logline=$(printf '%s\n%s\n' "$logline" "$line")
releases["$version"]="$logline"
fi
done < "${pkgdir}/${changelog}"
}
parse_oldstyle() {
while IFS= read -r line; do
if printf '%s' "$line" | \
grep -qE '^\d{4}-\d{2}-\d{2}'; then
date=$(printf '%s' "$line" | grep -oE '^\d{4}-\d{2}-\d{2}')
if [ -n "$entry" ]; then
# Print the previous entry and clear state
printf '%s\n\n' "$entry"
entry=''
logline=''
fi
elif printf '%s' "$line" | \
grep -qE '^\t\* .*-\d+ :$'; then
version=$(printf '%s' "$line" | grep -oE '\t\* .*-\d+' | cut -d' ' -f2)
elif printf '%s' "$line" | grep -qE '^\t[A-z]+'; then
logline=$(printf '%s\n%s\n' "$logline" "$line")
entry=$(printf '%s (%s)\n%s\n' "$version" "$date" "$logline")
fi
done < "${pkgdir}/${changelog}"
# Print the last entry
[ -n "$entry" ] && printf '%s\n' "$entry"
}
set -o pipefail
pkgdir='.'
[ -n "$1" ] && pkgdir="$1"
if [ ! -d "$pkgdir" ]; then
printf 'Missing directory: %s\n' "$pkgdir"
exit 1
fi
# shellcheck disable=SC1091
. "${pkgdir}/PKGBUILD"
[ -n "$changelog" ] || changelog='ChangeLog'
[ -e "${pkgdir}/${changelog}" ] || touch "${pkgdir}/${changelog}"
if head -n1 "${pkgdir}/${changelog}" | \
grep -qE '^\d{4}-\d{2}-\d{2}.*<[A-z\d._%+-]+@[A-z\d.-]+\.[A-z]{2,}>$'; then
content=$(parse_oldstyle)
printf '%s\n' "$content" >"${pkgdir}/${changelog}"
fi
declare -A releases
parse_newstyle
# shellcheck disable=SC2154
this_version="${pkgver}-${pkgrel}"
if [ ${releases[$this_version]+x} ]; then
printf 'An entry for version %s already exists in the ChangeLog\n' "$this_version"
exit 1
fi
printf 'Enter a change description for %s (press ctrl-d when done):\n' "$this_version"
input=$(cat)
wrapped_input=$(printf '%s' "$input" | fold -s -w 72 | sed -e 's/^[ \t]*//' -e 's@^@\t@')
tmpfile=$(mktemp)
entry=$(printf '%s (%s)\n\n%s\n\n' "$this_version" "$(date +%Y-%m-%d)" "$wrapped_input")
printf '%s\n\n' "$entry" >"$tmpfile"
cat "${pkgdir}/${changelog}" >>"$tmpfile"
mv "$tmpfile" "${pkgdir}/${changelog}"
# shellcheck disable=SC2154
printf '\nAdded the following entry to the ChangeLog for %s:\n\n%s\n\n' "$pkgname" "$entry"