Skip to content

Commit 2dced5e

Browse files
committed
port to main branch
1 parent 4db7a3a commit 2dced5e

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

.vale/templates/bot-comment-output.tmpl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@
2929
{{- /* Variables setup */ -}}
3030
{{- $loc := printf "%d" .Line -}}
3131
{{- $check := printf "%s" .Check -}}
32-
{{- $message := printf "%s" .Message -}}
32+
{{- /* Escape special characters for valid JSON */ -}}
33+
{{- $message := replace "\\" "\\\\" (printf "%s" .Message) -}}
34+
{{- $message = replace "\"" "\\\"" $message -}}
35+
{{- $message = replace "\n" "\\n" $message -}}
36+
{{- $message = replace "\r" "\\r" $message -}}
37+
{{- $message = replace "\t" "\\t" $message -}}
3338
{{- /* Only add a link for RedHat rule errors */ -}}
3439
{{- $link := "" -}}
3540
{{- if contains "RedHat." .Check -}}
@@ -45,4 +50,4 @@
4550
}
4651
{{end -}}
4752
{{end -}}
48-
]
53+
]

scripts/prow-vale-review.sh

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,18 @@ function post_review_comment {
2323
BODY=$1
2424
FILENAME=$2
2525
echo "Sending review comment curl request..."
26-
curl -L -X POST -H "Accept: application/vnd.github+json" -H "Authorization: Bearer $GITHUB_AUTH_TOKEN" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/openshift/openshift-docs/pulls/$PULL_NUMBER/comments -d '{"body":"'"$BODY"'","commit_id":"'"$COMMIT_ID"'","path":"'"$FILENAME"'","line":'"$LINE_NUMBER"',"side":"RIGHT"}'
26+
# Use jq to excruciatingly craft JSON payload
27+
# jq -n because we're constructing from scratch per https://jqlang.org/manual/
28+
# --arg for string, --argjson for integer
29+
# body constructed from https://docs.github.com/en/rest/pulls/comments?apiVersion=2022-11-28#create-a-review-comment-for-a-pull-request
30+
payload=$(jq -n \
31+
--arg body "$BODY" \
32+
--arg commit_id "$COMMIT_ID" \
33+
--arg path "$FILENAME" \
34+
--argjson line "$LINE_NUMBER" \
35+
'{body: $body, commit_id: $commit_id, path: $path, line: $line, side: "RIGHT"}')
36+
echo "DEBUG payload:" "$payload"
37+
curl -L -X POST -H "Accept: application/vnd.github+json" -H "Authorization: Bearer $GITHUB_AUTH_TOKEN" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/openshift/openshift-docs/pulls/$PULL_NUMBER/comments -d "$payload"
2738

2839
}
2940

@@ -132,4 +143,4 @@ do
132143

133144
done
134145

135-
done
146+
done

0 commit comments

Comments
 (0)