Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions .vale/templates/bot-comment-output.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@
{{- /* Variables setup */ -}}
{{- $loc := printf "%d" .Line -}}
{{- $check := printf "%s" .Check -}}
{{- $message := printf "%s" .Message -}}
{{- /* Escape special characters for valid JSON */ -}}
{{- $message := replace "\\" "\\\\" (printf "%s" .Message) -}}
{{- $message = replace "\"" "\\\"" $message -}}
{{- $message = replace "\n" "\\n" $message -}}
{{- $message = replace "\r" "\\r" $message -}}
{{- $message = replace "\t" "\\t" $message -}}
{{- /* Only add a link for RedHat rule errors */ -}}
{{- $link := "" -}}
{{- if contains "RedHat." .Check -}}
Expand All @@ -45,4 +50,5 @@
}
{{end -}}
{{end -}}
]
]

16 changes: 14 additions & 2 deletions scripts/prow-vale-review.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,18 @@ function post_review_comment {
BODY=$1
FILENAME=$2
echo "Sending review comment curl request..."
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"}'
# Use jq to excruciatingly craft JSON payload
# jq -n because we're constructing from scratch per https://jqlang.org/manual/
# --arg for string, --argjson for integer
# body constructed from https://docs.github.com/en/rest/pulls/comments?apiVersion=2022-11-28#create-a-review-comment-for-a-pull-request
payload=$(jq -n \
--arg body "$BODY" \
--arg commit_id "$COMMIT_ID" \
--arg path "$FILENAME" \
--argjson line "$LINE_NUMBER" \
'{body: $body, commit_id: $commit_id, path: $path, line: $line, side: "RIGHT"}')
echo "DEBUG payload:" "$payload"
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"

}

Expand Down Expand Up @@ -132,4 +143,5 @@ do

done

done
done