-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathadd-comment.sh
executable file
·58 lines (48 loc) · 1006 Bytes
/
add-comment.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
#!/bin/bash
# Check usage
if [ "$#" -lt 4 ]
then
echo "Usage: ./add-comment.sh <reply_to> <author> <email> <text>"
exit 1
fi
# Make sure our reference repo is up to date
if [ ! -d "repo" ]
then
echo "Please clone into a local repo:"
echo "git clone --bare <REPO_URL.git> repo"
exit
fi
pushd repo
git fetch --all --prune
popd
# Generate a comment id
CID="$(date +%s)-$(pwgen)"
# Create a working copy
git clone -b master repo "$CID"
pushd "$CID"
# Read input
reply_to="$1"
author="$2"
email="$3"
text="$4"
# Create new branch
BRANCH="comment/$CID"
git checkout -b "$BRANCH"
# Create comment file
FILE="_data/comments/$CID.yaml"
mkdir -p $(dirname "$FILE")
for field in reply_to author email text
do
yq n "$field" "${!field}" >> "$FILE"
done
# Commit comment and push to local repo
git add "$FILE"
git commit -m "Added comment $CID."
git push origin "$BRANCH"
popd
# Clean up temporary clone
rm -rf "$CID"
# Push local repo to original remote
pushd repo
git push --all
popd