forked from hse-tex/hse-tex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost-diff.sh
executable file
·71 lines (52 loc) · 1.65 KB
/
post-diff.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
#!/bin/bash
set -e
if [[ ! -d .pdf ]] || (!(find .pdf -mindepth 1 | read)); then
echo "nothing to diff"
exit
fi
function post_diff {
left="$1"; shift
right="$1"; shift
response=$(curl "https://api.draftable.com/v1/comparisons" \
-H "Authorization: Token $DRAFTABLE_API_TOKEN" \
-F "left.file_type=pdf" -F "left.file=@$left" \
-F "right.file_type=pdf" -F "right.file=@$right" \
-F "public=true")
>&2 echo "Draftable response: $response"
id=$(echo "$response" | jq .identifier -r)
echo "https://api.draftable.com/v1/comparisons/viewer/$DRAFTABLE_API_ID/$id"
}
function build_content {
pushd .pdf > /dev/null
echo "Build successfully finished. Document diff:"
for item in $(find . -name '*.pdf'); do
gh_pages_one="../_gh_pages/$item"
right="$item"
if [[ ! -f "$gh_pages_one" ]]; then
left="$item"
else
left="$gh_pages_one"
fi
url=$(post_diff "$left" "$right")
if [ "$left" != "$right" ]; then
echo "[$item]($url)"
else
echo "[$item]($url) — new document"
fi
done
popd > /dev/null
}
function post_comment {
content="$1"; shift
body=$(jq -n --arg content "$content" '{body: ($content)}')
GH_BOT_TOKEN=$(curl https://darkkeks.me/hse-bot-token)
curl -X POST \
-u hse-tex-bot:$GH_BOT_TOKEN \
-H "Accept: application/vnd.github.v3+json" \
$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/issues/$PULL_REQUEST_NUMBER/comments \
-d "$body"
}
content=$(build_content)
echo "Content:"
echo "$content"
post_comment "$content"