Skip to content

Commit ab5d1cd

Browse files
committed
attempt to use file-level comments for vale's 1:1 errors
1 parent 4cf9fb2 commit ab5d1cd

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

scripts/prow-vale-review.sh

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,35 @@ fi
1717

1818
FILES=$(git diff --name-only HEAD~1 HEAD --diff-filter=d "*.adoc" ':(exclude)_unused_topics/*' ':(exclude)rest_api/*' ':(exclude)microshift_rest_api/*' ':(exclude)modules/virt-runbook-*' ':(exclude)modules/oc-by-example-content.adoc' ':(exclude)modules/oc-adm-by-example-content.adoc' ':(exclude)monitoring/config-map-reference-for-the-cluster-monitoring-operator.adoc' ':(exclude)modules/microshift-oc-adm-by-example-content.adoc' ':(exclude)modules/microshift-oc-by-example-content.adoc')
1919

20-
function post_review_comment {
2120

21+
function post_review_comment {
2222
LINE_NUMBER=$3
2323
BODY=$1
2424
FILENAME=$2
25-
echo "Sending review comment curl request..."
25+
SUBJECT_TYPE=${4:-"line"} # Default to "line", but will use "file" for file-level comments
2626
# Use jq to excruciatingly craft JSON payload
2727
# jq -n because we're constructing from scratch per https://jqlang.org/manual/
2828
# --arg for string, --argjson for integer
2929
# 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"}')
30+
31+
echo "Sending review comment curl request..."
32+
if [[ "$SUBJECT_TYPE" == "file" ]]; then
33+
# File-level comment - no diff to apply to
34+
payload=$(jq -n \
35+
--arg body "$BODY" \
36+
--arg commit_id "$COMMIT_ID" \
37+
--arg path "$FILENAME" \
38+
'{body: $body, commit_id: $commit_id, path: $path, subject_type: "file"}')
39+
else
40+
# Line-level comment
41+
payload=$(jq -n \
42+
--arg body "$BODY" \
43+
--arg commit_id "$COMMIT_ID" \
44+
--arg path "$FILENAME" \
45+
--argjson line "$LINE_NUMBER" \
46+
'{body: $body, commit_id: $commit_id, path: $path, line: $line, side: "RIGHT"}')
47+
fi
48+
3649
echo "DEBUG payload:" "$payload"
3750
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"
3851
}
@@ -103,9 +116,9 @@ do
103116
FILENAME=$(echo "$object" | jq -r '.path')
104117
LINE_NUMBER=$(echo "$object" | jq -r '.line')
105118

106-
# Line 1 errors are file-level issues. Always post these!
119+
# Line 1 errors from Vale likely to be file-level issues - post as file-level comment
107120
if [[ "$LINE_NUMBER" -eq 1 ]]; then
108-
post_review_comment "$BODY" "$FILENAME" "$LINE_NUMBER"
121+
post_review_comment "$BODY" "$FILENAME" "" "file"
109122
sleep 1
110123
continue
111124
fi
@@ -163,4 +176,3 @@ do
163176
done
164177

165178
done
166-

0 commit comments

Comments
 (0)