-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommit.sh
More file actions
executable file
·65 lines (51 loc) · 2.23 KB
/
commit.sh
File metadata and controls
executable file
·65 lines (51 loc) · 2.23 KB
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
#!/usr/bin/env bash
main() {
scriptTag="<!-- SCRIPT_ADD_ITEMS_HERE -->"
messageTmpFile=$(mktemp) || fatal "error creating temporary file #1"
gitStagedFiles=$(git status --porcelain | grep -Ev '^( |\?)') || fatal "error getting git staged files"
gitDiff=$(git diff --staged)
printf 'TITLE_TO_CHANGE\nURL_TO_CHANGE\n%s\n\n%s\n' "$gitStagedFiles" "$gitDiff" >> "$messageTmpFile"
"$EDITOR" "$messageTmpFile" || fatal "error calling editor"
numLines=$(wc -l "$messageTmpFile" | cut -d ' ' -f 1) || fatal "error getting number of lines for message: $messageTmpFile"
if [ "$numLines" -lt 3 ]; then
fatal "error: message has <3 lines. aborting."
fi
title=$(cut -d $'\n' -f 1 < "$messageTmpFile") || fatal "error getting title from tmp file"
url=$(cut -d $'\n' -f 2 < "$messageTmpFile") || fatal "error getting url from tmp file"
description=$(cut -d $'\n' -f 3- < "$messageTmpFile") || fatal "error getting description from tmp file"
descriptionForChangelogXmlEntry=$(cut -d $'\n' -f 3- < "$messageTmpFile" | sed -E 's/^/ /') || fatal "error getting description from tmp file"
dateText=$(date -R) || fatal "error getting date"
uuid=$(< /proc/sys/kernel/random/uuid) || fatal "error getting uuid"
changelogEntry=$(cat <<EOF
<item>
<title>$title</title>
<link>$url</link>
<description>
$descriptionForChangelogXmlEntry
</description>
<pubDate>$dateText</pubDate>
<guid isPermaLink="false">urn:uuid:$uuid</guid>
</item>
EOF
)
changelogEntryFile=$(mktemp) || fatal "error creating temporary file #2"
printf ' %s\n%s\n' "$scriptTag" "$changelogEntry" > "$changelogEntryFile" || fatal "error writing changelog entry to tmp file"
sed -i -e "/$scriptTag/ {
r $changelogEntryFile
d
}" \
./changelog.rss
git add ./changelog.rss || fatal "error adding changelog to files to commit"
git commit -F - <<<"$title"$'\n'"$description" || fatal "error during git commit"
}
fatal() {
error "$1"
exit 1
}
error() {
printf 'error: \e[31m%s\e[0m\n' "$1" >> /dev/stderr
}
info() {
printf 'info: \e[34m%s\e[0m\n' "$1" >> /dev/stderr
}
main "$@"