-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomment.sh
More file actions
executable file
·57 lines (48 loc) · 1.58 KB
/
comment.sh
File metadata and controls
executable file
·57 lines (48 loc) · 1.58 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
#!/usr/bin/env bash
set -euo pipefail
DEPLOYMENT_URL="${INPUT_DEPLOYMENT_URL:-}"
ALIAS_URL="${INPUT_ALIAS_URL:-}"
if [ -z "$DEPLOYMENT_URL" ] && [ -z "$ALIAS_URL" ]; then
echo "No deployment URL, skipping comment"
exit 0
fi
API_BASE="${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}"
PR_NUMBER=$(jq -r '.pull_request.number' "$GITHUB_EVENT_PATH")
SHORT_SHA="${GITHUB_SHA:0:7}"
MARKER="${INPUT_COMMENT_MARKER}"
ENVIRONMENT="${INPUT_ENVIRONMENT:-preview}"
BODY="${MARKER}
### Cloudflare Pages Preview
| | |
|---|---|"
if [ -n "$ALIAS_URL" ]; then
BODY+="
| **Preview URL** | ${ALIAS_URL} |"
fi
if [ -n "$DEPLOYMENT_URL" ]; then
BODY+="
| **Commit URL** | ${DEPLOYMENT_URL} |"
fi
BODY+="
| **Commit** | \`${SHORT_SHA}\` |
| **Environment** | ${ENVIRONMENT} |"
# Find existing comment with our marker
COMMENT_ID=$(curl -sSf \
-H "Authorization: token ${INPUT_FORGEJO_TOKEN}" \
"${API_BASE}/issues/${PR_NUMBER}/comments" \
| jq -r --arg marker "$MARKER" '.[] | select(.body | contains($marker)) | .id' | head -n1)
if [ -n "$COMMENT_ID" ] && [ "$COMMENT_ID" != "null" ]; then
echo "Updating comment ${COMMENT_ID}"
curl -sSf -X PATCH \
-H "Authorization: token ${INPUT_FORGEJO_TOKEN}" \
-H "Content-Type: application/json" \
-d "$(jq -n --arg body "$BODY" '{body: $body}')" \
"${API_BASE}/issues/comments/${COMMENT_ID}"
else
echo "Creating new comment"
curl -sSf -X POST \
-H "Authorization: token ${INPUT_FORGEJO_TOKEN}" \
-H "Content-Type: application/json" \
-d "$(jq -n --arg body "$BODY" '{body: $body}')" \
"${API_BASE}/issues/${PR_NUMBER}/comments"
fi