generated from cotes2020/chirpy-starter
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtestParser.sh
executable file
·71 lines (55 loc) · 2.17 KB
/
testParser.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
LOG_DATA='
* At _site/posts/en/71400d408dc8/index.html:1:
internally linking to ../f6713ba3fee3/, which does not exist
* At _site/posts/en/71400d408dc8/index.html:1:
internally linking to ../1e85b8df2348/, which does not exist
* At _site/posts/en/71400d408dc8/index.html:1:
internally linking to ../4cb4437818f2/, which does not exist
* At _site/posts/en/71400d408dc8/index.html:121:
internally linking to ../4cb4437818f2/, which does not exist
'
GITHUB_TOKEN=$1
# GITHUB_TOKEN is required
if [ -z "$GITHUB_TOKEN" ]; then
echo "Error: GitHub token is required."
exit 1
fi
SEARCH_DIR="./_posts/zh-tw/zmediumtomarkdown"
commands=()
while IFS= read -r line; do
# Extract the missing internal link hash
if [[ "$line" =~ internally\ linking\ to\ \.\./([a-f0-9]+)/, ]]; then
HASH="${BASH_REMATCH[1]}"
FOUND_FILES=$(find "$SEARCH_DIR" -type f -name "*$HASH*" 2>/dev/null)
# Check if any file is found
if [ -n "$FOUND_FILES" ]; then
NEW_PATHS=$(echo "$FOUND_FILES" | sed 's|/zh-tw/|/en/|g')
API_URL="https://api.github.com/repos/ZhgChgLi/zhgchgli.github.io/issues/53/comments"
COMMENT="/gpt-translate $FOUND_FILES $NEW_PATHS English"
FOUND=false
for ITEM in "${commands[@]}"; do
if [[ "$ITEM" == "$COMMENT" ]]; then
FOUND=true
break
fi
done
if $FOUND; then
continue
fi
commands+=("$COMMENT")
RESPONSE=$(curl -s -X POST "$API_URL" \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
-d "{\"body\": \"$COMMENT\"}")
# Check if the request was successful
if echo "$RESPONSE" | grep -q '"id":'; then
echo "Comment Translator for $file successfully added!"
else
echo "Failed to add comment. Response from GitHub:"
echo "$RESPONSE"
fi
else
echo "No files found containing hash '$HASH' in directory '$SEARCH_DIR'."
fi
fi
done <<< "$LOG_DATA"